]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/EvpnPlugin.pm
evpn: remove uplink-id
[pve-network.git] / PVE / Network / SDN / Zones / EvpnPlugin.pm
1 package PVE::Network::SDN::Zones::EvpnPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Zones::VxlanPlugin;
6 use PVE::Tools qw($IPV4RE);
7 use PVE::INotify;
8 use PVE::Network::SDN::Controllers::EvpnPlugin;
9
10 use base('PVE::Network::SDN::Zones::VxlanPlugin');
11
12 sub type {
13 return 'evpn';
14 }
15
16 sub properties {
17 return {
18 'vrf-vxlan' => {
19 type => 'integer',
20 description => "l3vni.",
21 },
22 'controller' => {
23 type => 'string',
24 description => "Frr router name",
25 },
26 };
27 }
28
29 sub options {
30
31 return {
32 nodes => { optional => 1},
33 'vrf-vxlan' => { optional => 0 },
34 'controller' => { optional => 0 },
35 };
36 }
37
38 # Plugin implementation
39 sub generate_sdn_config {
40 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $controller, $config) = @_;
41
42 my $tag = $vnet->{tag};
43 my $alias = $vnet->{alias};
44 my $ipv4 = $vnet->{ipv4};
45 my $ipv6 = $vnet->{ipv6};
46 my $mac = $vnet->{mac};
47
48 my $vrf = $zoneid;
49 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
50
51 die "missing vxlan tag" if !$tag;
52
53 my @peers = split(',', $controller->{'peers'});
54 my ($ifaceip, $iface) = PVE::Network::SDN::Controllers::EvpnPlugin::find_local_ip_interface(\@peers);
55
56 my $mtu = 1450;
57 $mtu = $uplinks->{$iface}->{mtu} - 50 if $uplinks->{$iface}->{mtu};
58 $mtu = $vnet->{mtu} if $vnet->{mtu};
59
60 #vxlan interface
61 my @iface_config = ();
62 push @iface_config, "vxlan-id $tag";
63
64 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
65 push @iface_config, "bridge-learning off";
66 push @iface_config, "bridge-arp-nd-suppress on";
67
68 push @iface_config, "mtu $mtu" if $mtu;
69 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
70
71 #vnet bridge
72 @iface_config = ();
73 push @iface_config, "address $ipv4" if $ipv4;
74 push @iface_config, "address $ipv6" if $ipv6;
75 push @iface_config, "hwaddress $mac" if $mac;
76 push @iface_config, "bridge_ports vxlan$vnetid";
77 push @iface_config, "bridge_stp off";
78 push @iface_config, "bridge_fd 0";
79 push @iface_config, "mtu $mtu" if $mtu;
80 push @iface_config, "alias $alias" if $alias;
81 push @iface_config, "ip-forward on" if $ipv4;
82 push @iface_config, "ip6-forward on" if $ipv6;
83 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
84 push @iface_config, "vrf $vrf" if $vrf;
85 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
86
87 if ($vrf) {
88 #vrf interface
89 @iface_config = ();
90 push @iface_config, "vrf-table auto";
91 push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf};
92
93 if ($vrfvxlan) {
94 #l3vni vxlan interface
95 my $iface_vxlan = "vxvrf$vrf";
96 @iface_config = ();
97 push @iface_config, "vxlan-id $vrfvxlan";
98 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
99 push @iface_config, "bridge-learning off";
100 push @iface_config, "bridge-arp-nd-suppress on";
101 push @iface_config, "mtu $mtu" if $mtu;
102 push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan};
103
104 #l3vni bridge
105 my $brvrf = "br$vrf";
106 @iface_config = ();
107 push @iface_config, "bridge-ports $iface_vxlan";
108 push @iface_config, "bridge_stp off";
109 push @iface_config, "bridge_fd 0";
110 push @iface_config, "mtu $mtu" if $mtu;
111 push @iface_config, "vrf $vrf";
112 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
113 }
114 }
115
116 return $config;
117 }
118
119 sub on_update_hook {
120 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
121
122 # verify that controller exist
123 my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
124 if (!defined($controller_cfg->{ids}->{$controller})) {
125 die "controller $controller don't exist";
126 } else {
127 die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
128 }
129
130 #vrf-vxlan need to be defined
131
132 my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
133 # verify that vrf-vxlan is not already declared in another zone
134 foreach my $id (keys %{$zone_cfg->{ids}}) {
135 next if $id eq $zoneid;
136 die "vrf-vxlan $vrfvxlan is already declared in $id"
137 if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
138 }
139 }
140
141 1;
142
143