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;
}
}
- 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 (sort keys %{$frr_cfg->{ids}}) {
- my $plugin_config = $frr_cfg->{ids}->{$id};
+ foreach my $id (keys %{$sdn_cfg->{ids}}) {
+ my $plugin_config = $sdn_cfg->{ids}->{$id};
my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
- $plugin->generate_frr_config($plugin_config, $plugin_config, $id, $uplinks, $config);
- }
-
- foreach my $id (sort keys %{$transport_cfg->{ids}}) {
- my $plugin_config = $transport_cfg->{ids}->{$id};
- my $routerid = $plugin_config->{router};
- if ($routerid) {
- my $router = $frr_cfg->{ids}->{$routerid};
- if ($router) {
- my $plugin = PVE::Network::SDN::Plugin->lookup($plugin_config->{type});
- $plugin->generate_frr_config($plugin_config, $router, $id, $uplinks, $config);
+ 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($plugin_config->{type});
+ $controller_plugin->generate_controller_config($plugin_config, $controller, $id, $uplinks, $config);
+ }
}
}
}
- my $final_config = [];
- push @{$final_config}, "log syslog informational";
- push @{$final_config}, "!";
-
- generate_frr_recurse($final_config, $config, undef, 0);
-
- push @{$final_config}, "!";
- push @{$final_config}, "line vty";
- push @{$final_config}, "!";
-
- my $raw_frr_config = join("\n", @{$final_config});
- return $raw_frr_config;
-}
-
-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;
+ return $config;
}
-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_etc_network_config {
my ($rawconfig) = @_;
$writefh->close();
}
-sub write_frr_config {
- my ($rawconfig) = @_;
+sub write_controller_config {
+ my ($config) = @_;
- return if !$rawconfig;
- return if !-d "/etc/frr";
-
- 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";