For true sdn, We have 2 plugins, 1 for dataplane (switch), 1 for controlplane (controller)
rename:
- Frr to EvpnController
- Faucet to FaucetController
- OvsFaucet to Faucet
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
use PVE::Network::SDN::VlanPlugin;
use PVE::Network::SDN::VxlanPlugin;
use PVE::Network::SDN::VnetPlugin;
-use PVE::Network::SDN::FrrPlugin;
-use PVE::Network::SDN::OVSFaucetPlugin;
+use PVE::Network::SDN::FaucetControllerPlugin;
use PVE::Network::SDN::FaucetPlugin;
+use PVE::Network::SDN::EvpnControllerPlugin;
use PVE::Network::SDN::EvpnPlugin;
use Storable qw(dclone);
use PVE::Network::SDN::VnetPlugin;
use PVE::Network::SDN::VlanPlugin;
use PVE::Network::SDN::VxlanPlugin;
-use PVE::Network::SDN::FrrPlugin;
-use PVE::Network::SDN::OVSFaucetPlugin;
use PVE::Network::SDN::FaucetPlugin;
+use PVE::Network::SDN::FaucetControllerPlugin;
use PVE::Network::SDN::EvpnPlugin;
+use PVE::Network::SDN::EvpnControllerPlugin;
PVE::Network::SDN::VnetPlugin->register();
PVE::Network::SDN::VlanPlugin->register();
PVE::Network::SDN::VxlanPlugin->register();
-PVE::Network::SDN::FrrPlugin->register();
-PVE::Network::SDN::OVSFaucetPlugin->register();
+PVE::Network::SDN::FaucetControllerPlugin->register();
PVE::Network::SDN::FaucetPlugin->register();
PVE::Network::SDN::EvpnPlugin->register();
+PVE::Network::SDN::EvpnControllerPlugin->register();
PVE::Network::SDN::Plugin->init();
--- /dev/null
+package PVE::Network::SDN::EvpnControllerPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::SDN::Plugin;
+use PVE::Tools;
+use PVE::INotify;
+use PVE::JSONSchema qw(get_standard_option);
+
+use base('PVE::Network::SDN::Plugin');
+
+sub type {
+ return 'evpncontroller';
+}
+
+sub plugindata {
+ return {
+ role => 'controller',
+ };
+}
+
+sub properties {
+ return {
+ 'asn' => {
+ type => 'integer',
+ description => "autonomous system number",
+ },
+ 'peers' => {
+ description => "peers address list.",
+ type => 'string', format => 'ip-list'
+ },
+ 'gateway-nodes' => get_standard_option('pve-node-list'),
+ 'gateway-external-peers' => {
+ description => "upstream bgp peers address list.",
+ type => 'string', format => 'ip-list'
+ },
+ };
+}
+
+sub options {
+
+ return {
+ 'uplink-id' => { optional => 0 },
+ 'asn' => { optional => 0 },
+ 'peers' => { optional => 0 },
+ 'gateway-nodes' => { optional => 1 },
+ 'gateway-external-peers' => { optional => 1 },
+ };
+}
+
+# Plugin implementation
+sub generate_controller_config {
+ my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+
+ my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
+
+ my $asn = $plugin_config->{asn};
+ my $uplink = $plugin_config->{'uplink-id'};
+ my $gatewaynodes = $plugin_config->{'gateway-nodes'};
+ my @gatewaypeers = split(',', $plugin_config->{'gateway-external-peers'}) if $plugin_config->{'gateway-external-peers'};
+
+ return if !$asn;
+
+ my $iface = "uplink$uplink";
+ my $ifaceip = "";
+
+ if($uplinks->{$uplink}->{name}) {
+ $iface = $uplinks->{$uplink}->{name};
+ $ifaceip = PVE::Network::SDN::Plugin::get_first_local_ipv4_from_interface($iface);
+ }
+
+ my $is_gateway = undef;
+ my $local_node = PVE::INotify::nodename();
+
+ foreach my $gatewaynode (PVE::Tools::split_list($gatewaynodes)) {
+ $is_gateway = 1 if $gatewaynode eq $local_node;
+ }
+
+ my @router_config = ();
+
+ push @router_config, "bgp router-id $ifaceip";
+ push @router_config, "no bgp default ipv4-unicast";
+ push @router_config, "coalesce-time 1000";
+
+ foreach my $address (@peers) {
+ next if $address eq $ifaceip;
+ push @router_config, "neighbor $address remote-as $asn";
+ }
+
+ if ($is_gateway) {
+ foreach my $address (@gatewaypeers) {
+ push @router_config, "neighbor $address remote-as external";
+ }
+ }
+ push(@{$config->{frr}->{router}->{"bgp $asn"}->{""}}, @router_config);
+
+ @router_config = ();
+ foreach my $address (@peers) {
+ next if $address eq $ifaceip;
+ push @router_config, "neighbor $address activate";
+ }
+ push @router_config, "advertise-all-vni";
+ push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
+
+ if ($is_gateway) {
+
+ @router_config = ();
+ #import /32 routes of evpn network from vrf1 to default vrf (for packet return)
+ #frr 7.1 tag is bugged -> works fine with 7.1 stable branch(20190829-02-g6ba76bbc1)
+ #https://github.com/FRRouting/frr/issues/4905
+ foreach my $address (@gatewaypeers) {
+ push @router_config, "neighbor $address activate";
+ }
+ push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
+ push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv6 unicast"}}, @router_config);
+
+ }
+
+ return $config;
+}
+
+sub generate_controller_transport_config {
+ my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+
+ my $vrf = $plugin_config->{'vrf'};
+ my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
+ my $asn = $router->{asn};
+ my $gatewaynodes = $router->{'gateway-nodes'};
+
+ return if !$vrf || !$vrfvxlan || !$asn;
+
+ #vrf
+ my @router_config = ();
+ push @router_config, "vni $vrfvxlan";
+ push(@{$config->{frr}->{vrf}->{"$vrf"}}, @router_config);
+
+ @router_config = ();
+
+ my $is_gateway = undef;
+ my $local_node = PVE::INotify::nodename();
+
+ foreach my $gatewaynode (PVE::Tools::split_list($gatewaynodes)) {
+ $is_gateway = 1 if $gatewaynode eq $local_node;
+ }
+
+ if ($is_gateway) {
+
+ @router_config = ();
+ #import /32 routes of evpn network from vrf1 to default vrf (for packet return)
+ #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->{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->{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 @router_config, "default-originate ipv6";
+ push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
+ }
+
+ return $config;
+}
+
+sub on_delete_hook {
+ 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, $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);
+ }
+}
+
+sub sort_frr_config {
+ my $order = {};
+ $order->{''} = 0;
+ $order->{'vrf'} = 1;
+ $order->{'ipv4 unicast'} = 1;
+ $order->{'ipv6 unicast'} = 2;
+ $order->{'l2vpn evpn'} = 3;
+
+ my $a_val = 100;
+ my $b_val = 100;
+
+ $a_val = $order->{$a} if defined($order->{$a});
+ $b_val = $order->{$b} if defined($order->{$b});
+
+ if($a =~ /bgp (\d+)$/) {
+ $a_val = 2;
+ }
+
+ if($b =~ /bgp (\d+)$/) {
+ $b_val = 2;
+ }
+
+ return $a_val <=> $b_val;
+}
+
+sub generate_frr_recurse{
+ my ($final_config, $content, $parentkey, $level) = @_;
+
+ my $keylist = {};
+ $keylist->{vrf} = 1;
+ $keylist->{'address-family'} = 1;
+ $keylist->{router} = 1;
+
+ my $exitkeylist = {};
+ $exitkeylist->{vrf} = 1;
+ $exitkeylist->{'address-family'} = 1;
+
+ #fix me, make this generic
+ my $paddinglevel = undef;
+ if($level == 1 || $level == 2) {
+ $paddinglevel = $level - 1;
+ } elsif ($level == 3 || $level == 4) {
+ $paddinglevel = $level - 2;
+ }
+
+ my $padding = "";
+ $padding = ' ' x ($paddinglevel) if $paddinglevel;
+
+ if (ref $content eq ref {}) {
+ foreach my $key (sort sort_frr_config keys %$content) {
+ if ($parentkey && defined($keylist->{$parentkey})) {
+ push @{$final_config}, $padding."!";
+ push @{$final_config}, $padding."$parentkey $key";
+ } else {
+ push @{$final_config}, $padding."$key" if $key ne '' && !defined($keylist->{$key});
+ }
+
+ my $option = $content->{$key};
+ generate_frr_recurse($final_config, $option, $key, $level+1);
+
+ push @{$final_config}, $padding."exit-$parentkey" if $parentkey && defined($exitkeylist->{$parentkey});
+ }
+ }
+
+ if (ref $content eq 'ARRAY') {
+ foreach my $value (@$content) {
+ push @{$final_config}, $padding."$value";
+ }
+ }
+}
+
+sub write_controller_config {
+ my ($class, $plugin_config, $config) = @_;
+
+ my $final_config = [];
+ push @{$final_config}, "log syslog informational";
+ push @{$final_config}, "!";
+
+ generate_frr_recurse($final_config, $config->{frr}, undef, 0);
+
+ push @{$final_config}, "!";
+ push @{$final_config}, "line vty";
+ push @{$final_config}, "!";
+
+ my $rawconfig = join("\n", @{$final_config});
+
+
+ return if !$rawconfig;
+ return if !-d "/etc/frr";
+
+ my $frr_config_file = "/etc/frr/frr.conf";
+
+ my $writefh = IO::File->new($frr_config_file,">");
+ print $writefh $rawconfig;
+ $writefh->close();
+}
+
+sub reload_controller {
+ my ($class) = @_;
+
+ my $conf_file = "/etc/frr/frr.conf";
+ my $bin_path = "/usr/bin/vtysh";
+
+ my $err = sub {
+ my $line = shift;
+ if ($line =~ /^line (\S+)/) {
+ print "$line \n";
+ }
+ };
+
+ if (-e $conf_file && -e $bin_path) {
+ PVE::Tools::run_command([$bin_path, '-m', '-f', $conf_file], outfunc => {}, errfunc => $err);
+ }
+}
+
+1;
+
+
--- /dev/null
+package PVE::Network::SDN::FaucetControllerPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::SDN::Plugin;
+use PVE::Tools;
+use PVE::INotify;
+use PVE::JSONSchema qw(get_standard_option);
+use CPAN::Meta::YAML;
+use Encode;
+
+use base('PVE::Network::SDN::Plugin');
+
+sub type {
+ return 'faucetcontroller';
+}
+
+sub plugindata {
+ return {
+ role => 'controller',
+ };
+}
+
+sub properties {
+ return {
+ };
+}
+
+# Plugin implementation
+sub generate_controller_config {
+ my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+
+}
+
+sub generate_controller_transport_config {
+ my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+
+ my $dpid = $plugin_config->{'dp-id'};
+ my $dphex = printf("%x",$dpid);
+
+ my $transport_config = {
+ dp_id => $dphex,
+ hardware => "Open vSwitch",
+ };
+
+ $config->{faucet}->{dps}->{$id} = $transport_config;
+
+}
+
+
+sub generate_controller_vnet_config {
+ my ($class, $plugin_config, $controller, $transportid, $vnetid, $config) = @_;
+
+ my $mac = $plugin_config->{mac};
+ my $ipv4 = $plugin_config->{ipv4};
+ my $ipv6 = $plugin_config->{ipv6};
+ my $tag = $plugin_config->{tag};
+ my $alias = $plugin_config->{alias};
+
+ my @ips = ();
+ push @ips, $ipv4 if $ipv4;
+ push @ips, $ipv6 if $ipv6;
+
+ my $vlan_config = { vid => $tag };
+
+ $vlan_config->{description} = $alias if $alias;
+ $vlan_config->{faucet_mac} = $mac if $mac;
+ $vlan_config->{faucet_vips} = \@ips if scalar @ips > 0;
+
+ $config->{faucet}->{vlans}->{$vnetid} = $vlan_config;
+
+ push(@{$config->{faucet}->{routers}->{$transportid}->{vlans}} , $vnetid);
+
+}
+
+sub on_delete_hook {
+ my ($class, $routerid, $sdn_cfg) = @_;
+
+}
+
+sub on_update_hook {
+ my ($class, $routerid, $sdn_cfg) = @_;
+
+}
+
+sub write_controller_config {
+ my ($class, $plugin_config, $config) = @_;
+
+ my $rawconfig = encode('UTF-8', CPAN::Meta::YAML::Dump($config->{faucet}));
+
+ return if !$rawconfig;
+ return if !-d "/etc/faucet";
+
+ my $frr_config_file = "/etc/faucet/faucet.yaml";
+
+ my $writefh = IO::File->new($frr_config_file,">");
+ print $writefh $rawconfig;
+ $writefh->close();
+}
+
+sub reload_controller {
+ my ($class) = @_;
+
+ my $conf_file = "/etc/faucet/faucet.yaml";
+ my $bin_path = "/usr/bin/faucet";
+
+ if (-e $conf_file && -e $bin_path) {
+ PVE::Tools::run_command(['systemctl', 'reload', 'faucet']);
+ }
+}
+
+1;
+
use strict;
use warnings;
-use PVE::Network::SDN::Plugin;
-use PVE::Tools;
-use PVE::INotify;
-use PVE::JSONSchema qw(get_standard_option);
-use CPAN::Meta::YAML;
-use Encode;
+use PVE::Network::SDN::VlanPlugin;
-use base('PVE::Network::SDN::Plugin');
+use base('PVE::Network::SDN::VlanPlugin');
sub type {
return 'faucet';
sub plugindata {
return {
- role => 'controller',
+ role => 'transport',
};
}
sub properties {
return {
+ 'dp-id' => {
+ type => 'integer',
+ description => 'Faucet dataplane id',
+ },
};
}
-# Plugin implementation
-sub generate_controller_config {
- my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+sub options {
+ return {
+ 'dp-id' => { optional => 0 },
+ 'uplink-id' => { optional => 0 },
+ 'controller' => { optional => 0 },
+ 'vlan-allowed' => { optional => 1 },
+ };
}
-sub generate_controller_transport_config {
- my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
+# Plugin implementation
+sub generate_sdn_config {
+ my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+ my $mtu = $vnet->{mtu};
+ my $uplink = $plugin_config->{'uplink-id'};
my $dpid = $plugin_config->{'dp-id'};
- my $dphex = printf("%x",$dpid);
-
- my $transport_config = {
- dp_id => $dphex,
- hardware => "Open vSwitch",
- };
-
- $config->{faucet}->{dps}->{$id} = $transport_config;
-
-}
-
-
-sub generate_controller_vnet_config {
- my ($class, $plugin_config, $controller, $transportid, $vnetid, $config) = @_;
-
- my $mac = $plugin_config->{mac};
- my $ipv4 = $plugin_config->{ipv4};
- my $ipv6 = $plugin_config->{ipv6};
- my $tag = $plugin_config->{tag};
- my $alias = $plugin_config->{alias};
+ my $dphex = printf("%x",$dpid); #fixme :should be 16characters hex
- my @ips = ();
- push @ips, $ipv4 if $ipv4;
- push @ips, $ipv6 if $ipv6;
+ my $iface = $uplinks->{$uplink}->{name};
+ $iface = "uplink${uplink}" if !$iface;
- my $vlan_config = { vid => $tag };
+ #tagged interface
+ my @iface_config = ();
+ push @iface_config, "ovs_type OVSPort";
+ push @iface_config, "ovs_bridge $zoneid";
+ push @iface_config, "ovs_mtu $mtu" if $mtu;
+ push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
- $vlan_config->{description} = $alias if $alias;
- $vlan_config->{faucet_mac} = $mac if $mac;
- $vlan_config->{faucet_vips} = \@ips if scalar @ips > 0;
+ #vnet bridge
+ @iface_config = ();
+ push @iface_config, "ovs_port $iface";
+ push @iface_config, "ovs_type OVSBridge";
+ push @iface_config, "ovs_mtu $mtu" if $mtu;
- $config->{faucet}->{vlans}->{$vnetid} = $vlan_config;
-
- push(@{$config->{faucet}->{routers}->{$transportid}->{vlans}} , $vnetid);
-
-}
+ push @iface_config, "ovs_extra set bridge $zoneid other-config:datapath-id=$dphex";
+ push @iface_config, "ovs_extra set bridge $zoneid other-config:disable-in-band=true";
+ push @iface_config, "ovs_extra set bridge $zoneid fail_mode=secure";
+ push @iface_config, "ovs_extra set-controller $vnetid tcp:127.0.0.1:6653";
-sub on_delete_hook {
- my ($class, $routerid, $sdn_cfg) = @_;
+ push(@{$config->{$zoneid}}, @iface_config) if !$config->{$zoneid};
+ return $config;
}
-sub on_update_hook {
- my ($class, $routerid, $sdn_cfg) = @_;
-
-}
-
-sub write_controller_config {
- my ($class, $plugin_config, $config) = @_;
-
- my $rawconfig = encode('UTF-8', CPAN::Meta::YAML::Dump($config->{faucet}));
-
- return if !$rawconfig;
- return if !-d "/etc/faucet";
-
- my $frr_config_file = "/etc/faucet/faucet.yaml";
-
- my $writefh = IO::File->new($frr_config_file,">");
- print $writefh $rawconfig;
- $writefh->close();
-}
-
-sub reload_controller {
- my ($class) = @_;
-
- my $conf_file = "/etc/faucet/faucet.yaml";
- my $bin_path = "/usr/bin/faucet";
-
- if (-e $conf_file && -e $bin_path) {
- PVE::Tools::run_command(['systemctl', 'reload', 'faucet']);
- }
-}
1;
+
+++ /dev/null
-package PVE::Network::SDN::FrrPlugin;
-
-use strict;
-use warnings;
-use PVE::Network::SDN::Plugin;
-use PVE::Tools;
-use PVE::INotify;
-use PVE::JSONSchema qw(get_standard_option);
-
-use base('PVE::Network::SDN::Plugin');
-
-sub type {
- return 'frr';
-}
-
-sub plugindata {
- return {
- role => 'controller',
- };
-}
-
-sub properties {
- return {
- 'asn' => {
- type => 'integer',
- description => "autonomous system number",
- },
- 'peers' => {
- description => "peers address list.",
- type => 'string', format => 'ip-list'
- },
- 'gateway-nodes' => get_standard_option('pve-node-list'),
- 'gateway-external-peers' => {
- description => "upstream bgp peers address list.",
- type => 'string', format => 'ip-list'
- },
- };
-}
-
-sub options {
-
- return {
- 'uplink-id' => { optional => 0 },
- 'asn' => { optional => 0 },
- 'peers' => { optional => 0 },
- 'gateway-nodes' => { optional => 1 },
- 'gateway-external-peers' => { optional => 1 },
- };
-}
-
-# Plugin implementation
-sub generate_controller_config {
- my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
-
- my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
-
- my $asn = $plugin_config->{asn};
- my $uplink = $plugin_config->{'uplink-id'};
- my $gatewaynodes = $plugin_config->{'gateway-nodes'};
- my @gatewaypeers = split(',', $plugin_config->{'gateway-external-peers'}) if $plugin_config->{'gateway-external-peers'};
-
- return if !$asn;
-
- my $iface = "uplink$uplink";
- my $ifaceip = "";
-
- if($uplinks->{$uplink}->{name}) {
- $iface = $uplinks->{$uplink}->{name};
- $ifaceip = PVE::Network::SDN::Plugin::get_first_local_ipv4_from_interface($iface);
- }
-
- my $is_gateway = undef;
- my $local_node = PVE::INotify::nodename();
-
- foreach my $gatewaynode (PVE::Tools::split_list($gatewaynodes)) {
- $is_gateway = 1 if $gatewaynode eq $local_node;
- }
-
- my @router_config = ();
-
- push @router_config, "bgp router-id $ifaceip";
- push @router_config, "no bgp default ipv4-unicast";
- push @router_config, "coalesce-time 1000";
-
- foreach my $address (@peers) {
- next if $address eq $ifaceip;
- push @router_config, "neighbor $address remote-as $asn";
- }
-
- if ($is_gateway) {
- foreach my $address (@gatewaypeers) {
- push @router_config, "neighbor $address remote-as external";
- }
- }
- push(@{$config->{frr}->{router}->{"bgp $asn"}->{""}}, @router_config);
-
- @router_config = ();
- foreach my $address (@peers) {
- next if $address eq $ifaceip;
- push @router_config, "neighbor $address activate";
- }
- push @router_config, "advertise-all-vni";
- push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
-
- if ($is_gateway) {
-
- @router_config = ();
- #import /32 routes of evpn network from vrf1 to default vrf (for packet return)
- #frr 7.1 tag is bugged -> works fine with 7.1 stable branch(20190829-02-g6ba76bbc1)
- #https://github.com/FRRouting/frr/issues/4905
- foreach my $address (@gatewaypeers) {
- push @router_config, "neighbor $address activate";
- }
- push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv4 unicast"}}, @router_config);
- push(@{$config->{frr}->{router}->{"bgp $asn"}->{"address-family"}->{"ipv6 unicast"}}, @router_config);
-
- }
-
- return $config;
-}
-
-sub generate_controller_transport_config {
- my ($class, $plugin_config, $router, $id, $uplinks, $config) = @_;
-
- my $vrf = $plugin_config->{'vrf'};
- my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
- my $asn = $router->{asn};
- my $gatewaynodes = $router->{'gateway-nodes'};
-
- return if !$vrf || !$vrfvxlan || !$asn;
-
- #vrf
- my @router_config = ();
- push @router_config, "vni $vrfvxlan";
- push(@{$config->{frr}->{vrf}->{"$vrf"}}, @router_config);
-
- @router_config = ();
-
- my $is_gateway = undef;
- my $local_node = PVE::INotify::nodename();
-
- foreach my $gatewaynode (PVE::Tools::split_list($gatewaynodes)) {
- $is_gateway = 1 if $gatewaynode eq $local_node;
- }
-
- if ($is_gateway) {
-
- @router_config = ();
- #import /32 routes of evpn network from vrf1 to default vrf (for packet return)
- #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->{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->{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 @router_config, "default-originate ipv6";
- push(@{$config->{frr}->{router}->{"bgp $asn vrf $vrf"}->{"address-family"}->{"l2vpn evpn"}}, @router_config);
- }
-
- return $config;
-}
-
-sub on_delete_hook {
- 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, $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);
- }
-}
-
-sub sort_frr_config {
- my $order = {};
- $order->{''} = 0;
- $order->{'vrf'} = 1;
- $order->{'ipv4 unicast'} = 1;
- $order->{'ipv6 unicast'} = 2;
- $order->{'l2vpn evpn'} = 3;
-
- my $a_val = 100;
- my $b_val = 100;
-
- $a_val = $order->{$a} if defined($order->{$a});
- $b_val = $order->{$b} if defined($order->{$b});
-
- if($a =~ /bgp (\d+)$/) {
- $a_val = 2;
- }
-
- if($b =~ /bgp (\d+)$/) {
- $b_val = 2;
- }
-
- return $a_val <=> $b_val;
-}
-
-sub generate_frr_recurse{
- my ($final_config, $content, $parentkey, $level) = @_;
-
- my $keylist = {};
- $keylist->{vrf} = 1;
- $keylist->{'address-family'} = 1;
- $keylist->{router} = 1;
-
- my $exitkeylist = {};
- $exitkeylist->{vrf} = 1;
- $exitkeylist->{'address-family'} = 1;
-
- #fix me, make this generic
- my $paddinglevel = undef;
- if($level == 1 || $level == 2) {
- $paddinglevel = $level - 1;
- } elsif ($level == 3 || $level == 4) {
- $paddinglevel = $level - 2;
- }
-
- my $padding = "";
- $padding = ' ' x ($paddinglevel) if $paddinglevel;
-
- if (ref $content eq ref {}) {
- foreach my $key (sort sort_frr_config keys %$content) {
- if ($parentkey && defined($keylist->{$parentkey})) {
- push @{$final_config}, $padding."!";
- push @{$final_config}, $padding."$parentkey $key";
- } else {
- push @{$final_config}, $padding."$key" if $key ne '' && !defined($keylist->{$key});
- }
-
- my $option = $content->{$key};
- generate_frr_recurse($final_config, $option, $key, $level+1);
-
- push @{$final_config}, $padding."exit-$parentkey" if $parentkey && defined($exitkeylist->{$parentkey});
- }
- }
-
- if (ref $content eq 'ARRAY') {
- foreach my $value (@$content) {
- push @{$final_config}, $padding."$value";
- }
- }
-}
-
-sub write_controller_config {
- my ($class, $plugin_config, $config) = @_;
-
- my $final_config = [];
- push @{$final_config}, "log syslog informational";
- push @{$final_config}, "!";
-
- generate_frr_recurse($final_config, $config->{frr}, undef, 0);
-
- push @{$final_config}, "!";
- push @{$final_config}, "line vty";
- push @{$final_config}, "!";
-
- my $rawconfig = join("\n", @{$final_config});
-
-
- return if !$rawconfig;
- return if !-d "/etc/frr";
-
- my $frr_config_file = "/etc/frr/frr.conf";
-
- my $writefh = IO::File->new($frr_config_file,">");
- print $writefh $rawconfig;
- $writefh->close();
-}
-
-sub reload_controller {
- my ($class) = @_;
-
- my $conf_file = "/etc/frr/frr.conf";
- my $bin_path = "/usr/bin/vtysh";
-
- my $err = sub {
- my $line = shift;
- if ($line =~ /^line (\S+)/) {
- print "$line \n";
- }
- };
-
- if (-e $conf_file && -e $bin_path) {
- PVE::Tools::run_command([$bin_path, '-m', '-f', $conf_file], outfunc => {}, errfunc => $err);
- }
-}
-
-1;
-
-
-SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FrrPlugin.pm FaucetPlugin.pm OVSFaucetPlugin.pm EvpnPlugin.pm
+SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FaucetControllerPlugin.pm FaucetPlugin.pm EvpnPlugin.pm EvpnControllerPlugin.pm
PERL5DIR=${DESTDIR}/usr/share/perl5
+++ /dev/null
-package PVE::Network::SDN::OVSFaucetPlugin;
-
-use strict;
-use warnings;
-use PVE::Network::SDN::VlanPlugin;
-
-use base('PVE::Network::SDN::VlanPlugin');
-
-sub type {
- return 'ovsfaucet';
-}
-
-sub plugindata {
- return {
- role => 'transport',
- };
-}
-
-sub properties {
- return {
- 'dp-id' => {
- type => 'integer',
- description => 'Faucet dataplane id',
- },
- };
-}
-
-sub options {
-
- return {
- 'dp-id' => { optional => 0 },
- 'uplink-id' => { optional => 0 },
- 'controller' => { optional => 0 },
- 'vlan-allowed' => { optional => 1 },
- };
-}
-
-# Plugin implementation
-sub generate_sdn_config {
- my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
-
- my $mtu = $vnet->{mtu};
- my $uplink = $plugin_config->{'uplink-id'};
- my $dpid = $plugin_config->{'dp-id'};
- my $dphex = printf("%x",$dpid); #fixme :should be 16characters hex
-
- my $iface = $uplinks->{$uplink}->{name};
- $iface = "uplink${uplink}" if !$iface;
-
- #tagged interface
- my @iface_config = ();
- push @iface_config, "ovs_type OVSPort";
- push @iface_config, "ovs_bridge $zoneid";
- push @iface_config, "ovs_mtu $mtu" if $mtu;
- push(@{$config->{$iface}}, @iface_config) if !$config->{$iface};
-
- #vnet bridge
- @iface_config = ();
- push @iface_config, "ovs_port $iface";
- push @iface_config, "ovs_type OVSBridge";
- push @iface_config, "ovs_mtu $mtu" if $mtu;
-
- push @iface_config, "ovs_extra set bridge $zoneid other-config:datapath-id=$dphex";
- push @iface_config, "ovs_extra set bridge $zoneid other-config:disable-in-band=true";
- push @iface_config, "ovs_extra set bridge $zoneid fail_mode=secure";
- push @iface_config, "ovs_extra set-controller $vnetid tcp:127.0.0.1:6653";
-
- push(@{$config->{$zoneid}}, @iface_config) if !$config->{$zoneid};
-
- return $config;
-}
-
-
-1;
-
-
#create a layer2 vxlan unicast transportzone
pvesh create /cluster/sdn/ --sdn vxlanunicastzone --type vxlan --uplink-id 1 --unicast-address 192.168.0.1,192.168.0.2,192.168.0.3
-#create a frr controller
-pvesh create /cluster/sdn/ --sdn frrrouter1 --type frr --uplink-id 1 --peers 192.168.0.1,192.168.0.2,192.168.0.3 --asn 1234 --gateway-nodes pxnode1,pxnode2 --gateway-external-peers 192.168.0.253,192.168.0.254
+#create an controller
+pvesh create /cluster/sdn/ --sdn frrrouter1 --type evpncontroller --uplink-id 1 --peers 192.168.0.1,192.168.0.2,192.168.0.3 --asn 1234 --gateway-nodes pxnode1,pxnode2 --gateway-external-peers 192.168.0.253,192.168.0.254
#create a layer2 vxlan bgpevpn transportzone
pvesh create /cluster/sdn/ --sdn layer2evpnzone --type evpn --uplink-id 1 --controller frrrouter1