[pve-devel] [PATCH v2 pve-network 06/13] add frr plugin

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


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Network/SDN.pm      |  1 +
 PVE/Network/SDN.pm           |  2 +
 PVE/Network/SDN/FrrPlugin.pm | 93 ++++++++++++++++++++++++++++++++++++
 PVE/Network/SDN/Makefile     |  2 +-
 PVE/Network/SDN/Plugin.pm    |  6 +++
 5 files changed, 103 insertions(+), 1 deletion(-)
 create mode 100644 PVE/Network/SDN/FrrPlugin.pm

diff --git a/PVE/API2/Network/SDN.pm b/PVE/API2/Network/SDN.pm
index 22b26f8..7ca5a5d 100644
--- a/PVE/API2/Network/SDN.pm
+++ b/PVE/API2/Network/SDN.pm
@@ -11,6 +11,7 @@ use PVE::Network::SDN::Plugin;
 use PVE::Network::SDN::VlanPlugin;
 use PVE::Network::SDN::VxlanPlugin;
 use PVE::Network::SDN::VnetPlugin;
+use PVE::Network::SDN::FrrPlugin;
 use Storable qw(dclone);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
diff --git a/PVE/Network/SDN.pm b/PVE/Network/SDN.pm
index 1b060e7..9d61e08 100644
--- a/PVE/Network/SDN.pm
+++ b/PVE/Network/SDN.pm
@@ -12,10 +12,12 @@ use PVE::Network::SDN::Plugin;
 use PVE::Network::SDN::VnetPlugin;
 use PVE::Network::SDN::VlanPlugin;
 use PVE::Network::SDN::VxlanPlugin;
+use PVE::Network::SDN::FrrPlugin;
 
 PVE::Network::SDN::VnetPlugin->register();
 PVE::Network::SDN::VlanPlugin->register();
 PVE::Network::SDN::VxlanPlugin->register();
+PVE::Network::SDN::FrrPlugin->register();
 PVE::Network::SDN::Plugin->init();
 
 
diff --git a/PVE/Network/SDN/FrrPlugin.pm b/PVE/Network/SDN/FrrPlugin.pm
new file mode 100644
index 0000000..4db9ba6
--- /dev/null
+++ b/PVE/Network/SDN/FrrPlugin.pm
@@ -0,0 +1,93 @@
+package PVE::Network::SDN::FrrPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::SDN::Plugin;
+use PVE::Tools;
+
+use base('PVE::Network::SDN::Plugin');
+
+sub type {
+    return 'frr';
+}
+
+sub properties {
+    return {
+        'asn' => {
+            type => 'integer',
+            description => "autonomous system number",
+        },
+        'peers' => {
+            description => "peers address list.",
+            type => 'string',  #fixme: format 
+        },
+    };
+}
+
+sub options {
+
+    return {
+	'uplink-id' => { optional => 0 },
+        'asn' => { optional => 0 },
+        'peers' => { optional => 0 },
+    };
+}
+
+# Plugin implementation
+sub generate_frr_config {
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks) = @_;
+
+    my $asn = $plugin_config->{'asn'};
+    my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
+
+    my $uplink = $plugin_config->{'uplink-id'};
+
+    die "missing peers" if !$plugin_config->{'peers'};
+
+    my $iface = "uplink$uplink";
+    my $ifaceip = "";
+
+    if($uplinks->{$uplink}->{name}) {
+	$iface = $uplinks->{$uplink}->{name};
+	$ifaceip = get_first_local_ipv4_from_interface($iface);
+    }
+
+    my $config = "\n";
+    $config .= "router bgp $asn\n";
+    $config .= "bgp router-id $ifaceip\n";
+    $config .= "no bgp default ipv4-unicast\n";
+    $config .= "coalesce-time 1000\n";
+
+    foreach my $address (@peers) {
+	next if $address eq $ifaceip;
+	$config .= "neighbor $address remote-as $asn\n";
+    } 
+    $config .= "!\n";
+    $config .= "address-family l2vpn evpn\n";
+    foreach my $address (@peers) {
+	next if $address eq $ifaceip;
+	$config .= " neighbor $address activate\n";
+    }
+    $config .= " advertise-all-vni\n";
+    $config .= "exit-address-family\n";
+    $config .= "!\n";
+    $config .= "line vty\n";
+    $config .= "!\n";
+
+
+    return $config;
+}
+
+sub on_delete_hook {
+    my ($class, $transportid, $sdn_cfg) = @_;
+
+}
+
+sub on_update_hook {
+    my ($class, $transportid, $sdn_cfg) = @_;
+
+}
+
+1;
+
+
diff --git a/PVE/Network/SDN/Makefile b/PVE/Network/SDN/Makefile
index 19a8e35..1930004 100644
--- a/PVE/Network/SDN/Makefile
+++ b/PVE/Network/SDN/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm  VxlanPlugin.pm
+SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FrrPlugin.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/Network/SDN/Plugin.pm b/PVE/Network/SDN/Plugin.pm
index 36efbe1..11feb12 100644
--- a/PVE/Network/SDN/Plugin.pm
+++ b/PVE/Network/SDN/Plugin.pm
@@ -71,6 +71,12 @@ sub generate_sdn_config {
     die "please implement inside plugin";
 }
 
+sub generate_frr_config {
+    my ($class, $plugin_config, $node, $data, $ctime) = @_;
+
+    die "please implement inside plugin";
+}
+
 sub on_delete_hook {
     my ($class, $sndid, $scfg) = @_;
 
-- 
2.20.1




More information about the pve-devel mailing list