]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/QinQPlugin.pm
zones: vxlan : remove uplink-id and multicast
[pve-network.git] / PVE / Network / SDN / Zones / QinQPlugin.pm
CommitLineData
f5eabba0 1package PVE::Network::SDN::Zones::QinQPlugin;
20e19696
AD
2
3use strict;
4use warnings;
f5eabba0 5use PVE::Network::SDN::Zones::VlanPlugin;
20e19696 6
f5eabba0 7use base('PVE::Network::SDN::Zones::VlanPlugin');
20e19696
AD
8
9sub type {
10 return 'qinq';
11}
12
20e19696
AD
13sub properties {
14 return {
f5eabba0
AD
15 tag => {
16 type => 'integer',
17 description => "vlan tag",
18 },
20e19696
AD
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
29sub options {
30
31 return {
c2b9c173 32 nodes => { optional => 1},
20e19696
AD
33 'uplink-id' => { optional => 0 },
34 'tag' => { optional => 0 },
20e19696
AD
35 'vlan-protocol' => { optional => 1 },
36 };
37}
38
39# Plugin implementation
40sub generate_sdn_config {
ba7ac021 41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
20e19696
AD
42
43 my $tag = $vnet->{tag};
56cdcac9 44 my $zone_tag = $plugin_config->{tag};
20e19696
AD
45 my $mtu = $vnet->{mtu};
46 my $alias = $vnet->{alias};
47 my $vlanprotocol = $plugin_config->{'vlan-protocol'};
48 my $uplink = $plugin_config->{'uplink-id'};
20e19696
AD
49
50 die "missing vlan tag" if !$tag;
56cdcac9 51 die "missing zone vlan tag" if !$zone_tag;
20e19696 52
ba7ac021
AD
53 #check uplinks
54 my $uplinks = {};
55 foreach my $id (keys %{$interfaces_config->{ifaces}}) {
56 my $interface = $interfaces_config->{ifaces}->{$id};
57 if (my $uplink = $interface->{'uplink-id'}) {
58 die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
59 $interface->{name} = $id;
60 $uplinks->{$interface->{'uplink-id'}} = $interface;
61 }
62 }
63
20e19696
AD
64 my $iface = $uplinks->{$uplink}->{name};
65 $iface = "uplink${uplink}" if !$iface;
56cdcac9 66 $iface .= ".$zone_tag";
20e19696
AD
67
68 #tagged interface
69 my @iface_config = ();
70 push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
71 push @iface_config, "mtu $mtu" if $mtu;
72 push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
73
74 $iface .= ".$tag";
75 #vnet bridge
76 @iface_config = ();
77 push @iface_config, "bridge_ports $iface";
78 push @iface_config, "bridge_stp off";
79 push @iface_config, "bridge_fd 0";
80 push @iface_config, "mtu $mtu" if $mtu;
81 push @iface_config, "alias $alias" if $alias;
82 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
83
84 return $config;
85}
86
871;
88
89