]>
Commit | Line | Data |
---|---|---|
f5eabba0 | 1 | package PVE::Network::SDN::Zones::EvpnPlugin; |
63586d2f AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
f5eabba0 | 5 | use PVE::Network::SDN::Zones::VxlanPlugin; |
63586d2f AD |
6 | use PVE::Tools qw($IPV4RE); |
7 | use PVE::INotify; | |
5ca07ed9 AD |
8 | use PVE::Cluster; |
9 | use PVE::Tools; | |
10 | ||
4405f2de | 11 | use PVE::Network::SDN::Controllers::EvpnPlugin; |
63586d2f | 12 | |
f5eabba0 | 13 | use base('PVE::Network::SDN::Zones::VxlanPlugin'); |
63586d2f AD |
14 | |
15 | sub type { | |
16 | return 'evpn'; | |
17 | } | |
18 | ||
63586d2f AD |
19 | sub properties { |
20 | return { | |
63586d2f AD |
21 | 'vrf-vxlan' => { |
22 | type => 'integer', | |
23 | description => "l3vni.", | |
24 | }, | |
25 | 'controller' => { | |
26 | type => 'string', | |
27 | description => "Frr router name", | |
28 | }, | |
29 | }; | |
30 | } | |
31 | ||
32 | sub options { | |
33 | ||
34 | return { | |
c2b9c173 | 35 | nodes => { optional => 1}, |
63586d2f AD |
36 | 'vrf-vxlan' => { optional => 0 }, |
37 | 'controller' => { optional => 0 }, | |
823f2e2a | 38 | mtu => { optional => 1 }, |
63586d2f AD |
39 | }; |
40 | } | |
41 | ||
42 | # Plugin implementation | |
43 | sub generate_sdn_config { | |
7024ec2b | 44 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_; |
63586d2f AD |
45 | |
46 | my $tag = $vnet->{tag}; | |
47 | my $alias = $vnet->{alias}; | |
48 | my $ipv4 = $vnet->{ipv4}; | |
49 | my $ipv6 = $vnet->{ipv6}; | |
50 | my $mac = $vnet->{mac}; | |
51 | ||
1de0abc0 | 52 | my $vrf_iface = "vrf_$zoneid"; |
63586d2f AD |
53 | my $vrfvxlan = $plugin_config->{'vrf-vxlan'}; |
54 | ||
55 | die "missing vxlan tag" if !$tag; | |
912fb443 | 56 | warn "vlan-aware vnet can't be enabled with evpn plugin" if $vnet->{vlanaware}; |
63586d2f | 57 | |
5a60da84 | 58 | my @peers = PVE::Tools::split_list($controller->{'peers'}); |
1f543c5f | 59 | my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers); |
63586d2f AD |
60 | |
61 | my $mtu = 1450; | |
ba7ac021 | 62 | $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu}; |
0251ed2f | 63 | $mtu = $plugin_config->{mtu} if $plugin_config->{mtu}; |
63586d2f AD |
64 | |
65 | #vxlan interface | |
1de0abc0 | 66 | my $vxlan_iface = "vxlan_$vnetid"; |
63586d2f AD |
67 | my @iface_config = (); |
68 | push @iface_config, "vxlan-id $tag"; | |
63586d2f AD |
69 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; |
70 | push @iface_config, "bridge-learning off"; | |
71 | push @iface_config, "bridge-arp-nd-suppress on"; | |
72 | ||
73 | push @iface_config, "mtu $mtu" if $mtu; | |
1de0abc0 | 74 | push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface}; |
63586d2f AD |
75 | |
76 | #vnet bridge | |
77 | @iface_config = (); | |
7024ec2b AD |
78 | |
79 | my @subnets = PVE::Tools::split_list($vnet->{subnets}) if $vnet->{subnets}; | |
80 | foreach my $subnet (@subnets) { | |
81 | next if !defined($subnet_cfg->{ids}->{$subnet}); | |
82 | push @iface_config, "address $subnet_cfg->{ids}->{$subnet}->{gateway}" if $subnet_cfg->{ids}->{$subnet}->{gateway}; | |
83 | } | |
84 | ||
63586d2f | 85 | push @iface_config, "hwaddress $mac" if $mac; |
1de0abc0 | 86 | push @iface_config, "bridge_ports $vxlan_iface"; |
63586d2f AD |
87 | push @iface_config, "bridge_stp off"; |
88 | push @iface_config, "bridge_fd 0"; | |
89 | push @iface_config, "mtu $mtu" if $mtu; | |
90 | push @iface_config, "alias $alias" if $alias; | |
91 | push @iface_config, "ip-forward on" if $ipv4; | |
92 | push @iface_config, "ip6-forward on" if $ipv6; | |
93 | push @iface_config, "arp-accept on" if $ipv4||$ipv6; | |
1de0abc0 | 94 | push @iface_config, "vrf $vrf_iface" if $vrf_iface; |
63586d2f AD |
95 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; |
96 | ||
1de0abc0 | 97 | if ($vrf_iface) { |
63586d2f AD |
98 | #vrf interface |
99 | @iface_config = (); | |
100 | push @iface_config, "vrf-table auto"; | |
1de0abc0 | 101 | push(@{$config->{$vrf_iface}}, @iface_config) if !$config->{$vrf_iface}; |
63586d2f AD |
102 | |
103 | if ($vrfvxlan) { | |
104 | #l3vni vxlan interface | |
1de0abc0 | 105 | my $iface_vrf_vxlan = "vrfvx_$zoneid"; |
63586d2f AD |
106 | @iface_config = (); |
107 | push @iface_config, "vxlan-id $vrfvxlan"; | |
108 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; | |
109 | push @iface_config, "bridge-learning off"; | |
110 | push @iface_config, "bridge-arp-nd-suppress on"; | |
111 | push @iface_config, "mtu $mtu" if $mtu; | |
1de0abc0 | 112 | push(@{$config->{$iface_vrf_vxlan}}, @iface_config) if !$config->{$iface_vrf_vxlan}; |
63586d2f AD |
113 | |
114 | #l3vni bridge | |
1de0abc0 | 115 | my $brvrf = "vrfbr_$zoneid"; |
63586d2f | 116 | @iface_config = (); |
1de0abc0 | 117 | push @iface_config, "bridge-ports $iface_vrf_vxlan"; |
63586d2f AD |
118 | push @iface_config, "bridge_stp off"; |
119 | push @iface_config, "bridge_fd 0"; | |
120 | push @iface_config, "mtu $mtu" if $mtu; | |
1de0abc0 | 121 | push @iface_config, "vrf $vrf_iface"; |
63586d2f AD |
122 | push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf}; |
123 | } | |
124 | } | |
125 | ||
126 | return $config; | |
127 | } | |
128 | ||
129 | sub on_update_hook { | |
a2b32a94 AD |
130 | my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_; |
131 | ||
132 | # verify that controller exist | |
133 | my $controller = $zone_cfg->{ids}->{$zoneid}->{controller}; | |
134 | if (!defined($controller_cfg->{ids}->{$controller})) { | |
135 | die "controller $controller don't exist"; | |
136 | } else { | |
137 | die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn'; | |
138 | } | |
63586d2f | 139 | |
7cb9714d | 140 | #vrf-vxlan need to be defined |
a2b32a94 AD |
141 | |
142 | my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'}; | |
143 | # verify that vrf-vxlan is not already declared in another zone | |
144 | foreach my $id (keys %{$zone_cfg->{ids}}) { | |
145 | next if $id eq $zoneid; | |
146 | die "vrf-vxlan $vrfvxlan is already declared in $id" | |
147 | if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan); | |
63586d2f | 148 | } |
5ca07ed9 | 149 | |
63586d2f AD |
150 | } |
151 | ||
1d44ce70 | 152 | |
5ca07ed9 AD |
153 | sub vnet_update_hook { |
154 | my ($class, $vnet) = @_; | |
155 | ||
156 | raise_param_exc({ tag => "missing vxlan tag"}) if !defined($vnet->{tag}); | |
157 | raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $vnet->{tag} > 16777216; | |
158 | ||
159 | if (!defined($vnet->{mac})) { | |
160 | my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg'); | |
161 | $vnet->{mac} = PVE::Tools::random_ether_addr($dc->{mac_prefix}); | |
162 | } | |
1d44ce70 AD |
163 | } |
164 | ||
5ca07ed9 | 165 | |
63586d2f AD |
166 | 1; |
167 | ||
168 |