]>
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; | |
4405f2de | 8 | use PVE::Network::SDN::Controllers::EvpnPlugin; |
63586d2f | 9 | |
f5eabba0 | 10 | use base('PVE::Network::SDN::Zones::VxlanPlugin'); |
63586d2f AD |
11 | |
12 | sub type { | |
13 | return 'evpn'; | |
14 | } | |
15 | ||
63586d2f AD |
16 | sub properties { |
17 | return { | |
63586d2f AD |
18 | 'vrf-vxlan' => { |
19 | type => 'integer', | |
20 | description => "l3vni.", | |
21 | }, | |
22 | 'controller' => { | |
23 | type => 'string', | |
24 | description => "Frr router name", | |
25 | }, | |
26 | }; | |
27 | } | |
28 | ||
29 | sub options { | |
30 | ||
31 | return { | |
c2b9c173 | 32 | nodes => { optional => 1}, |
63586d2f AD |
33 | 'vrf-vxlan' => { optional => 0 }, |
34 | 'controller' => { optional => 0 }, | |
35 | }; | |
36 | } | |
37 | ||
38 | # Plugin implementation | |
39 | sub generate_sdn_config { | |
4405f2de | 40 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_; |
63586d2f AD |
41 | |
42 | my $tag = $vnet->{tag}; | |
43 | my $alias = $vnet->{alias}; | |
44 | my $ipv4 = $vnet->{ipv4}; | |
45 | my $ipv6 = $vnet->{ipv6}; | |
46 | my $mac = $vnet->{mac}; | |
47 | ||
7cb9714d | 48 | my $vrf = $zoneid; |
63586d2f AD |
49 | my $vrfvxlan = $plugin_config->{'vrf-vxlan'}; |
50 | ||
51 | die "missing vxlan tag" if !$tag; | |
63586d2f | 52 | |
4405f2de AD |
53 | my @peers = split(',', $controller->{'peers'}); |
54 | my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers); | |
63586d2f AD |
55 | |
56 | my $mtu = 1450; | |
4405f2de | 57 | $mtu = $uplinks->{$iface}->{mtu} - 50 if $uplinks->{$iface}->{mtu}; |
63586d2f AD |
58 | $mtu = $vnet->{mtu} if $vnet->{mtu}; |
59 | ||
60 | #vxlan interface | |
61 | my @iface_config = (); | |
62 | push @iface_config, "vxlan-id $tag"; | |
63 | ||
64 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; | |
65 | push @iface_config, "bridge-learning off"; | |
66 | push @iface_config, "bridge-arp-nd-suppress on"; | |
67 | ||
68 | push @iface_config, "mtu $mtu" if $mtu; | |
69 | push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"}; | |
70 | ||
71 | #vnet bridge | |
72 | @iface_config = (); | |
73 | push @iface_config, "address $ipv4" if $ipv4; | |
74 | push @iface_config, "address $ipv6" if $ipv6; | |
75 | push @iface_config, "hwaddress $mac" if $mac; | |
76 | push @iface_config, "bridge_ports vxlan$vnetid"; | |
77 | push @iface_config, "bridge_stp off"; | |
78 | push @iface_config, "bridge_fd 0"; | |
79 | push @iface_config, "mtu $mtu" if $mtu; | |
80 | push @iface_config, "alias $alias" if $alias; | |
81 | push @iface_config, "ip-forward on" if $ipv4; | |
82 | push @iface_config, "ip6-forward on" if $ipv6; | |
83 | push @iface_config, "arp-accept on" if $ipv4||$ipv6; | |
84 | push @iface_config, "vrf $vrf" if $vrf; | |
85 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; | |
86 | ||
87 | if ($vrf) { | |
88 | #vrf interface | |
89 | @iface_config = (); | |
90 | push @iface_config, "vrf-table auto"; | |
91 | push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf}; | |
92 | ||
93 | if ($vrfvxlan) { | |
94 | #l3vni vxlan interface | |
7cb9714d | 95 | my $iface_vxlan = "vxvrf$vrf"; |
63586d2f AD |
96 | @iface_config = (); |
97 | push @iface_config, "vxlan-id $vrfvxlan"; | |
98 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; | |
99 | push @iface_config, "bridge-learning off"; | |
100 | push @iface_config, "bridge-arp-nd-suppress on"; | |
101 | push @iface_config, "mtu $mtu" if $mtu; | |
102 | push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan}; | |
103 | ||
104 | #l3vni bridge | |
105 | my $brvrf = "br$vrf"; | |
106 | @iface_config = (); | |
107 | push @iface_config, "bridge-ports $iface_vxlan"; | |
108 | push @iface_config, "bridge_stp off"; | |
109 | push @iface_config, "bridge_fd 0"; | |
110 | push @iface_config, "mtu $mtu" if $mtu; | |
111 | push @iface_config, "vrf $vrf"; | |
112 | push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf}; | |
113 | } | |
114 | } | |
115 | ||
116 | return $config; | |
117 | } | |
118 | ||
119 | sub on_update_hook { | |
a2b32a94 AD |
120 | my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_; |
121 | ||
122 | # verify that controller exist | |
123 | my $controller = $zone_cfg->{ids}->{$zoneid}->{controller}; | |
124 | if (!defined($controller_cfg->{ids}->{$controller})) { | |
125 | die "controller $controller don't exist"; | |
126 | } else { | |
127 | die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn'; | |
128 | } | |
63586d2f | 129 | |
7cb9714d | 130 | #vrf-vxlan need to be defined |
a2b32a94 AD |
131 | |
132 | my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'}; | |
133 | # verify that vrf-vxlan is not already declared in another zone | |
134 | foreach my $id (keys %{$zone_cfg->{ids}}) { | |
135 | next if $id eq $zoneid; | |
136 | die "vrf-vxlan $vrfvxlan is already declared in $id" | |
137 | if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan); | |
63586d2f AD |
138 | } |
139 | } | |
140 | ||
141 | 1; | |
142 | ||
143 |