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