]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/QinQPlugin.pm
split transport/controllers/vnet to separate plugins
[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-allowed' => { optional => 1 },
35 'vlan-protocol' => { optional => 1 },
36 };
37 }
38
39 # Plugin implementation
40 sub generate_sdn_config {
41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
42
43 my $tag = $vnet->{tag};
44 my $transport_tag = $plugin_config->{tag};
45 my $mtu = $vnet->{mtu};
46 my $alias = $vnet->{alias};
47 my $vlanprotocol = $plugin_config->{'vlan-protocol'};
48 my $uplink = $plugin_config->{'uplink-id'};
49 my $vlanallowed = $plugin_config->{'vlan-allowed'};
50
51 die "missing vlan tag" if !$tag;
52 die "missing transport vlan tag" if !$transport_tag;
53
54 my $iface = $uplinks->{$uplink}->{name};
55 $iface = "uplink${uplink}" if !$iface;
56 $iface .= ".$transport_tag";
57
58 #tagged interface
59 my @iface_config = ();
60 push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
61 push @iface_config, "mtu $mtu" if $mtu;
62 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
63
64 $iface .= ".$tag";
65 #vnet bridge
66 @iface_config = ();
67 push @iface_config, "bridge_ports $iface";
68 push @iface_config, "bridge_stp off";
69 push @iface_config, "bridge_fd 0";
70 push @iface_config, "mtu $mtu" if $mtu;
71 push @iface_config, "alias $alias" if $alias;
72 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
73
74 return $config;
75 }
76
77 1;
78
79