]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN.pm
rename plugins with controllers
[pve-network.git] / PVE / Network / SDN.pm
index 1d84a32e9f1a8d9090715170d99ff86ebe0a08d8..8e8e6379a727e64f85289e302faecefaa2cece91 100644 (file)
@@ -12,12 +12,18 @@ 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;
+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::FaucetControllerPlugin->register();
+PVE::Network::SDN::FaucetPlugin->register();
+PVE::Network::SDN::EvpnPlugin->register();
+PVE::Network::SDN::EvpnControllerPlugin->register();
 PVE::Network::SDN::Plugin->init();
 
 
@@ -162,7 +168,7 @@ sub generate_etc_network_config {
     return $raw_network_config;
 }
 
-sub generate_frr_config {
+sub generate_controller_config {
 
     my $sdn_cfg = PVE::Cluster::cfs_read_file('sdn.cfg');
     return if !$sdn_cfg;
@@ -184,70 +190,61 @@ sub generate_frr_config {
        }
     }
 
-    my $frr_cfg = undef;
-    my $transport_cfg = undef;
-
-    foreach my $id (keys %{$sdn_cfg->{ids}}) {
-       if ($sdn_cfg->{ids}->{$id}->{type} eq 'frr') {
-           $frr_cfg->{ids}->{$id} = $sdn_cfg->{ids}->{$id};
-       } elsif ($sdn_cfg->{ids}->{$id}->{type} ne 'vnet') {
-           $transport_cfg->{ids}->{$id} = $sdn_cfg->{ids}->{$id};
-       }
-    }
-
-    return undef if !$frr_cfg;
-
     #generate configuration
     my $config = {};
 
-    foreach my $id (keys %{$frr_cfg->{ids}}) {
-       my $plugin_config = $frr_cfg->{ids}->{$id};
-       my $asn = $plugin_config->{asn};
-       if ($asn) {
-           my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
-           $plugin->generate_frr_config($plugin_config, $asn, $id, $uplinks, $config);
-       }
-    }
-
-    foreach my $id (keys %{$transport_cfg->{ids}}) {
-       my $plugin_config = $transport_cfg->{ids}->{$id};
-       my $router = $plugin_config->{router};
-       if ($router) {
-           my $asn = $frr_cfg->{ids}->{$router}->{asn};
-           if ($asn) {
-               my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
-               $plugin->generate_frr_config($plugin_config, $asn, $id, $uplinks, $config);
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+       my $plugin_config = $sdn_cfg->{ids}->{$id};
+       my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
+       my $pd = $plugin->plugindata();
+       my $role = $pd->{role};
+       if ($role eq 'controller') {
+           $plugin->generate_controller_config($plugin_config, $plugin_config, $id, $uplinks, $config);
+       } elsif ($role eq 'transport') {
+           my $controllerid = $plugin_config->{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_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);
+                       }
+                   }
+               }
            }
        }
     }
 
-    my $raw_frr_config = "log syslog informational\n";
-    $raw_frr_config .= "!\n";
+    return $config;
+}
 
-    #vrf first
-    my $vrfconfig = $config->{vrf};
-    foreach my $vrf (sort keys %$vrfconfig) {
-       $raw_frr_config .= "$vrf\n";
-       foreach my $option (@{$vrfconfig->{$vrf}}) {
-           $raw_frr_config .= " $option\n";
-       }
-       $raw_frr_config .= "!\n";
-    }
 
-    #routers
-    my $routerconfig = $config->{router};
-    foreach my $router (sort keys %$routerconfig) {
-       $raw_frr_config .= "$router\n";
-       foreach my $option (@{$routerconfig->{$router}}) {
-           $raw_frr_config .= " $option\n";
-       }
-       $raw_frr_config .= "!\n";
-    }
+sub reload_controller {
 
-    $raw_frr_config .= "line vty\n";
-    $raw_frr_config .= "!\n";
+    my $sdn_cfg = PVE::Cluster::cfs_read_file('sdn.cfg');
+    return if !$sdn_cfg;
 
-    return $raw_frr_config;
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+       my $plugin_config = $sdn_cfg->{ids}->{$id};
+       my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
+       my $pd = $plugin->plugindata();
+       my $role = $pd->{role};
+       if ($role eq 'controller') {
+           $plugin->reload_controller();
+       }
+    }
 }
 
 sub write_etc_network_config {
@@ -261,20 +258,23 @@ sub write_etc_network_config {
     $writefh->close();
 }
 
-sub write_frr_config {
-    my ($rawconfig) = @_;
-
-    return if !$rawconfig;
-    return if !-d "/etc/frr";
+sub write_controller_config {
+    my ($config) = @_;
 
-    my $frr_config_file = "/etc/frr/frr.conf";
+    my $sdn_cfg = PVE::Cluster::cfs_read_file('sdn.cfg');
+    return if !$sdn_cfg;
 
-    my $writefh = IO::File->new($frr_config_file,">");
-    print $writefh $rawconfig;
-    $writefh->close();
+    foreach my $id (keys %{$sdn_cfg->{ids}}) {
+       my $plugin_config = $sdn_cfg->{ids}->{$id};
+       my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
+       my $pd = $plugin->plugindata();
+       my $role = $pd->{role};
+       if ($role eq 'controller') {
+               $plugin->write_controller_config($plugin_config, $config);
+       }
+    }
 }
 
-
 sub status {
 
     my $cluster_sdn_file = "/etc/pve/sdn.cfg";