add frr plugin

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2019-08-29 12:32:47 +02:00 committed by Thomas Lamprecht
parent 3ee45e4ce1
commit 32602a38ae
5 changed files with 103 additions and 1 deletions

View File

@ -11,6 +11,7 @@ use PVE::Network::SDN::Plugin;
use PVE::Network::SDN::VlanPlugin; use PVE::Network::SDN::VlanPlugin;
use PVE::Network::SDN::VxlanPlugin; use PVE::Network::SDN::VxlanPlugin;
use PVE::Network::SDN::VnetPlugin; use PVE::Network::SDN::VnetPlugin;
use PVE::Network::SDN::FrrPlugin;
use Storable qw(dclone); use Storable qw(dclone);
use PVE::JSONSchema qw(get_standard_option); use PVE::JSONSchema qw(get_standard_option);
use PVE::RPCEnvironment; use PVE::RPCEnvironment;

View File

@ -12,10 +12,12 @@ use PVE::Network::SDN::Plugin;
use PVE::Network::SDN::VnetPlugin; use PVE::Network::SDN::VnetPlugin;
use PVE::Network::SDN::VlanPlugin; use PVE::Network::SDN::VlanPlugin;
use PVE::Network::SDN::VxlanPlugin; use PVE::Network::SDN::VxlanPlugin;
use PVE::Network::SDN::FrrPlugin;
PVE::Network::SDN::VnetPlugin->register(); PVE::Network::SDN::VnetPlugin->register();
PVE::Network::SDN::VlanPlugin->register(); PVE::Network::SDN::VlanPlugin->register();
PVE::Network::SDN::VxlanPlugin->register(); PVE::Network::SDN::VxlanPlugin->register();
PVE::Network::SDN::FrrPlugin->register();
PVE::Network::SDN::Plugin->init(); PVE::Network::SDN::Plugin->init();

View File

@ -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;

View 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 PERL5DIR=${DESTDIR}/usr/share/perl5

View File

@ -71,6 +71,12 @@ sub generate_sdn_config {
die "please implement inside plugin"; 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 { sub on_delete_hook {
my ($class, $sndid, $scfg) = @_; my ($class, $sndid, $scfg) = @_;