]> git.proxmox.com Git - pve-network.git/commitdiff
add frr plugin
authorAlexandre Derumier <aderumier@odiso.com>
Thu, 29 Aug 2019 10:32:47 +0000 (12:32 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Tue, 3 Sep 2019 06:22:56 +0000 (08:22 +0200)
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN.pm
PVE/Network/SDN.pm
PVE/Network/SDN/FrrPlugin.pm [new file with mode: 0644]
PVE/Network/SDN/Makefile
PVE/Network/SDN/Plugin.pm

index 22b26f85be387e21b83d7400d1187f5ef56b7470..7ca5a5dfdff27072180a1ff3bcb8bfa868edd795 100644 (file)
@@ -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;
index 1b060e7dc7b47376b729388deec43d6fcb1eb2a3..9d61e087bacb733eb0e1701f1a8dbdc49c68f4a9 100644 (file)
@@ -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 (file)
index 0000000..4db9ba6
--- /dev/null
@@ -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;
+
+
index 19a8e35869d62be59c52201800e81313f4594de9..1930004c0e92ca852b61550a7b49524447113ce3 100644 (file)
@@ -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
index 36efbe17f8514c5e852a572a41080908d11e3512..11feb1228f6b748e866ec3d95444dc1d22f0e8f2 100644 (file)
@@ -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) = @_;