[pve-devel] [PATCH v2 pve-network 11/13] add update_delete hook on frr related options

Alexandre Derumier aderumier at odiso.com
Thu Aug 29 12:32:52 CEST 2019


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/SDN/FrrPlugin.pm   | 20 ++++++++++++++++---
 PVE/Network/SDN/VxlanPlugin.pm | 35 ++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 3 deletions(-)

diff --git a/PVE/Network/SDN/FrrPlugin.pm b/PVE/Network/SDN/FrrPlugin.pm
index 0ea6d48..a628cf2 100644
--- a/PVE/Network/SDN/FrrPlugin.pm
+++ b/PVE/Network/SDN/FrrPlugin.pm
@@ -73,13 +73,27 @@ sub generate_frr_config {
 }
 
 sub on_delete_hook {
-    my ($class, $transportid, $sdn_cfg) = @_;
+    my ($class, $routerid, $sdn_cfg) = @_;
 
+    # verify that transport is associated to this router
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+        my $sdn = $sdn_cfg->{ids}->{$id};
+        die "router $routerid is used by $id"
+            if (defined($sdn->{router}) && $sdn->{router} eq $routerid);
+    }
 }
 
 sub on_update_hook {
-    my ($class, $transportid, $sdn_cfg) = @_;
-
+    my ($class, $routerid, $sdn_cfg) = @_;
+
+    # verify that asn is not already used by another router
+    my $asn = $sdn_cfg->{ids}->{$routerid}->{asn};
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+	next if $id eq $routerid;
+        my $sdn = $sdn_cfg->{ids}->{$id};
+        die "asn $asn is already used by $id"
+            if (defined($sdn->{asn}) && $sdn->{asn} eq $asn);
+    }
 }
 
 1;
diff --git a/PVE/Network/SDN/VxlanPlugin.pm b/PVE/Network/SDN/VxlanPlugin.pm
index 99cd2af..b0b48c4 100644
--- a/PVE/Network/SDN/VxlanPlugin.pm
+++ b/PVE/Network/SDN/VxlanPlugin.pm
@@ -235,6 +235,41 @@ sub on_update_hook {
 	    }
 	}
     }
+
+    # verify that router exist
+    if (defined($sdn_cfg->{ids}->{$transportid}->{router})) {
+	my $router = $sdn_cfg->{ids}->{$transportid}->{router};
+	if (!defined($sdn_cfg->{ids}->{$router})) {
+	    die "router $router don't exist";
+	} else {
+	    die "$router is not a router type" if $sdn_cfg->{ids}->{$router}->{type} ne 'frr';
+	}
+
+	#vrf && vrf-vxlan need to be defined with router
+	my $vrf = $sdn_cfg->{ids}->{$transportid}->{vrf};
+	if (!defined($vrf)) {
+	    die "missing vrf option";
+	} else {
+	    # verify that vrf is not already declared in another transport
+	    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+		next if $id eq $transportid;
+		die "vrf $vrf is already declared in $id"
+			if (defined($sdn_cfg->{ids}->{$id}->{vrf}) && $sdn_cfg->{ids}->{$id}->{vrf} eq $vrf);
+	    }
+	}
+
+	my $vrfvxlan = $sdn_cfg->{ids}->{$transportid}->{'vrf-vxlan'};
+	if (!defined($vrfvxlan)) {
+	    die "missing vrf-vxlan option";
+	} else {
+	    # verify that vrf-vxlan is not already declared in another transport
+	    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+		next if $id eq $transportid;
+		die "vrf-vxlan $vrfvxlan is already declared in $id"
+			if (defined($sdn_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
+	    }
+	}
+    } 
 }
 
 1;
-- 
2.20.1



More information about the pve-devel mailing list