]> git.proxmox.com Git - pve-network.git/commitdiff
add faucet sdn controller plugins
authorAlexandre Derumier <aderumier@odiso.com>
Mon, 30 Sep 2019 09:03:34 +0000 (11:03 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 17 Oct 2019 17:25:49 +0000 (19:25 +0200)
1 plugin for controller, 1 plugin for dataplane

This is not 100% complete, but it's a proof of concept
to test differents sdn controller

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
PVE/API2/Network/SDN.pm
PVE/Network/SDN.pm
PVE/Network/SDN/FaucetPlugin.pm [new file with mode: 0644]
PVE/Network/SDN/Makefile
PVE/Network/SDN/OVSFaucetPlugin.pm [new file with mode: 0644]
PVE/Network/SDN/Plugin.pm

index 043aa0d8f1a47b8b66ed41eaf8115cdbf1e88061..e4ed5cc6b4158aeb3fb51405081fc14cce824add 100644 (file)
@@ -12,6 +12,9 @@ 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::FaucetPlugin;
+
 use Storable qw(dclone);
 use PVE::JSONSchema qw(get_standard_option);
 use PVE::RPCEnvironment;
index b5d98b72575de3814c9ee4b3a3e53df23339e0fc..1946bc539da7a3d5b5c144b483bae6c88b8dd582 100644 (file)
@@ -13,11 +13,15 @@ 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;
 
 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::FaucetPlugin->register();
 PVE::Network::SDN::Plugin->init();
 
 
@@ -203,6 +207,21 @@ sub generate_controller_config {
                    $controller_plugin->generate_controller_transport_config($plugin_config, $controller, $id, $uplinks, $config);
                }
            }
+       } elsif ($role eq 'vnet') {
+           my $transportid = $plugin_config->{transportzone};
+           if ($transportid) {
+               my $transport = $sdn_cfg->{ids}->{$transportid};
+               if ($transport) {
+                   my $controllerid = $transport->{controller};
+                   if ($controllerid) {
+                       my $controller = $sdn_cfg->{ids}->{$controllerid};
+                       if ($controller) {
+                           my $controller_plugin = PVE::Network::SDN::Plugin->lookup($controller->{type});
+                           $controller_plugin->generate_controller_vnet_config($plugin_config, $controller, $transportid, $id, $config);
+                       }
+                   }
+               }
+           }
        }
     }
 
diff --git a/PVE/Network/SDN/FaucetPlugin.pm b/PVE/Network/SDN/FaucetPlugin.pm
new file mode 100644 (file)
index 0000000..9e313c3
--- /dev/null
@@ -0,0 +1,102 @@
+package PVE::Network::SDN::FaucetPlugin;
+
+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 'faucet';
+}
+
+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();
+}
+
+1;
+
index 1930004c0e92ca852b61550a7b49524447113ce3..5bb44dd57df2de10694d5c72efadec2d1429846e 100644 (file)
@@ -1,4 +1,4 @@
-SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FrrPlugin.pm
+SOURCES=Plugin.pm VnetPlugin.pm VlanPlugin.pm VxlanPlugin.pm FrrPlugin.pm FaucetPlugin.pm OVSFaucetPlugin.pm
 
 
 PERL5DIR=${DESTDIR}/usr/share/perl5
diff --git a/PVE/Network/SDN/OVSFaucetPlugin.pm b/PVE/Network/SDN/OVSFaucetPlugin.pm
new file mode 100644 (file)
index 0000000..7a665f3
--- /dev/null
@@ -0,0 +1,76 @@
+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;
+
+
index 9428aead72e76a7851042f00606dc8b7e36774c7..605fd0602890cdd01aa9056d9f9ff718729b81ad 100644 (file)
@@ -77,6 +77,11 @@ sub generate_controller_config {
     die "please implement inside plugin";
 }
 
+sub generate_controller_vnet_config {
+    my ($class, $plugin_config, $controller, $transportid, $vnetid, $config) = @_;
+
+}
+
 sub write_controller_config {
     my ($class, $plugin_config, $config) = @_;