[pve-devel] [PATCH pve-network 1/7] vlan/qinq: use bridge option instead uplink-id

Alexandre Derumier aderumier at odiso.com
Mon Feb 10 17:26:04 CET 2020


---
 PVE/Network/SDN/Zones/FaucetPlugin.pm |  2 +-
 PVE/Network/SDN/Zones/QinQPlugin.pm   | 63 +++++++++------------------
 PVE/Network/SDN/Zones/VlanPlugin.pm   | 36 ++-------------
 test/documentation.txt                |  8 ++--
 4 files changed, 29 insertions(+), 80 deletions(-)

diff --git a/PVE/Network/SDN/Zones/FaucetPlugin.pm b/PVE/Network/SDN/Zones/FaucetPlugin.pm
index 6093723..ef422ca 100644
--- a/PVE/Network/SDN/Zones/FaucetPlugin.pm
+++ b/PVE/Network/SDN/Zones/FaucetPlugin.pm
@@ -24,7 +24,7 @@ sub options {
     return {
         nodes => { optional => 1},
 	'dp-id' => { optional => 0 },
-	'uplink-id' => { optional => 0 },
+#	'uplink-id' => { optional => 0 },
         'controller' => { optional => 0 },
     };
 }
diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/QinQPlugin.pm
index d3f4b7d..08448dc 100644
--- a/PVE/Network/SDN/Zones/QinQPlugin.pm
+++ b/PVE/Network/SDN/Zones/QinQPlugin.pm
@@ -16,13 +16,6 @@ sub properties {
             type => 'integer',
             description => "vlan tag",
         },
-	'vlan-protocol' => {
-	    type => 'string',
-            enum => ['802.1q', '802.1ad'],
-	    default => '802.1q',
-	    optional => 1,
-	    description => "vlan protocol",
-	}
     };
 }
 
@@ -30,9 +23,8 @@ sub options {
 
     return {
         nodes => { optional => 1},
-	'uplink-id' => { optional => 0 },
 	'tag' => { optional => 0 },
-	'vlan-protocol' => { optional => 1 },
+	'bridge' => { optional => 0 },
     };
 }
 
@@ -40,43 +32,28 @@ sub options {
 sub generate_sdn_config {
     my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
 
-    my $tag = $vnet->{tag};
-    my $zone_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 $tag = $plugin_config->{tag};
+    my $mtu = $plugin_config->{mtu};
+    my $bridge = $plugin_config->{'bridge'};
 
     die "missing vlan tag" if !$tag;
-    die "missing zone vlan tag" if !$zone_tag;
 
-    my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink);
-
-    #service vlan
-    my @iface_config = ();
-    push @iface_config, "vlan-raw-device $iface";
-    push @iface_config, "vlan-id $zone_tag";
-    push @iface_config, "vlan-protocol $vlanprotocol" if $vlanprotocol;
-    push @iface_config, "mtu $mtu" if $mtu;
-    push(@{$config->{"qinq$zoneid"}}, @iface_config) if !$config->{$iface};
-
-    #customer vlan
-    @iface_config = ();
-    push @iface_config, "vlan-raw-device qinq$zoneid";
-    push @iface_config, "vlan-id $tag";
-    push @iface_config, "mtu $mtu" if $mtu;
-    push(@{$config->{"vlan$vnetid"}}, @iface_config) if !$config->{$iface};
-
-    #vnet bridge
-    @iface_config = ();
-    push @iface_config, "bridge_ports vlan$vnetid";
-    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;
+    if (!$config->{$zoneid}) {
+	#zone vlan bridge
+	my @iface_config = ();
+	push @iface_config, "mtu $mtu" if $mtu;
+	push @iface_config, "bridge-stp off";
+	push @iface_config, "bridge-fd 0";
+	push @iface_config, "bridge-vlan-aware yes";
+	push @iface_config, "bridge-vids 2-4094";
+	push(@{$config->{$zoneid}}, @iface_config);
+
+	#main bridge. ifupdown2 will merge it
+	@iface_config = ();
+	push @iface_config, "bridge-ports $zoneid.$tag";
+	push(@{$config->{$bridge}}, @iface_config);
+	return $config;
+    }
 }
 
 1;
diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm
index af76b43..0fb4aa7 100644
--- a/PVE/Network/SDN/Zones/VlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VlanPlugin.pm
@@ -21,10 +21,8 @@ sub pve_verify_sdn_vlanrange {
 
 sub properties {
     return {
-	'uplink-id' => {
-	    type => 'integer',
-	    minimum => 1, maximum => 4096,
-	    description => 'Uplink interface',
+	'bridge' => {
+	    type => 'string',
 	},
     };
 }
@@ -33,40 +31,14 @@ sub options {
 
     return {
         nodes => { optional => 1},
-	'uplink-id' => { optional => 0 },
+	'bridge' => { optional => 0 },
     };
 }
 
 # Plugin implementation
 sub generate_sdn_config {
     my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
-
-    my $tag = $vnet->{tag};
-    my $mtu = $vnet->{mtu};
-    my $alias = $vnet->{alias};
-    my $uplink = $plugin_config->{'uplink-id'};
-
-    die "missing vlan tag" if !$tag;
-
-    my $iface = PVE::Network::SDN::Zones::Plugin::get_uplink_iface($interfaces_config, $uplink);
-
-    #tagged interface
-    my @iface_config = ();
-    push @iface_config, "mtu $mtu" if $mtu;
-    push @iface_config, "vlan-raw-device $iface";
-    push @iface_config, "vlan-id $tag";
-    push(@{$config->{"vlan$vnetid"}}, @iface_config) if !$config->{$iface};
-
-    #vnet bridge
-    @iface_config = ();
-    push @iface_config, "bridge_ports vlan$vnetid";
-    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;
+    return "";
 }
 
 1;
diff --git a/test/documentation.txt b/test/documentation.txt
index a091dc4..316e5af 100644
--- a/test/documentation.txt
+++ b/test/documentation.txt
@@ -2,7 +2,7 @@ Here a sample of command with pvesh to manage the sdn.
 
 
 #create a vlan transportzone
-pvesh create /cluster/sdn/zones/ --zone vlanzone --type vlan --uplink-id 1
+pvesh create /cluster/sdn/zones/ --zone vlanzone --type vlan --bridge vmbr0
 
 
 #create a layer2 vxlan unicast transportzone
@@ -19,11 +19,11 @@ pvesh create /cluster/sdn/zones/ --zone layer3evpnzone --type evpn --controller
 
 
 #create a vnet in the transportzone
-pvesh create /cluster/sdn/vnets/ --vnet vnet10 --type vnet --transportzone vlanzone --tag 10
+pvesh create /cluster/sdn/vnets/ --vnet vnet10 --type vnet --zone vlanzone --tag 10
 
 #create a vnet in the transportzone with ip for evpn routing
-pvesh create /cluster/sdn/vnets/ --vnet vnet11 --type vnet --transportzone layer3evpnzone --tag 11 --ipv4 10.0.0.1/24 --mac c8:1f:66:f8:62:8d
-pvesh create /cluster/sdn/vnets/ --vnet vnet12 --type vnet --transportzone layer3evpnzone --tag 12 --ipv4 10.0.1.1/24 --mac c8:1f:66:f8:62:8e
+pvesh create /cluster/sdn/vnets/ --vnet vnet11 --type vnet --zone layer3evpnzone --tag 11 --ipv4 10.0.0.1/24 --mac c8:1f:66:f8:62:8d
+pvesh create /cluster/sdn/vnets/ --vnet vnet12 --type vnet --zone layer3evpnzone --tag 12 --ipv4 10.0.1.1/24 --mac c8:1f:66:f8:62:8e
 
 
 #apply changes from /etc/pve/sdn.cfg.new to /etc/pve/sdn.cfg
-- 
2.20.1




More information about the pve-devel mailing list