]> git.proxmox.com Git - pve-network.git/blobdiff - PVE/Network/SDN/Zones/EvpnPlugin.pm
evpn: prefix interfaces
[pve-network.git] / PVE / Network / SDN / Zones / EvpnPlugin.pm
index f9998472cdb3ac8e01f6b6cd4ddbf8fa8cf91efa..973e8e054b4d548393a3fe71f59dcf6a2f2fdc82 100644 (file)
@@ -5,6 +5,7 @@ use warnings;
 use PVE::Network::SDN::Zones::VxlanPlugin;
 use PVE::Tools qw($IPV4RE);
 use PVE::INotify;
+use PVE::Network::SDN::Controllers::EvpnPlugin;
 
 use base('PVE::Network::SDN::Zones::VxlanPlugin');
 
@@ -12,18 +13,8 @@ sub type {
     return 'evpn';
 }
 
-sub plugindata {
-    return {
-        role => 'transport',
-    };
-}
-
 sub properties {
     return {
-       'vrf' => {
-           description => "vrf name.",
-           type => 'string',  #fixme: format
-       },
        'vrf-vxlan' => {
            type => 'integer',
            description => "l3vni.",
@@ -39,16 +30,15 @@ sub options {
 
     return {
         nodes => { optional => 1},
-       'uplink-id' => { optional => 0 },
-        'vrf' => { optional => 0 },
         'vrf-vxlan' => { optional => 0 },
         'controller' => { optional => 0 },
+       mtu => { optional => 1 },
     };
 }
 
 # Plugin implementation
 sub generate_sdn_config {
-    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
 
     my $tag = $vnet->{tag};
     my $alias = $vnet->{alias};
@@ -56,40 +46,35 @@ sub generate_sdn_config {
     my $ipv6 = $vnet->{ipv6};
     my $mac = $vnet->{mac};
 
-    my $uplink = $plugin_config->{'uplink-id'};
-    my $vrf = $plugin_config->{'vrf'};
+    my $vrf_iface = "vrf_$zoneid";
     my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
 
     die "missing vxlan tag" if !$tag;
-    my $iface = "uplink$uplink";
-    my $ifaceip = "";
 
-    if($uplinks->{$uplink}->{name}) {
-       $iface = $uplinks->{$uplink}->{name};
-       $ifaceip = PVE::Network::SDN::Zones::Plugin::get_first_local_ipv4_from_interface($iface);
-    }
+    my @peers = split(',', $controller->{'peers'});
+    my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
 
     my $mtu = 1450;
-    $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu};
-    $mtu = $vnet->{mtu} if $vnet->{mtu};
+    $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
+    $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
 
     #vxlan interface
+    my $vxlan_iface = "vxlan_$vnetid";
     my @iface_config = ();
     push @iface_config, "vxlan-id $tag";
-
     push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
     push @iface_config, "bridge-learning off";
     push @iface_config, "bridge-arp-nd-suppress on";
 
     push @iface_config, "mtu $mtu" if $mtu;
-    push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
+    push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
 
     #vnet bridge
     @iface_config = ();
     push @iface_config, "address $ipv4" if $ipv4;
     push @iface_config, "address $ipv6" if $ipv6;
     push @iface_config, "hwaddress $mac" if $mac;
-    push @iface_config, "bridge_ports vxlan$vnetid";
+    push @iface_config, "bridge_ports $vxlan_iface";
     push @iface_config, "bridge_stp off";
     push @iface_config, "bridge_fd 0";
     push @iface_config, "mtu $mtu" if $mtu;
@@ -97,34 +82,34 @@ sub generate_sdn_config {
     push @iface_config, "ip-forward on" if $ipv4;
     push @iface_config, "ip6-forward on" if $ipv6;
     push @iface_config, "arp-accept on" if $ipv4||$ipv6;
-    push @iface_config, "vrf $vrf" if $vrf;
+    push @iface_config, "vrf $vrf_iface" if $vrf_iface;
     push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
 
-    if ($vrf) {
+    if ($vrf_iface) {
        #vrf interface
        @iface_config = ();
        push @iface_config, "vrf-table auto";
-       push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf};
+       push(@{$config->{$vrf_iface}}, @iface_config) if !$config->{$vrf_iface};
 
        if ($vrfvxlan) {
            #l3vni vxlan interface
-           my $iface_vxlan = "vxlan$vrf";
+           my $iface_vrf_vxlan = "vrfvx_$zoneid";
            @iface_config = ();
            push @iface_config, "vxlan-id $vrfvxlan";
            push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
            push @iface_config, "bridge-learning off";
            push @iface_config, "bridge-arp-nd-suppress on";
            push @iface_config, "mtu $mtu" if $mtu;
-           push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan};
+           push(@{$config->{$iface_vrf_vxlan}}, @iface_config) if !$config->{$iface_vrf_vxlan};
 
            #l3vni bridge
-           my $brvrf = "br$vrf";
+           my $brvrf = "vrfbr_$zoneid";
            @iface_config = ();
-           push @iface_config, "bridge-ports $iface_vxlan";
+           push @iface_config, "bridge-ports $iface_vrf_vxlan";
            push @iface_config, "bridge_stp off";
            push @iface_config, "bridge_fd 0";
            push @iface_config, "mtu $mtu" if $mtu;
-           push @iface_config, "vrf $vrf";
+           push @iface_config, "vrf $vrf_iface";
            push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
        }
     }
@@ -133,41 +118,24 @@ sub generate_sdn_config {
 }
 
 sub on_update_hook {
-    my ($class, $transportid, $sdn_cfg) = @_;
-
-    # verify that router exist
-    if (defined($sdn_cfg->{ids}->{$transportid}->{router})) {
-       my $router = $sdn_cfg->{ids}->{$transportid}->{router};
-       if (!defined($sdn_cfg->{ids}->{$router})) {
-           die "router $router don't exist";
-       } else {
-           die "$router is not a router type" if $sdn_cfg->{ids}->{$router}->{type} ne 'frr';
-       }
+    my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
+
+    # verify that controller exist
+    my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
+    if (!defined($controller_cfg->{ids}->{$controller})) {
+       die "controller $controller don't exist";
+    } else {
+       die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
+    }
 
-       #vrf && vrf-vxlan need to be defined with router
-       my $vrf = $sdn_cfg->{ids}->{$transportid}->{vrf};
-       if (!defined($vrf)) {
-           die "missing vrf option";
-       } else {
-           # verify that vrf is not already declared in another transport
-           foreach my $id (keys %{$sdn_cfg->{ids}}) {
-               next if $id eq $transportid;
-               die "vrf $vrf is already declared in $id"
-                       if (defined($sdn_cfg->{ids}->{$id}->{vrf}) && $sdn_cfg->{ids}->{$id}->{vrf} eq $vrf);
-           }
-       }
+    #vrf-vxlan need to be defined
 
-       my $vrfvxlan = $sdn_cfg->{ids}->{$transportid}->{'vrf-vxlan'};
-       if (!defined($vrfvxlan)) {
-           die "missing vrf-vxlan option";
-       } else {
-           # verify that vrf-vxlan is not already declared in another transport
-           foreach my $id (keys %{$sdn_cfg->{ids}}) {
-               next if $id eq $transportid;
-               die "vrf-vxlan $vrfvxlan is already declared in $id"
-                       if (defined($sdn_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
-           }
-       }
+    my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
+    # verify that vrf-vxlan is not already declared in another zone
+    foreach my $id (keys %{$zone_cfg->{ids}}) {
+       next if $id eq $zoneid;
+       die "vrf-vxlan $vrfvxlan is already declared in $id"
+               if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
     }
 }