[pve-devel] [PATCH pve-network 7/8] add qinq plugin
Alexandre Derumier
aderumier at odiso.com
Mon Sep 30 11:03:38 CEST 2019
move code from vlanplugin, add transport tag option
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Network/SDN.pm | 1 +
PVE/Network/SDN.pm | 2 +
PVE/Network/SDN/Makefile | 2 +-
PVE/Network/SDN/QinQPlugin.pm | 81 +++++++++++++++++++++++++++++++++++
PVE/Network/SDN/VlanPlugin.pm | 19 --------
5 files changed, 85 insertions(+), 20 deletions(-)
create mode 100644 PVE/Network/SDN/QinQPlugin.pm
diff --git a/PVE/API2/Network/SDN.pm b/PVE/API2/Network/SDN.pm
index 8294cb8..36d293d 100644
--- a/PVE/API2/Network/SDN.pm
+++ b/PVE/API2/Network/SDN.pm
@@ -15,6 +15,7 @@ use PVE::Network::SDN::FaucetControllerPlugin;
use PVE::Network::SDN::FaucetPlugin;
use PVE::Network::SDN::EvpnControllerPlugin;
use PVE::Network::SDN::EvpnPlugin;
+use PVE::Network::SDN::QinQPlugin;
use Storable qw(dclone);
use PVE::JSONSchema qw(get_standard_option);
diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm
index 8e8e637..96f76d1 100644
--- a/PVE/Network/SDN.pm
+++ b/PVE/Network/SDN.pm
@@ -16,6 +16,7 @@ use PVE::Network::SDN::FaucetPlugin;
use PVE::Network::SDN::FaucetControllerPlugin;
use PVE::Network::SDN::EvpnPlugin;
use PVE::Network::SDN::EvpnControllerPlugin;
+use PVE::Network::SDN::QinQPlugin;
PVE::Network::SDN::VnetPlugin->register();
PVE::Network::SDN::VlanPlugin->register();
@@ -24,6 +25,7 @@ PVE::Network::SDN::FaucetControllerPlugin->register();
PVE::Network::SDN::FaucetPlugin->register();
PVE::Network::SDN::EvpnPlugin->register();
PVE::Network::SDN::EvpnControllerPlugin->register();
+PVE::Network::SDN::QinQPlugin->register();
PVE::Network::SDN::Plugin->init();
diff --git a/PVE/Network/SDN/Makefile b/PVE/Network/SDN/Makefile
index ba8f903..232db52 100644
--- a/PVE/Network/SDN/Makefile
+++ b/PVE/Network/SDN/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FaucetControllerPlugin.pm FaucetPlugin.pm EvpnPlugin.pm EvpnControllerPlugin.pm
+SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FaucetControllerPlugin.pm FaucetPlugin.pm EvpnPlugin.pm EvpnControllerPlugin.pm QinQPlugin.pm
PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/Network/SDN/QinQPlugin.pm b/PVE/Network/SDN/QinQPlugin.pm
new file mode 100644
index 0000000..9f40e84
--- /dev/null
+++ b/PVE/Network/SDN/QinQPlugin.pm
@@ -0,0 +1,81 @@
+package PVE::Network::SDN::QinQPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::SDN::VlanPlugin;
+
+use base('PVE::Network::SDN::VlanPlugin');
+
+sub type {
+ return 'qinq';
+}
+
+sub plugindata {
+ return {
+ role => 'transport',
+ };
+}
+
+sub properties {
+ return {
+ 'vlan-protocol' => {
+ type => 'string',
+ enum => ['802.1q', '802.1ad'],
+ default => '802.1q',
+ optional => 1,
+ description => "vlan protocol",
+ }
+ };
+}
+
+sub options {
+
+ return {
+ 'uplink-id' => { optional => 0 },
+ 'tag' => { optional => 0 },
+ 'vlan-allowed' => { optional => 1 },
+ 'vlan-protocol' => { optional => 1 },
+ };
+}
+
+# Plugin implementation
+sub generate_sdn_config {
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+
+ my $tag = $vnet->{tag};
+ my $transport_tag = $plugin_config->{tag};
+ my $mtu = $vnet->{mtu};
+ my $alias = $vnet->{alias};
+ my $vlanprotocol = $plugin_config->{'vlan-protocol'};
+ my $uplink = $plugin_config->{'uplink-id'};
+ my $vlanallowed = $plugin_config->{'vlan-allowed'};
+
+ die "missing vlan tag" if !$tag;
+ die "missing transport vlan tag" if !$transport_tag;
+
+ my $iface = $uplinks->{$uplink}->{name};
+ $iface = "uplink${uplink}" if !$iface;
+ $iface .= ".$transport_tag";
+
+ #tagged interface
+ my @iface_config = ();
+ push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
+ push @iface_config, "mtu $mtu" if $mtu;
+ push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
+
+ $iface .= ".$tag";
+ #vnet bridge
+ @iface_config = ();
+ push @iface_config, "bridge_ports $iface";
+ push @iface_config, "bridge_stp off";
+ push @iface_config, "bridge_fd 0";
+ push @iface_config, "mtu $mtu" if $mtu;
+ push @iface_config, "alias $alias" if $alias;
+ push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
+
+ return $config;
+}
+
+1;
+
+
diff --git a/PVE/Network/SDN/VlanPlugin.pm b/PVE/Network/SDN/VlanPlugin.pm
index 6078206..5a38f59 100644
--- a/PVE/Network/SDN/VlanPlugin.pm
+++ b/PVE/Network/SDN/VlanPlugin.pm
@@ -36,17 +36,6 @@ sub properties {
type => 'string', format => 'pve-sdn-vlanrange',
description => "Allowed vlan range",
},
- 'vlan-aware' => {
- type => 'boolean',
- description => "enable 802.1q stacked vlan",
- },
- 'vlan-protocol' => {
- type => 'string',
- enum => ['802.1q', '802.1ad'],
- default => '802.1q',
- optional => 1,
- description => "vlan protocol",
- }
};
}
@@ -55,9 +44,6 @@ sub options {
return {
'uplink-id' => { optional => 0 },
'vlan-allowed' => { optional => 1 },
- 'vlan-protocol' => { optional => 1 },
- 'vlan-aware' => { optional => 1 },
-
};
}
@@ -68,10 +54,7 @@ sub generate_sdn_config {
my $tag = $vnet->{tag};
my $mtu = $vnet->{mtu};
my $alias = $vnet->{alias};
- my $vlanaware = $plugin_config->{'vlan-aware'};
- my $vlanprotocol = $plugin_config->{'vlan-protocol'};
my $uplink = $plugin_config->{'uplink-id'};
- my $vlanallowed = $plugin_config->{'vlan-allowed'};
die "missing vlan tag" if !$tag;
@@ -81,7 +64,6 @@ sub generate_sdn_config {
#tagged interface
my @iface_config = ();
- push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
push @iface_config, "mtu $mtu" if $mtu;
push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
@@ -90,7 +72,6 @@ sub generate_sdn_config {
push @iface_config, "bridge_ports $iface";
push @iface_config, "bridge_stp off";
push @iface_config, "bridge_fd 0";
- push @iface_config, "bridge-vlan-aware yes" if $vlanaware;
push @iface_config, "mtu $mtu" if $mtu;
push @iface_config, "alias $alias" if $alias;
push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
--
2.20.1
More information about the pve-devel
mailing list