]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/QinQPlugin.pm
734c56bbcf582f92bf32cc6584f16cd6b7ac9a90
[pve-network.git] / PVE / Network / SDN / Zones / QinQPlugin.pm
1 package PVE::Network::SDN::Zones::QinQPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Zones::VlanPlugin;
6
7 use base('PVE::Network::SDN::Zones::VlanPlugin');
8
9 sub type {
10 return 'qinq';
11 }
12
13 sub properties {
14 return {
15 tag => {
16 type => 'integer',
17 description => "vlan tag",
18 },
19 'vlan-protocol' => {
20 type => 'string',
21 enum => ['802.1q', '802.1ad'],
22 default => '802.1q',
23 optional => 1,
24 description => "vlan protocol",
25 }
26 };
27 }
28
29 sub options {
30
31 return {
32 'uplink-id' => { optional => 0 },
33 'tag' => { optional => 0 },
34 'vlan-protocol' => { optional => 1 },
35 };
36 }
37
38 # Plugin implementation
39 sub generate_sdn_config {
40 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
41
42 my $tag = $vnet->{tag};
43 my $transport_tag = $plugin_config->{tag};
44 my $mtu = $vnet->{mtu};
45 my $alias = $vnet->{alias};
46 my $vlanprotocol = $plugin_config->{'vlan-protocol'};
47 my $uplink = $plugin_config->{'uplink-id'};
48
49 die "missing vlan tag" if !$tag;
50 die "missing transport vlan tag" if !$transport_tag;
51
52 my $iface = $uplinks->{$uplink}->{name};
53 $iface = "uplink${uplink}" if !$iface;
54 $iface .= ".$transport_tag";
55
56 #tagged interface
57 my @iface_config = ();
58 push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
59 push @iface_config, "mtu $mtu" if $mtu;
60 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
61
62 $iface .= ".$tag";
63 #vnet bridge
64 @iface_config = ();
65 push @iface_config, "bridge_ports $iface";
66 push @iface_config, "bridge_stp off";
67 push @iface_config, "bridge_fd 0";
68 push @iface_config, "mtu $mtu" if $mtu;
69 push @iface_config, "alias $alias" if $alias;
70 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
71
72 return $config;
73 }
74
75 1;
76
77