]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/VxlanPlugin.pm
make sdn controller plugin generic
[pve-network.git] / PVE / Network / SDN / VxlanPlugin.pm
index 3e18de356d16719426b61809f80c387b2db5e9c6..986a250a7629357c8a273effd38a8cc11fa80b8f 100644 (file)
@@ -3,9 +3,8 @@ package PVE::Network::SDN::VxlanPlugin;
 use strict;
 use warnings;
 use PVE::Network::SDN::Plugin;
-use PVE::Tools;
+use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
-use PVE::JSONSchema qw(get_standard_option);
 
 use base('PVE::Network::SDN::Plugin');
 
@@ -18,10 +17,35 @@ 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 plugindata {
+    return {
+        role => 'transport',
+    };
+}
+
 sub properties {
     return {
         'vxlan-allowed' => {
@@ -30,11 +54,11 @@ sub properties {
         },
         'multicast-address' => {
             description => "Multicast address.",
-            type => 'string',  #fixme: format
+            type => 'string', format => 'ipv4-multicast'
         },
        'unicast-address' => {
            description => "Unicast peers address ip list.",
-           type => 'string',  #fixme: format
+           type => 'string',  format => 'ip-list'
        },
        'vrf' => {
            description => "vrf name.",
@@ -44,11 +68,10 @@ sub properties {
            type => 'integer',
            description => "l3vni.",
        },
-       'router' => {
+       'controller' => {
            type => 'string',
            description => "Frr router name",
        },
-       'gateway-nodes' => get_standard_option('pve-node-list'),
     };
 }
 
@@ -61,8 +84,7 @@ sub options {
         'vxlan-allowed' => { optional => 1 },
         'vrf' => { optional => 1 },
         'vrf-vxlan' => { optional => 1 },
-        'router' => { optional => 1 },
-        'gateway-nodes' => { optional => 1 },
+        'controller' => { optional => 1 },
     };
 }
 
@@ -166,19 +188,20 @@ sub generate_sdn_config {
     return $config;
 }
 
-sub generate_frr_config {
-    my ($class, $plugin_config, $asn, $id, $uplinks, $config) = @_;
+sub generate_controller_config {
+    my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
 
     my $vrf = $plugin_config->{'vrf'};
     my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
-    my $gatewaynodes = $plugin_config->{'gateway-nodes'};
+    my $asn = $router->{asn};
+    my $gatewaynodes = $router->{'gateway-nodes'};
 
-    return if !$vrf || !$vrfvxlan;
+    return if !$vrf || !$vrfvxlan || !$asn;
 
     #vrf
     my @router_config = ();
     push @router_config, "vni $vrfvxlan";
-    push(@{$config->{vrf}->{"$vrf"}}, @router_config);
+    push(@{$config->{frr}->{vrf}->{"$vrf"}}, @router_config);
 
     @router_config = ();
 
@@ -196,17 +219,20 @@ sub generate_frr_config {
        #frr 7.1 tag is bugged -> works fine with 7.1 stable branch(20190829-02-g6ba76bbc1)
        #https://github.com/FRRouting/frr/issues/4905
        push @router_config, "import vrf $vrf";
-       push(@{$config->{router}->{"bgp $asn"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
+       push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
+       push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv6 unicast"}}, @router_config);
 
        @router_config = ();
        #redistribute connected to be able to route to local vms on the gateway
        push @router_config, "redistribute connected";
-       push(@{$config->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
+       push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
+       push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"ipv6 unicast"}}, @router_config);
 
        @router_config = ();
        #add default originate to announce 0.0.0.0/0 type5 route in evpn
        push @router_config, "default-originate ipv4";
-       push(@{$config->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
+       push @router_config, "default-originate ipv6";
+       push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
     }
 
     return $config;