]> git.proxmox.com Git - pve-network.git/commitdiff
evpn: remove uplink-id
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 28 Nov 2019 08:40:24 +0000 (09:40 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 28 Nov 2019 13:15:25 +0000 (14:15 +0100)
instead, auto find interfaces

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/Network/SDN/Controllers/EvpnPlugin.pm
PVE/Network/SDN/Controllers/Plugin.pm
PVE/Network/SDN/Zones.pm
PVE/Network/SDN/Zones/EvpnPlugin.pm
PVE/Network/SDN/Zones/FaucetPlugin.pm
PVE/Network/SDN/Zones/Plugin.pm
PVE/Network/SDN/Zones/QinQPlugin.pm
PVE/Network/SDN/Zones/VlanPlugin.pm
PVE/Network/SDN/Zones/VxlanPlugin.pm
test/documentation.txt

index 0693e2133e28b62a759191e3c8138476b2b2672d..66b4568ea680ed889787e73cbdb7e414c21f1d48 100644 (file)
@@ -3,7 +3,7 @@ package PVE::Network::SDN::Controllers::EvpnPlugin;
 use strict;
 use warnings;
 use PVE::Network::SDN::Controllers::Plugin;
 use strict;
 use warnings;
 use PVE::Network::SDN::Controllers::Plugin;
-use PVE::Tools;
+use PVE::Tools qw(run_command);
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 
 use PVE::INotify;
 use PVE::JSONSchema qw(get_standard_option);
 
@@ -15,11 +15,6 @@ sub type {
 
 sub properties {
     return {
 
 sub properties {
     return {
-       'uplink-id' => {
-           type => 'integer',
-           minimum => 1, maximum => 4096,
-           description => 'Uplink interface',
-       },
         'asn' => {
             type => 'integer',
             description => "autonomous system number",
         'asn' => {
             type => 'integer',
             description => "autonomous system number",
@@ -39,7 +34,6 @@ sub properties {
 sub options {
 
     return {
 sub options {
 
     return {
-       'uplink-id' => { optional => 0 },
         'asn' => { optional => 0 },
         'peers' => { optional => 0 },
        'gateway-nodes' => { optional => 1 },
         'asn' => { optional => 0 },
         'peers' => { optional => 0 },
        'gateway-nodes' => { optional => 1 },
@@ -47,6 +41,46 @@ sub options {
     };
 }
 
     };
 }
 
+sub get_local_route_ip {
+    my ($targetip) = @_;
+
+    my $ip = undef;
+    my $interface = undef;
+
+    run_command(['/sbin/ip', 'route', 'get', $targetip], outfunc => sub {
+        if ($_[0] =~ m/src ($PVE::Tools::IPRE)/) {
+           $ip = $1;
+        }
+        if ($_[0] =~ m/dev (\S+)/) {
+           $interface = $1;
+        }
+
+    });
+    return ($ip, $interface);
+}
+
+sub find_local_ip_interface {
+    my ($peers) = @_;
+
+    my $network_config = PVE::INotify::read_file('interfaces');
+    my $ifaces = $network_config->{ifaces};
+    #is a local ip member of peers list ?
+    foreach my $address (@{$peers}) {
+       while (my $interface = each %$ifaces) {
+           my $ip = $ifaces->{$interface}->{address};
+           if ($ip && $ip eq $address) {
+               return ($ip, $interface);
+           }
+       }
+    }
+
+    #if peer is remote, find source with ip route
+    foreach my $address (@{$peers}) {
+       my ($ip, $interface) = get_local_route_ip($address);
+       return ($ip, $interface);
+    }
+}
+
 # Plugin implementation
 sub generate_controller_config {
     my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
 # Plugin implementation
 sub generate_controller_config {
     my ($class, $plugin_config, $controller, $id, $uplinks, $config) = @_;
@@ -54,19 +88,12 @@ sub generate_controller_config {
     my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
 
     my $asn = $plugin_config->{asn};
     my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
 
     my $asn = $plugin_config->{asn};
-    my $uplink = $plugin_config->{'uplink-id'};
     my $gatewaynodes = $plugin_config->{'gateway-nodes'};
     my @gatewaypeers = split(',', $plugin_config->{'gateway-external-peers'}) if $plugin_config->{'gateway-external-peers'};
 
     return if !$asn;
 
     my $gatewaynodes = $plugin_config->{'gateway-nodes'};
     my @gatewaypeers = split(',', $plugin_config->{'gateway-external-peers'}) if $plugin_config->{'gateway-external-peers'};
 
     return if !$asn;
 
-    my $iface = "uplink$uplink";
-    my $ifaceip = "";
-
-    if($uplinks->{$uplink}->{name}) {
-       $iface = $uplinks->{$uplink}->{name};
-        $ifaceip = PVE::Network::SDN::Controllers::Plugin::get_first_local_ipv4_from_interface($iface);
-    }
+    my ($ifaceip, $interface) = find_local_ip_interface(\@peers);
 
     my $is_gateway = undef;
     my $local_node = PVE::INotify::nodename();
 
     my $is_gateway = undef;
     my $local_node = PVE::INotify::nodename();
index ce35574a025717cfa98080369f4609940a3f36cd..04eddca95e30df41702287eb5d41f83578cbe305 100644 (file)
@@ -107,28 +107,4 @@ sub on_update_hook {
     # do nothing by default
 }
 
     # do nothing by default
 }
 
-#helpers
-
-#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;
 1;
index 84ce60ce185c380f929f91330275a59a7b6d3963..022d061890ca06af96308a73a873db91d0fe80be 100644 (file)
@@ -76,6 +76,7 @@ sub generate_etc_network_config {
 
     my $vnet_cfg = PVE::Cluster::cfs_read_file('sdn/vnets.cfg');
     my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
 
     my $vnet_cfg = PVE::Cluster::cfs_read_file('sdn/vnets.cfg');
     my $zone_cfg = PVE::Cluster::cfs_read_file('sdn/zones.cfg');
+    my $controller_cfg = PVE::Cluster::cfs_read_file('sdn/controllers.cfg');
     return if !$vnet_cfg && !$zone_cfg;
 
     #read main config for physical interfaces
     return if !$vnet_cfg && !$zone_cfg;
 
     #read main config for physical interfaces
@@ -117,8 +118,14 @@ sub generate_etc_network_config {
 
        next if defined($plugin_config->{nodes}) && !$plugin_config->{nodes}->{$nodename};
 
 
        next if defined($plugin_config->{nodes}) && !$plugin_config->{nodes}->{$nodename};
 
+       my $controller = undef;
+       if($plugin_config->{controller}) {
+           my $controllerid = $plugin_config->{controller};
+           $controller = $controller_cfg->{ids}->{$controllerid};
+       }
+
        my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
        my $plugin = PVE::Network::SDN::Zones::Plugin->lookup($plugin_config->{type});
-       $plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $uplinks, $config);
+       $plugin->generate_sdn_config($plugin_config, $zone, $id, $vnet, $uplinks, $controller, $config);
     }
 
     my $raw_network_config = "";
     }
 
     my $raw_network_config = "";
index 62382fb482ddd25672d4801c9f056ce26645fff0..c80408a7426f1876251c1302bebb8b3884056fbd 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
+use PVE::Network::SDN::Controllers::EvpnPlugin;
 
 use base('PVE::Network::SDN::Zones::VxlanPlugin');
 
 
 use base('PVE::Network::SDN::Zones::VxlanPlugin');
 
@@ -29,7 +30,6 @@ sub options {
 
     return {
         nodes => { optional => 1},
 
     return {
         nodes => { optional => 1},
-       'uplink-id' => { optional => 0 },
         'vrf-vxlan' => { optional => 0 },
         'controller' => { optional => 0 },
     };
         'vrf-vxlan' => { optional => 0 },
         'controller' => { optional => 0 },
     };
@@ -37,7 +37,7 @@ sub options {
 
 # Plugin implementation
 sub generate_sdn_config {
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
@@ -45,21 +45,16 @@ sub generate_sdn_config {
     my $ipv6 = $vnet->{ipv6};
     my $mac = $vnet->{mac};
 
     my $ipv6 = $vnet->{ipv6};
     my $mac = $vnet->{mac};
 
-    my $uplink = $plugin_config->{'uplink-id'};
     my $vrf = $zoneid;
     my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
 
     die "missing vxlan tag" if !$tag;
     my $vrf = $zoneid;
     my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
 
     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 @peers = split(',', $controller->{'peers'});
+    my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
 
     my $mtu = 1450;
 
     my $mtu = 1450;
-    $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu};
+    $mtu = $uplinks->{$iface}->{mtu} - 50 if $uplinks->{$iface}->{mtu};
     $mtu = $vnet->{mtu} if $vnet->{mtu};
 
     #vxlan interface
     $mtu = $vnet->{mtu} if $vnet->{mtu};
 
     #vxlan interface
index bece4e4a04a2cd93ef5b79391df38180c992a1cb..609372371460cbb3676a9d9e05edb1ba1a9a01dc 100644 (file)
@@ -31,7 +31,7 @@ sub options {
 
 # Plugin implementation
 sub generate_sdn_config {
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     my $mtu = $vnet->{mtu};
     my $uplink = $plugin_config->{'uplink-id'};
 
     my $mtu = $vnet->{mtu};
     my $uplink = $plugin_config->{'uplink-id'};
index 5d9aeff1d3b2fefc6224a4796c461aa6ee0ba74a..7dd66e25a2d39f5a289a80dd8acd0ea75bdbf6b3 100644 (file)
@@ -96,7 +96,7 @@ sub parse_section_header {
 }
 
 sub generate_sdn_config {
 }
 
 sub generate_sdn_config {
-    my ($class, $plugin_config, $node, $data, $ctime) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     die "please implement inside plugin";
 }
 
     die "please implement inside plugin";
 }
index 2036620ef254233c3d64e7766d75edf666696a98..42b0decb86d5e9aa56a1f7c607f7ad57c134f005 100644 (file)
@@ -38,7 +38,7 @@ sub options {
 
 # Plugin implementation
 sub generate_sdn_config {
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     my $tag = $vnet->{tag};
     my $zone_tag = $plugin_config->{tag};
 
     my $tag = $vnet->{tag};
     my $zone_tag = $plugin_config->{tag};
index 8f957f341315f3ded3d4e5ea0e6fda529afa9f6a..8951e9ba2687efb325910a5b83f296cbfac25c6f 100644 (file)
@@ -39,7 +39,7 @@ sub options {
 
 # Plugin implementation
 sub generate_sdn_config {
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     my $tag = $vnet->{tag};
     my $mtu = $vnet->{mtu};
 
     my $tag = $vnet->{tag};
     my $mtu = $vnet->{mtu};
index 956c950c40e6fc7686611ea2293aabe32f98ccbc..a95d794ed561503428b978b157802b69aba6dc74 100644 (file)
@@ -65,7 +65,7 @@ sub options {
 
 # Plugin implementation
 sub generate_sdn_config {
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
index 82e7e1495fddc40d625d5d85971496c9811344f2..575027b36d1b9af0948787afe5eade35c72bd7b3 100644 (file)
@@ -12,13 +12,13 @@ pvesh create /cluster/sdn/zones/ --zone vxlanmulticastzone --type vxlan --uplink
 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
 
 #create an controller
 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
 
 #create an controller
-pvesh create /cluster/sdn/controllers/ --controller frrrouter1 --type evpn --uplink-id 1 --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
+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
 
 #create a layer2 vxlan bgpevpn transportzone
 
 #create a layer2 vxlan bgpevpn transportzone
-pvesh create /cluster/sdn/zones/ --zone layer2evpnzone --type evpn --uplink-id 1 --controller frrrouter1
+pvesh create /cluster/sdn/zones/ --zone layer2evpnzone --type evpn --controller frrrouter1
 
 #create a layer3 routable vxlan bgpevpn transportzone
 
 #create a layer3 routable vxlan bgpevpn transportzone
-pvesh create /cluster/sdn/zones/ --zone layer3evpnzone --type evpn --uplink-id 1 --controller frrrouter1 --vrf-vxlan 4000
+pvesh create /cluster/sdn/zones/ --zone layer3evpnzone --type evpn --controller frrrouter1 --vrf-vxlan 4000
 
 
 #create a vnet in the transportzone
 
 
 #create a vnet in the transportzone