]>
Commit | Line | Data |
---|---|---|
63586d2f AD |
1 | package PVE::Network::SDN::EvpnPlugin; |
2 | ||
3 | use strict; | |
4 | use warnings; | |
5 | use PVE::Network::SDN::Plugin; | |
6 | use PVE::Tools qw($IPV4RE); | |
7 | use PVE::INotify; | |
8 | ||
9 | use base('PVE::Network::SDN::VxlanPlugin'); | |
10 | ||
11 | sub type { | |
12 | return 'evpn'; | |
13 | } | |
14 | ||
15 | sub plugindata { | |
16 | return { | |
17 | role => 'transport', | |
18 | }; | |
19 | } | |
20 | ||
21 | sub properties { | |
22 | return { | |
23 | 'vrf' => { | |
24 | description => "vrf name.", | |
25 | type => 'string', #fixme: format | |
26 | }, | |
27 | 'vrf-vxlan' => { | |
28 | type => 'integer', | |
29 | description => "l3vni.", | |
30 | }, | |
31 | 'controller' => { | |
32 | type => 'string', | |
33 | description => "Frr router name", | |
34 | }, | |
35 | }; | |
36 | } | |
37 | ||
38 | sub options { | |
39 | ||
40 | return { | |
41 | 'uplink-id' => { optional => 0 }, | |
42 | 'vxlan-allowed' => { optional => 1 }, | |
43 | 'vrf' => { optional => 0 }, | |
44 | 'vrf-vxlan' => { optional => 0 }, | |
45 | 'controller' => { optional => 0 }, | |
46 | }; | |
47 | } | |
48 | ||
49 | # Plugin implementation | |
50 | sub generate_sdn_config { | |
51 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_; | |
52 | ||
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}; | |
58 | ||
59 | my $uplink = $plugin_config->{'uplink-id'}; | |
60 | my $vxlanallowed = $plugin_config->{'vxlan-allowed'}; | |
61 | my $vrf = $plugin_config->{'vrf'}; | |
62 | my $vrfvxlan = $plugin_config->{'vrf-vxlan'}; | |
63 | ||
64 | die "missing vxlan tag" if !$tag; | |
65 | my $iface = "uplink$uplink"; | |
66 | my $ifaceip = ""; | |
67 | ||
68 | if($uplinks->{$uplink}->{name}) { | |
69 | $iface = $uplinks->{$uplink}->{name}; | |
70 | $ifaceip = PVE::Network::SDN::Plugin::get_first_local_ipv4_from_interface($iface); | |
71 | } | |
72 | ||
73 | my $mtu = 1450; | |
74 | $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu}; | |
75 | $mtu = $vnet->{mtu} if $vnet->{mtu}; | |
76 | ||
77 | #vxlan interface | |
78 | my @iface_config = (); | |
79 | push @iface_config, "vxlan-id $tag"; | |
80 | ||
81 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; | |
82 | push @iface_config, "bridge-learning off"; | |
83 | push @iface_config, "bridge-arp-nd-suppress on"; | |
84 | ||
85 | push @iface_config, "mtu $mtu" if $mtu; | |
86 | push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"}; | |
87 | ||
88 | #vnet bridge | |
89 | @iface_config = (); | |
90 | push @iface_config, "address $ipv4" if $ipv4; | |
91 | push @iface_config, "address $ipv6" if $ipv6; | |
92 | push @iface_config, "hwaddress $mac" if $mac; | |
93 | push @iface_config, "bridge_ports vxlan$vnetid"; | |
94 | push @iface_config, "bridge_stp off"; | |
95 | push @iface_config, "bridge_fd 0"; | |
96 | push @iface_config, "mtu $mtu" if $mtu; | |
97 | push @iface_config, "alias $alias" if $alias; | |
98 | push @iface_config, "ip-forward on" if $ipv4; | |
99 | push @iface_config, "ip6-forward on" if $ipv6; | |
100 | push @iface_config, "arp-accept on" if $ipv4||$ipv6; | |
101 | push @iface_config, "vrf $vrf" if $vrf; | |
102 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; | |
103 | ||
104 | if ($vrf) { | |
105 | #vrf interface | |
106 | @iface_config = (); | |
107 | push @iface_config, "vrf-table auto"; | |
108 | push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf}; | |
109 | ||
110 | if ($vrfvxlan) { | |
111 | #l3vni vxlan interface | |
112 | my $iface_vxlan = "vxlan$vrf"; | |
113 | @iface_config = (); | |
114 | push @iface_config, "vxlan-id $vrfvxlan"; | |
115 | push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip; | |
116 | push @iface_config, "bridge-learning off"; | |
117 | push @iface_config, "bridge-arp-nd-suppress on"; | |
118 | push @iface_config, "mtu $mtu" if $mtu; | |
119 | push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan}; | |
120 | ||
121 | #l3vni bridge | |
122 | my $brvrf = "br$vrf"; | |
123 | @iface_config = (); | |
124 | push @iface_config, "bridge-ports $iface_vxlan"; | |
125 | push @iface_config, "bridge_stp off"; | |
126 | push @iface_config, "bridge_fd 0"; | |
127 | push @iface_config, "mtu $mtu" if $mtu; | |
128 | push @iface_config, "vrf $vrf"; | |
129 | push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf}; | |
130 | } | |
131 | } | |
132 | ||
133 | return $config; | |
134 | } | |
135 | ||
136 | sub on_update_hook { | |
137 | my ($class, $transportid, $sdn_cfg) = @_; | |
138 | ||
139 | my $transport = $sdn_cfg->{ids}->{$transportid}; | |
140 | ||
141 | # verify that vxlan-allowed don't conflict with another vxlan-allowed transport | |
142 | ||
143 | # verify that vxlan-allowed is matching currently vnet tag in this transport | |
144 | my $vxlanallowed = $transport->{'vxlan-allowed'}; | |
145 | if ($vxlanallowed) { | |
146 | foreach my $id (keys %{$sdn_cfg->{ids}}) { | |
147 | my $sdn = $sdn_cfg->{ids}->{$id}; | |
148 | if ($sdn->{type} eq 'vnet' && defined($sdn->{tag})) { | |
149 | if(defined($sdn->{transportzone}) && $sdn->{transportzone} eq $transportid) { | |
150 | my $tag = $sdn->{tag}; | |
151 | eval { | |
152 | PVE::Network::SDN::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag); | |
153 | }; | |
154 | if($@) { | |
155 | die "vnet $id - vlan $tag is not allowed in transport $transportid"; | |
156 | } | |
157 | } | |
158 | } | |
159 | } | |
160 | } | |
161 | ||
162 | # verify that router exist | |
163 | if (defined($sdn_cfg->{ids}->{$transportid}->{router})) { | |
164 | my $router = $sdn_cfg->{ids}->{$transportid}->{router}; | |
165 | if (!defined($sdn_cfg->{ids}->{$router})) { | |
166 | die "router $router don't exist"; | |
167 | } else { | |
168 | die "$router is not a router type" if $sdn_cfg->{ids}->{$router}->{type} ne 'frr'; | |
169 | } | |
170 | ||
171 | #vrf && vrf-vxlan need to be defined with router | |
172 | my $vrf = $sdn_cfg->{ids}->{$transportid}->{vrf}; | |
173 | if (!defined($vrf)) { | |
174 | die "missing vrf option"; | |
175 | } else { | |
176 | # verify that vrf is not already declared in another transport | |
177 | foreach my $id (keys %{$sdn_cfg->{ids}}) { | |
178 | next if $id eq $transportid; | |
179 | die "vrf $vrf is already declared in $id" | |
180 | if (defined($sdn_cfg->{ids}->{$id}->{vrf}) && $sdn_cfg->{ids}->{$id}->{vrf} eq $vrf); | |
181 | } | |
182 | } | |
183 | ||
184 | my $vrfvxlan = $sdn_cfg->{ids}->{$transportid}->{'vrf-vxlan'}; | |
185 | if (!defined($vrfvxlan)) { | |
186 | die "missing vrf-vxlan option"; | |
187 | } else { | |
188 | # verify that vrf-vxlan is not already declared in another transport | |
189 | foreach my $id (keys %{$sdn_cfg->{ids}}) { | |
190 | next if $id eq $transportid; | |
191 | die "vrf-vxlan $vrfvxlan is already declared in $id" | |
192 | if (defined($sdn_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan); | |
193 | } | |
194 | } | |
195 | } | |
196 | } | |
197 | ||
198 | 1; | |
199 | ||
200 |