[pve-devel] [PATCH pve-network 2/4] zones: vxlan : remove uplink-id and multicast
Alexandre Derumier
aderumier at odiso.com
Thu Nov 28 09:40:25 CET 2019
only unicast for now, as multicast is not too much used currently.
remove uplink-id like for evpn
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Network/SDN/Zones.pm | 19 +--------
PVE/Network/SDN/Zones/EvpnPlugin.pm | 4 +-
PVE/Network/SDN/Zones/Plugin.pm | 24 +----------
PVE/Network/SDN/Zones/QinQPlugin.pm | 13 +++++-
PVE/Network/SDN/Zones/VlanPlugin.pm | 13 +++++-
PVE/Network/SDN/Zones/VxlanPlugin.pm | 61 ++++++----------------------
test/documentation.txt | 5 +--
7 files changed, 42 insertions(+), 97 deletions(-)
diff --git a/PVE/Network/SDN/Zones.pm b/PVE/Network/SDN/Zones.pm
index 022d061..e707213 100644
--- a/PVE/Network/SDN/Zones.pm
+++ b/PVE/Network/SDN/Zones.pm
@@ -79,22 +79,7 @@ sub generate_etc_network_config {
my $controller_cfg = PVE::Cluster::cfs_read_file('sdn/controllers.cfg');
return if !$vnet_cfg && !$zone_cfg;
- #read main config for physical interfaces
- my $current_config_file = "/etc/network/interfaces";
- my $fh = IO::File->new($current_config_file);
- my $interfaces_config = PVE::INotify::read_etc_network_interfaces(1,$fh);
- $fh->close();
-
- #check uplinks
- my $uplinks = {};
- foreach my $id (keys %{$interfaces_config->{ifaces}}) {
- my $interface = $interfaces_config->{ifaces}->{$id};
- if (my $uplink = $interface->{'uplink-id'}) {
- die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
- $interface->{name} = $id;
- $uplinks->{$interface->{'uplink-id'}} = $interface;
- }
- }
+ my $interfaces_config = PVE::INotify::read_file('interfaces');
#generate configuration
my $config = {};
@@ -125,7 +110,7 @@ sub generate_etc_network_config {
}
my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
- $plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $uplinks, $controller, $config);
+ $plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $controller, $interfaces_config, $config);
}
my $raw_network_config = "";
diff --git a/PVE/Network/SDN/Zones/EvpnPlugin.pm b/PVE/Network/SDN/Zones/EvpnPlugin.pm
index c80408a..25c82c7 100644
--- a/PVE/Network/SDN/Zones/EvpnPlugin.pm
+++ b/PVE/Network/SDN/Zones/EvpnPlugin.pm
@@ -37,7 +37,7 @@ sub options {
# Plugin implementation
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
my $tag = $vnet->{tag};
my $alias = $vnet->{alias};
@@ -54,7 +54,7 @@ sub generate_sdn_config {
my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
my $mtu = 1450;
- $mtu = $uplinks->{$iface}->{mtu} - 50 if $uplinks->{$iface}->{mtu};
+ $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
$mtu = $vnet->{mtu} if $vnet->{mtu};
#vxlan interface
diff --git a/PVE/Network/SDN/Zones/Plugin.pm b/PVE/Network/SDN/Zones/Plugin.pm
index 7dd66e2..4d0732e 100644
--- a/PVE/Network/SDN/Zones/Plugin.pm
+++ b/PVE/Network/SDN/Zones/Plugin.pm
@@ -96,7 +96,7 @@ sub parse_section_header {
}
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
die "please implement inside plugin";
}
@@ -179,26 +179,4 @@ sub parse_tag_number_or_range {
return (scalar(@elements) > 1);
}
-#to be move to Network.pm helper
-sub get_first_local_ipv4_from_interface {
- my ($interface) = @_;
-
- my $cmd = ['/sbin/ip', 'address', 'show', 'dev', $interface];
-
- my $IP = "";
-
- my $code = sub {
- my $line = shift;
-
- if ($line =~ m!^\s*inet\s+($PVE::Tools::IPRE)(?:/\d+|\s+peer\s+)!) {
- $IP = $1;
- return;
- }
- };
-
- PVE::Tools::run_command($cmd, outfunc => $code);
-
- return $IP;
-}
-
1;
diff --git a/PVE/Network/SDN/Zones/QinQPlugin.pm b/PVE/Network/SDN/Zones/QinQPlugin.pm
index 42b0dec..63f4528 100644
--- a/PVE/Network/SDN/Zones/QinQPlugin.pm
+++ b/PVE/Network/SDN/Zones/QinQPlugin.pm
@@ -38,7 +38,7 @@ sub options {
# Plugin implementation
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
my $tag = $vnet->{tag};
my $zone_tag = $plugin_config->{tag};
@@ -50,6 +50,17 @@ sub generate_sdn_config {
die "missing vlan tag" if !$tag;
die "missing zone vlan tag" if !$zone_tag;
+ #check uplinks
+ my $uplinks = {};
+ foreach my $id (keys %{$interfaces_config->{ifaces}}) {
+ my $interface = $interfaces_config->{ifaces}->{$id};
+ if (my $uplink = $interface->{'uplink-id'}) {
+ die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
+ $interface->{name} = $id;
+ $uplinks->{$interface->{'uplink-id'}} = $interface;
+ }
+ }
+
my $iface = $uplinks->{$uplink}->{name};
$iface = "uplink${uplink}" if !$iface;
$iface .= ".$zone_tag";
diff --git a/PVE/Network/SDN/Zones/VlanPlugin.pm b/PVE/Network/SDN/Zones/VlanPlugin.pm
index 8951e9b..adb698f 100644
--- a/PVE/Network/SDN/Zones/VlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VlanPlugin.pm
@@ -39,7 +39,7 @@ sub options {
# Plugin implementation
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
my $tag = $vnet->{tag};
my $mtu = $vnet->{mtu};
@@ -48,6 +48,17 @@ sub generate_sdn_config {
die "missing vlan tag" if !$tag;
+ #check uplinks
+ my $uplinks = {};
+ foreach my $id (keys %{$interfaces_config->{ifaces}}) {
+ my $interface = $interfaces_config->{ifaces}->{$id};
+ if (my $uplink = $interface->{'uplink-id'}) {
+ die "uplink-id $uplink is already defined on $uplinks->{$uplink}" if $uplinks->{$uplink};
+ $interface->{name} = $id;
+ $uplinks->{$interface->{'uplink-id'}} = $interface;
+ }
+ }
+
my $iface = $uplinks->{$uplink}->{name};
$iface = "uplink${uplink}" if !$iface;
$iface .= ".$tag";
diff --git a/PVE/Network/SDN/Zones/VxlanPlugin.pm b/PVE/Network/SDN/Zones/VxlanPlugin.pm
index a95d794..66d8a95 100644
--- a/PVE/Network/SDN/Zones/VxlanPlugin.pm
+++ b/PVE/Network/SDN/Zones/VxlanPlugin.pm
@@ -5,6 +5,7 @@ use warnings;
use PVE::Network::SDN::Zones::Plugin;
use PVE::Tools qw($IPV4RE);
use PVE::INotify;
+use PVE::Network::SDN::Controllers::EvpnPlugin;
use base('PVE::Network::SDN::Zones::Plugin');
@@ -17,39 +18,16 @@ sub pve_verify_sdn_vxlanrange {
return $vxlanstr;
}
-PVE::JSONSchema::register_format('ipv4-multicast', \&parse_ipv4_multicast);
-sub parse_ipv4_multicast {
- my ($ipv4, $noerr) = @_;
-
- if ($ipv4 !~ m/^(?:$IPV4RE)$/) {
- return undef if $noerr;
- die "value does not look like a valid multicast IPv4 address\n";
- }
-
- if ($ipv4 =~ m/^(\d+)\.\d+.\d+.\d+/) {
- if($1 < 224 || $1 > 239) {
- return undef if $noerr;
- die "value does not look like a valid multicast IPv4 address\n";
- }
- }
-
- return $ipv4;
-}
-
sub type {
return 'vxlan';
}
sub properties {
return {
- 'multicast-address' => {
- description => "Multicast address.",
- type => 'string', format => 'ipv4-multicast'
+ 'peers' => {
+ description => "peers address list.",
+ type => 'string', format => 'ip-list'
},
- 'unicast-address' => {
- description => "Unicast peers address ip list.",
- type => 'string', format => 'ip-list'
- },
};
}
@@ -57,15 +35,13 @@ sub options {
return {
nodes => { optional => 1},
- 'uplink-id' => { optional => 0 },
- 'multicast-address' => { optional => 1 },
- 'unicast-address' => { optional => 1 },
+ peers => { optional => 0 },
};
}
# Plugin implementation
sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
my $tag = $vnet->{tag};
my $alias = $vnet->{alias};
@@ -73,36 +49,23 @@ sub generate_sdn_config {
my $ipv6 = $vnet->{ipv6};
my $mac = $vnet->{mac};
my $multicastaddress = $plugin_config->{'multicast-address'};
- my @unicastaddress = split(',', $plugin_config->{'unicast-address'}) if $plugin_config->{'unicast-address'};
-
- my $uplink = $plugin_config->{'uplink-id'};
+ my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
die "missing vxlan tag" if !$tag;
- my $iface = "uplink$uplink";
- my $ifaceip = "";
- if($uplinks->{$uplink}->{name}) {
- $iface = $uplinks->{$uplink}->{name};
- $ifaceip = PVE::Network::SDN::Zones::Plugin::get_first_local_ipv4_from_interface($iface);
- }
+ my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
my $mtu = 1450;
- $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu};
+ $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
$mtu = $vnet->{mtu} if $vnet->{mtu};
#vxlan interface
my @iface_config = ();
push @iface_config, "vxlan-id $tag";
- if($multicastaddress) {
- push @iface_config, "vxlan-svcnodeip $multicastaddress";
- push @iface_config, "vxlan-physdev $iface";
- } elsif (@unicastaddress) {
-
- foreach my $address (@unicastaddress) {
- next if $address eq $ifaceip;
- push @iface_config, "vxlan_remoteip $address";
- }
+ foreach my $address (@peers) {
+ next if $address eq $ifaceip;
+ push @iface_config, "vxlan_remoteip $address";
}
push @iface_config, "mtu $mtu" if $mtu;
diff --git a/test/documentation.txt b/test/documentation.txt
index 575027b..a091dc4 100644
--- a/test/documentation.txt
+++ b/test/documentation.txt
@@ -5,11 +5,8 @@ Here a sample of command with pvesh to manage the sdn.
pvesh create /cluster/sdn/zones/ --zone vlanzone --type vlan --uplink-id 1
-#create a layer2 vxlan multicast transportzone
-pvesh create /cluster/sdn/zones/ --zone vxlanmulticastzone --type vxlan --uplink-id 1 --multicast-address 239.192.114.23
-
#create a layer2 vxlan unicast transportzone
-pvesh create /cluster/sdn/zones/ --zone vxlanunicastzone --type vxlan --uplink-id 1 --unicast-address 192.168.0.1,192.168.0.2,192.168.0.3
+pvesh create /cluster/sdn/zones/ --zone vxlanunicastzone --type vxlan --peers 192.168.0.1,192.168.0.2,192.168.0.3
#create an controller
pvesh create /cluster/sdn/controllers/ --controller frrrouter1 --type evpn --peers 192.168.0.1,192.168.0.2,192.168.0.3 --asn 1234 --gateway-nodes pxnode1,pxnode2 --gateway-external-peers 192.168.0.253,192.168.0.254
--
2.20.1
More information about the pve-devel
mailing list