]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/EvpnPlugin.pm
remove vxlan|vlan allowed zone option
[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 {
41 'uplink-id' => { optional => 0 },
63586d2f
AD
42 'vrf' => { optional => 0 },
43 'vrf-vxlan' => { optional => 0 },
44 'controller' => { optional => 0 },
45 };
46}
47
48# Plugin implementation
49sub generate_sdn_config {
50 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $uplinks, $config) = @_;
51
52 my $tag = $vnet->{tag};
53 my $alias = $vnet->{alias};
54 my $ipv4 = $vnet->{ipv4};
55 my $ipv6 = $vnet->{ipv6};
56 my $mac = $vnet->{mac};
57
58 my $uplink = $plugin_config->{'uplink-id'};
63586d2f
AD
59 my $vrf = $plugin_config->{'vrf'};
60 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
61
62 die "missing vxlan tag" if !$tag;
63 my $iface = "uplink$uplink";
64 my $ifaceip = "";
65
66 if($uplinks->{$uplink}->{name}) {
67 $iface = $uplinks->{$uplink}->{name};
f5eabba0 68 $ifaceip = PVE::Network::SDN::Zones::Plugin::get_first_local_ipv4_from_interface($iface);
63586d2f
AD
69 }
70
71 my $mtu = 1450;
72 $mtu = $uplinks->{$uplink}->{mtu} - 50 if $uplinks->{$uplink}->{mtu};
73 $mtu = $vnet->{mtu} if $vnet->{mtu};
74
75 #vxlan interface
76 my @iface_config = ();
77 push @iface_config, "vxlan-id $tag";
78
79 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
80 push @iface_config, "bridge-learning off";
81 push @iface_config, "bridge-arp-nd-suppress on";
82
83 push @iface_config, "mtu $mtu" if $mtu;
84 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
85
86 #vnet bridge
87 @iface_config = ();
88 push @iface_config, "address $ipv4" if $ipv4;
89 push @iface_config, "address $ipv6" if $ipv6;
90 push @iface_config, "hwaddress $mac" if $mac;
91 push @iface_config, "bridge_ports vxlan$vnetid";
92 push @iface_config, "bridge_stp off";
93 push @iface_config, "bridge_fd 0";
94 push @iface_config, "mtu $mtu" if $mtu;
95 push @iface_config, "alias $alias" if $alias;
96 push @iface_config, "ip-forward on" if $ipv4;
97 push @iface_config, "ip6-forward on" if $ipv6;
98 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
99 push @iface_config, "vrf $vrf" if $vrf;
100 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
101
102 if ($vrf) {
103 #vrf interface
104 @iface_config = ();
105 push @iface_config, "vrf-table auto";
106 push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf};
107
108 if ($vrfvxlan) {
109 #l3vni vxlan interface
110 my $iface_vxlan = "vxlan$vrf";
111 @iface_config = ();
112 push @iface_config, "vxlan-id $vrfvxlan";
113 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
114 push @iface_config, "bridge-learning off";
115 push @iface_config, "bridge-arp-nd-suppress on";
116 push @iface_config, "mtu $mtu" if $mtu;
117 push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan};
118
119 #l3vni bridge
120 my $brvrf = "br$vrf";
121 @iface_config = ();
122 push @iface_config, "bridge-ports $iface_vxlan";
123 push @iface_config, "bridge_stp off";
124 push @iface_config, "bridge_fd 0";
125 push @iface_config, "mtu $mtu" if $mtu;
126 push @iface_config, "vrf $vrf";
127 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
128 }
129 }
130
131 return $config;
132}
133
134sub on_update_hook {
135 my ($class, $transportid, $sdn_cfg) = @_;
136
63586d2f
AD
137 # verify that router exist
138 if (defined($sdn_cfg->{ids}->{$transportid}->{router})) {
139 my $router = $sdn_cfg->{ids}->{$transportid}->{router};
140 if (!defined($sdn_cfg->{ids}->{$router})) {
141 die "router $router don't exist";
142 } else {
143 die "$router is not a router type" if $sdn_cfg->{ids}->{$router}->{type} ne 'frr';
144 }
145
146 #vrf && vrf-vxlan need to be defined with router
147 my $vrf = $sdn_cfg->{ids}->{$transportid}->{vrf};
148 if (!defined($vrf)) {
149 die "missing vrf option";
150 } else {
151 # verify that vrf is not already declared in another transport
152 foreach my $id (keys %{$sdn_cfg->{ids}}) {
153 next if $id eq $transportid;
154 die "vrf $vrf is already declared in $id"
155 if (defined($sdn_cfg->{ids}->{$id}->{vrf}) && $sdn_cfg->{ids}->{$id}->{vrf} eq $vrf);
156 }
157 }
158
159 my $vrfvxlan = $sdn_cfg->{ids}->{$transportid}->{'vrf-vxlan'};
160 if (!defined($vrfvxlan)) {
161 die "missing vrf-vxlan option";
162 } else {
163 # verify that vrf-vxlan is not already declared in another transport
164 foreach my $id (keys %{$sdn_cfg->{ids}}) {
165 next if $id eq $transportid;
166 die "vrf-vxlan $vrfvxlan is already declared in $id"
167 if (defined($sdn_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $sdn_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
168 }
169 }
170 }
171}
172
1731;
174
175