1 package PVE
::Network
::SDN
::Zones
::EvpnPlugin
;
5 use PVE
::Network
::SDN
::Zones
::VxlanPlugin
;
6 use PVE
::Tools
qw($IPV4RE);
9 use base
('PVE::Network::SDN::Zones::VxlanPlugin');
24 description
=> "vrf name.",
25 type
=> 'string', #fixme: format
29 description
=> "l3vni.",
33 description
=> "Frr router name",
41 nodes
=> { optional
=> 1},
42 'uplink-id' => { optional
=> 0 },
43 'vrf' => { optional
=> 0 },
44 'vrf-vxlan' => { optional
=> 0 },
45 'controller' => { optional
=> 0 },
49 # Plugin implementation
50 sub generate_sdn_config
{
51 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
53 my $tag = $vnet->{tag
};
54 my $alias = $vnet->{alias
};
55 my $ipv4 = $vnet->{ipv4
};
56 my $ipv6 = $vnet->{ipv6
};
57 my $mac = $vnet->{mac
};
59 my $uplink = $plugin_config->{'uplink-id'};
60 my $vrf = $plugin_config->{'vrf'};
61 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
63 die "missing vxlan tag" if !$tag;
64 my $iface = "uplink$uplink";
67 if($uplinks->{$uplink}->{name
}) {
68 $iface = $uplinks->{$uplink}->{name
};
69 $ifaceip = PVE
::Network
::SDN
::Zones
::Plugin
::get_first_local_ipv4_from_interface
($iface);
73 $mtu = $uplinks->{$uplink}->{mtu
} - 50 if $uplinks->{$uplink}->{mtu
};
74 $mtu = $vnet->{mtu
} if $vnet->{mtu
};
77 my @iface_config = ();
78 push @iface_config, "vxlan-id $tag";
80 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
81 push @iface_config, "bridge-learning off";
82 push @iface_config, "bridge-arp-nd-suppress on";
84 push @iface_config, "mtu $mtu" if $mtu;
85 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
89 push @iface_config, "address $ipv4" if $ipv4;
90 push @iface_config, "address $ipv6" if $ipv6;
91 push @iface_config, "hwaddress $mac" if $mac;
92 push @iface_config, "bridge_ports vxlan$vnetid";
93 push @iface_config, "bridge_stp off";
94 push @iface_config, "bridge_fd 0";
95 push @iface_config, "mtu $mtu" if $mtu;
96 push @iface_config, "alias $alias" if $alias;
97 push @iface_config, "ip-forward on" if $ipv4;
98 push @iface_config, "ip6-forward on" if $ipv6;
99 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
100 push @iface_config, "vrf $vrf" if $vrf;
101 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
106 push @iface_config, "vrf-table auto";
107 push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf};
110 #l3vni vxlan interface
111 my $iface_vxlan = "vxlan$vrf";
113 push @iface_config, "vxlan-id $vrfvxlan";
114 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
115 push @iface_config, "bridge-learning off";
116 push @iface_config, "bridge-arp-nd-suppress on";
117 push @iface_config, "mtu $mtu" if $mtu;
118 push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan};
121 my $brvrf = "br$vrf";
123 push @iface_config, "bridge-ports $iface_vxlan";
124 push @iface_config, "bridge_stp off";
125 push @iface_config, "bridge_fd 0";
126 push @iface_config, "mtu $mtu" if $mtu;
127 push @iface_config, "vrf $vrf";
128 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
136 my ($class, $transportid, $sdn_cfg) = @_;
138 # verify that router exist
139 if (defined($sdn_cfg->{ids
}->{$transportid}->{controller
})) {
140 my $controller = $sdn_cfg->{ids
}->{$transportid}->{controller
};
141 if (!defined($sdn_cfg->{ids
}->{$controller})) {
142 die "controller $controller don't exist";
144 die "$controller is not a evpn controller type" if $sdn_cfg->{ids
}->{$controller}->{type
} ne 'evpn';
147 #vrf && vrf-vxlan need to be defined with controller
148 my $vrf = $sdn_cfg->{ids
}->{$transportid}->{vrf
};
149 if (!defined($vrf)) {
150 die "missing vrf option";
152 # verify that vrf is not already declared in another transport
153 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
154 next if $id eq $transportid;
155 die "vrf $vrf is already declared in $id"
156 if (defined($sdn_cfg->{ids
}->{$id}->{vrf
}) && $sdn_cfg->{ids
}->{$id}->{vrf
} eq $vrf);
160 my $vrfvxlan = $sdn_cfg->{ids
}->{$transportid}->{'vrf-vxlan'};
161 if (!defined($vrfvxlan)) {
162 die "missing vrf-vxlan option";
164 # verify that vrf-vxlan is not already declared in another transport
165 foreach my $id (keys %{$sdn_cfg->{ids
}}) {
166 next if $id eq $transportid;
167 die "vrf-vxlan $vrfvxlan is already declared in $id"
168 if (defined($sdn_cfg->{ids
}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids
}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);