]>
Commit | Line | Data |
---|---|---|
f5eabba0 | 1 | package PVE::Network::SDN::Zones::QinQPlugin; |
20e19696 AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
3dfdc684 | 5 | use PVE::Network::SDN::Zones::Plugin; |
1d44ce70 | 6 | use PVE::Exception qw(raise raise_param_exc); |
20e19696 | 7 | |
3dfdc684 | 8 | use base('PVE::Network::SDN::Zones::Plugin'); |
20e19696 AD |
9 | |
10 | sub type { | |
11 | return 'qinq'; | |
12 | } | |
13 | ||
20e19696 AD |
14 | sub properties { |
15 | return { | |
1c95991c TL |
16 | tag => { |
17 | type => 'integer', | |
18 | minimum => 0, | |
19 | description => "Service-VLAN Tag", | |
20 | }, | |
823f2e2a AD |
21 | mtu => { |
22 | type => 'integer', | |
1c95991c | 23 | description => "MTU", |
823f2e2a AD |
24 | optional => 1, |
25 | }, | |
3dfdc684 AD |
26 | 'vlan-protocol' => { |
27 | type => 'string', | |
28 | enum => ['802.1q', '802.1ad'], | |
29 | default => '802.1q', | |
30 | optional => 1, | |
31 | } | |
20e19696 AD |
32 | }; |
33 | } | |
34 | ||
35 | sub options { | |
36 | ||
37 | return { | |
c2b9c173 | 38 | nodes => { optional => 1}, |
20e19696 | 39 | 'tag' => { optional => 0 }, |
938ebef7 | 40 | 'bridge' => { optional => 0 }, |
823f2e2a | 41 | 'mtu' => { optional => 1 }, |
3dfdc684 | 42 | 'vlan-protocol' => { optional => 1 }, |
4ad78442 AD |
43 | dns => { optional => 1 }, |
44 | reversedns => { optional => 1 }, | |
45 | dnszone => { optional => 1 }, | |
331e2330 | 46 | ipam => { optional => 0 }, |
20e19696 AD |
47 | }; |
48 | } | |
49 | ||
50 | # Plugin implementation | |
51 | sub generate_sdn_config { | |
efffa0ff | 52 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_; |
20e19696 | 53 | |
3dfdc684 | 54 | my $stag = $plugin_config->{tag}; |
938ebef7 AD |
55 | my $mtu = $plugin_config->{mtu}; |
56 | my $bridge = $plugin_config->{'bridge'}; | |
3dfdc684 AD |
57 | my $vlanprotocol = $plugin_config->{'vlan-protocol'}; |
58 | my $ctag = $vnet->{tag}; | |
59 | my $alias = $vnet->{alias}; | |
20e19696 | 60 | |
fdf22d5f AD |
61 | PVE::Network::SDN::Zones::Plugin::find_bridge($bridge); |
62 | ||
63 | my $vlan_aware = PVE::Network::SDN::Zones::Plugin::is_vlanaware($bridge); | |
64 | my $is_ovs = PVE::Network::SDN::Zones::Plugin::is_ovs($bridge); | |
20e19696 | 65 | |
3dfdc684 AD |
66 | my @iface_config = (); |
67 | my $vnet_bridge_ports = ""; | |
68 | ||
69 | if($is_ovs) { | |
70 | ||
71 | #ovs--->ovsintport(dot1q-tunnel tag)------->vlanawarebrige-----(tag)--->vnet | |
72 | ||
73 | $vlanprotocol = "802.1q" if !$vlanprotocol; | |
74 | my $svlan_iface = "sv_".$zoneid; | |
75 | my $zone = "z_$zoneid"; | |
76 | ||
77 | #ovs dot1q-tunnel port | |
78 | @iface_config = (); | |
79 | push @iface_config, "ovs_type OVSIntPort"; | |
80 | push @iface_config, "ovs_bridge $bridge"; | |
82159388 | 81 | push @iface_config, "ovs_mtu $mtu" if $mtu; |
3dfdc684 AD |
82 | push @iface_config, "ovs_options vlan_mode=dot1q-tunnel tag=$stag other_config:qinq-ethtype=$vlanprotocol"; |
83 | push(@{$config->{$svlan_iface}}, @iface_config) if !$config->{$svlan_iface}; | |
84 | ||
880f6d61 AD |
85 | #redefine main ovs bridge, ifupdown2 will merge ovs_ports |
86 | @iface_config = (); | |
87 | push @iface_config, "ovs_ports $svlan_iface"; | |
0f700635 | 88 | push(@{$config->{$bridge}}, @iface_config); |
3dfdc684 AD |
89 | |
90 | #zone vlan aware bridge | |
91 | @iface_config = (); | |
938ebef7 AD |
92 | push @iface_config, "mtu $mtu" if $mtu; |
93 | push @iface_config, "bridge-stp off"; | |
3dfdc684 | 94 | push @iface_config, "bridge-ports $svlan_iface"; |
938ebef7 AD |
95 | push @iface_config, "bridge-fd 0"; |
96 | push @iface_config, "bridge-vlan-aware yes"; | |
97 | push @iface_config, "bridge-vids 2-4094"; | |
3dfdc684 AD |
98 | push(@{$config->{$zone}}, @iface_config) if !$config->{$zone}; |
99 | ||
100 | $vnet_bridge_ports = "$zone.$ctag"; | |
101 | ||
102 | } elsif ($vlan_aware) { | |
103 | ||
104 | #vlanawarebrige-(tag)----->vlanwarebridge-(tag)----->vnet | |
938ebef7 | 105 | |
3dfdc684 AD |
106 | my $zone = "z_$zoneid"; |
107 | ||
108 | if($vlanprotocol) { | |
109 | @iface_config = (); | |
110 | push @iface_config, "bridge-vlan-protocol $vlanprotocol"; | |
111 | push(@{$config->{$bridge}}, @iface_config) if !$config->{$bridge}; | |
112 | } | |
113 | ||
114 | #zone vlan bridge | |
938ebef7 | 115 | @iface_config = (); |
3dfdc684 AD |
116 | push @iface_config, "mtu $mtu" if $mtu; |
117 | push @iface_config, "bridge-stp off"; | |
118 | push @iface_config, "bridge-ports $bridge.$stag"; | |
119 | push @iface_config, "bridge-fd 0"; | |
120 | push @iface_config, "bridge-vlan-aware yes"; | |
121 | push @iface_config, "bridge-vids 2-4094"; | |
122 | push(@{$config->{$zone}}, @iface_config) if !$config->{$zone}; | |
123 | ||
124 | $vnet_bridge_ports = "$zone.$ctag"; | |
125 | ||
126 | } else { | |
127 | ||
128 | #eth--->eth.x(svlan)--->eth.x.y(cvlan)---->vnet | |
129 | ||
fdf22d5f | 130 | my @bridge_ifaces = PVE::Network::SDN::Zones::Plugin::get_bridge_ifaces($bridge); |
3dfdc684 AD |
131 | |
132 | foreach my $bridge_iface (@bridge_ifaces) { | |
133 | ||
134 | # use named vlan interface to avoid too long names | |
135 | my $svlan_iface = "sv_$vnetid"; | |
136 | my $cvlan_iface = "cv_$vnetid"; | |
137 | ||
138 | #svlan | |
139 | @iface_config = (); | |
140 | push @iface_config, "vlan-raw-device $bridge_iface"; | |
141 | push @iface_config, "vlan-id $stag"; | |
142 | push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol; | |
143 | push(@{$config->{$svlan_iface}}, @iface_config) if !$config->{$svlan_iface}; | |
144 | ||
145 | #cvlan | |
146 | @iface_config = (); | |
147 | push @iface_config, "vlan-raw-device $svlan_iface"; | |
148 | push @iface_config, "vlan-id $ctag"; | |
149 | push(@{$config->{$cvlan_iface}}, @iface_config) if !$config->{$cvlan_iface}; | |
150 | ||
151 | $vnet_bridge_ports .= " $cvlan_iface"; | |
152 | } | |
153 | } | |
154 | ||
155 | #vnet bridge | |
156 | @iface_config = (); | |
157 | push @iface_config, "bridge_ports $vnet_bridge_ports"; | |
158 | push @iface_config, "bridge_stp off"; | |
159 | push @iface_config, "bridge_fd 0"; | |
912fb443 AD |
160 | if($vnet->{vlanaware}) { |
161 | push @iface_config, "bridge-vlan-aware yes"; | |
162 | push @iface_config, "bridge-vids 2-4094"; | |
163 | } | |
3dfdc684 AD |
164 | push @iface_config, "mtu $mtu" if $mtu; |
165 | push @iface_config, "alias $alias" if $alias; | |
166 | push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid}; | |
167 | ||
20e19696 AD |
168 | } |
169 | ||
58433186 | 170 | sub status { |
4d7cc94f | 171 | my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_; |
58433186 AD |
172 | |
173 | my $bridge = $plugin_config->{bridge}; | |
4d7cc94f AD |
174 | my $err_msg = []; |
175 | ||
176 | if (!-d "/sys/class/net/$bridge") { | |
177 | push @$err_msg, "missing $bridge"; | |
178 | return $err_msg; | |
179 | } | |
180 | ||
fdf22d5f AD |
181 | my $vlan_aware = PVE::Network::SDN::Zones::Plugin::is_vlanaware($bridge); |
182 | my $is_ovs = PVE::Network::SDN::Zones::Plugin::is_ovs($bridge); | |
4d7cc94f AD |
183 | |
184 | my $tag = $vnet->{tag}; | |
185 | my $vnet_uplink = "ln_".$vnetid; | |
186 | my $vnet_uplinkpeer = "pr_".$vnetid; | |
187 | ||
188 | # ifaces to check | |
189 | my $ifaces = [ $vnetid, $bridge ]; | |
190 | if($is_ovs) { | |
191 | my $svlan_iface = "sv_".$zone; | |
192 | my $zonebridge = "z_$zone"; | |
193 | push @$ifaces, $svlan_iface; | |
194 | push @$ifaces, $zonebridge; | |
195 | } elsif ($vlan_aware) { | |
196 | my $zonebridge = "z_$zone"; | |
197 | push @$ifaces, $zonebridge; | |
58433186 | 198 | } else { |
4d7cc94f AD |
199 | my $svlan_iface = "sv_$vnetid"; |
200 | my $cvlan_iface = "cv_$vnetid"; | |
201 | push @$ifaces, $svlan_iface; | |
202 | push @$ifaces, $cvlan_iface; | |
203 | } | |
204 | ||
205 | foreach my $iface (@{$ifaces}) { | |
206 | if (!$status->{$iface}->{status}) { | |
207 | push @$err_msg, "missing $iface"; | |
208 | } elsif ($status->{$iface}->{status} ne 'pass') { | |
209 | push @$err_msg, "error $iface"; | |
210 | } | |
58433186 | 211 | } |
4d7cc94f | 212 | return $err_msg; |
58433186 AD |
213 | } |
214 | ||
5ca07ed9 | 215 | sub vnet_update_hook { |
88d9562b AD |
216 | my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_; |
217 | ||
218 | my $vnet = $vnet_cfg->{ids}->{$vnetid}; | |
219 | my $tag = $vnet->{tag}; | |
1d44ce70 | 220 | |
5ca07ed9 AD |
221 | raise_param_exc({ tag => "missing vlan tag"}) if !defined($vnet->{tag}); |
222 | raise_param_exc({ tag => "vlan tag max value is 4096"}) if $vnet->{tag} > 4096; | |
88d9562b AD |
223 | |
224 | # verify that tag is not already defined in another vnet on same zone | |
225 | foreach my $id (keys %{$vnet_cfg->{ids}}) { | |
226 | next if $id eq $vnetid; | |
227 | my $othervnet = $vnet_cfg->{ids}->{$id}; | |
228 | my $other_tag = $othervnet->{tag}; | |
229 | next if $vnet->{zone} ne $othervnet->{zone}; | |
230 | raise_param_exc({ tag => "tag $tag already exist in vnet $id"}) if $other_tag && $tag eq $other_tag; | |
231 | } | |
1d44ce70 AD |
232 | } |
233 | ||
20e19696 AD |
234 | 1; |
235 | ||
236 |