]>
Commit | Line | Data |
---|---|---|
f5eabba0 | 1 | package PVE::Network::SDN::Zones::QinQPlugin; |
20e19696 AD |
2 | |
3 | use strict; | |
4 | use warnings; | |
f5eabba0 | 5 | use PVE::Network::SDN::Zones::VlanPlugin; |
20e19696 | 6 | |
f5eabba0 | 7 | use base('PVE::Network::SDN::Zones::VlanPlugin'); |
20e19696 AD |
8 | |
9 | sub type { | |
10 | return 'qinq'; | |
11 | } | |
12 | ||
20e19696 AD |
13 | sub properties { |
14 | return { | |
f5eabba0 AD |
15 | tag => { |
16 | type => 'integer', | |
17 | description => "vlan tag", | |
18 | }, | |
823f2e2a AD |
19 | mtu => { |
20 | type => 'integer', | |
21 | description => "mtu", | |
22 | optional => 1, | |
23 | }, | |
20e19696 AD |
24 | }; |
25 | } | |
26 | ||
27 | sub options { | |
28 | ||
29 | return { | |
c2b9c173 | 30 | nodes => { optional => 1}, |
20e19696 | 31 | 'tag' => { optional => 0 }, |
938ebef7 | 32 | 'bridge' => { optional => 0 }, |
823f2e2a | 33 | 'mtu' => { optional => 1 }, |
20e19696 AD |
34 | }; |
35 | } | |
36 | ||
37 | # Plugin implementation | |
38 | sub generate_sdn_config { | |
ba7ac021 | 39 | my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_; |
20e19696 | 40 | |
938ebef7 AD |
41 | my $tag = $plugin_config->{tag}; |
42 | my $mtu = $plugin_config->{mtu}; | |
43 | my $bridge = $plugin_config->{'bridge'}; | |
20e19696 AD |
44 | |
45 | die "missing vlan tag" if !$tag; | |
20e19696 | 46 | |
938ebef7 AD |
47 | if (!$config->{$zoneid}) { |
48 | #zone vlan bridge | |
49 | my @iface_config = (); | |
50 | push @iface_config, "mtu $mtu" if $mtu; | |
51 | push @iface_config, "bridge-stp off"; | |
52 | push @iface_config, "bridge-fd 0"; | |
53 | push @iface_config, "bridge-vlan-aware yes"; | |
54 | push @iface_config, "bridge-vids 2-4094"; | |
55 | push(@{$config->{$zoneid}}, @iface_config); | |
56 | ||
57 | #main bridge. ifupdown2 will merge it | |
58 | @iface_config = (); | |
59 | push @iface_config, "bridge-ports $zoneid.$tag"; | |
60 | push(@{$config->{$bridge}}, @iface_config); | |
61 | return $config; | |
62 | } | |
20e19696 AD |
63 | } |
64 | ||
58433186 AD |
65 | sub status { |
66 | my ($class, $plugin_config, $zone, $id, $vnet, $err_config, $status, $vnet_status, $zone_status) = @_; | |
67 | ||
68 | my $bridge = $plugin_config->{bridge}; | |
69 | $vnet_status->{$id}->{zone} = $zone; | |
70 | $zone_status->{$zone}->{status} = 'available' if !defined($zone_status->{$zone}->{status}); | |
71 | ||
72 | if($err_config) { | |
73 | $vnet_status->{$id}->{status} = 'pending'; | |
74 | $vnet_status->{$id}->{statusmsg} = $err_config; | |
75 | $zone_status->{$zone}->{status} = 'pending'; | |
76 | } elsif ($status->{$bridge}->{status} && $status->{$bridge}->{status} eq 'pass') { | |
77 | $vnet_status->{$id}->{status} = 'available'; | |
78 | } else { | |
79 | $vnet_status->{$id}->{status} = 'error'; | |
80 | $vnet_status->{$id}->{statusmsg} = 'missing bridge'; | |
81 | $zone_status->{$zone}->{status} = 'error'; | |
82 | } | |
83 | } | |
84 | ||
2ba9613b AD |
85 | sub get_bridge_vlan { |
86 | my ($class, $plugin_config, $zoneid, $vnetid, $tag) = @_; | |
87 | ||
88 | my $bridge = $plugin_config->{bridge}; | |
89 | die "bridge $bridge is missing" if !-d "/sys/class/net/$bridge/"; | |
90 | ||
91 | my $vlan_aware = PVE::Tools::file_read_firstline("/sys/class/net/$bridge/bridge/vlan_filtering"); | |
92 | my $is_ovs = 1 if !-d "/sys/class/net/$bridge/brif"; | |
93 | ||
94 | die "ovs $bridge is not supported by qinq" if $is_ovs; | |
95 | die "bridge $bridge is not vlan aware" if !$vlan_aware; | |
96 | ||
97 | return ($bridge, $tag); | |
98 | } | |
99 | ||
20e19696 AD |
100 | 1; |
101 | ||
102 |