]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/EvpnPlugin.pm
zones: simple|evpn: add gateway ip from subnets to vnet
[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;
4405f2de 8use PVE::Network::SDN::Controllers::EvpnPlugin;
63586d2f 9
f5eabba0 10use base('PVE::Network::SDN::Zones::VxlanPlugin');
63586d2f
AD
11
12sub type {
13 return 'evpn';
14}
15
63586d2f
AD
16sub properties {
17 return {
63586d2f
AD
18 'vrf-vxlan' => {
19 type => 'integer',
20 description => "l3vni.",
21 },
22 'controller' => {
23 type => 'string',
24 description => "Frr router name",
25 },
26 };
27}
28
29sub options {
30
31 return {
c2b9c173 32 nodes => { optional => 1},
63586d2f
AD
33 'vrf-vxlan' => { optional => 0 },
34 'controller' => { optional => 0 },
823f2e2a 35 mtu => { optional => 1 },
63586d2f
AD
36 };
37}
38
39# Plugin implementation
40sub generate_sdn_config {
7024ec2b 41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
63586d2f
AD
42
43 my $tag = $vnet->{tag};
44 my $alias = $vnet->{alias};
45 my $ipv4 = $vnet->{ipv4};
46 my $ipv6 = $vnet->{ipv6};
47 my $mac = $vnet->{mac};
48
1de0abc0 49 my $vrf_iface = "vrf_$zoneid";
63586d2f
AD
50 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
51
52 die "missing vxlan tag" if !$tag;
912fb443 53 warn "vlan-aware vnet can't be enabled with evpn plugin" if $vnet->{vlanaware};
63586d2f 54
5a60da84 55 my @peers = PVE::Tools::split_list($controller->{'peers'});
1f543c5f 56 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
63586d2f
AD
57
58 my $mtu = 1450;
ba7ac021 59 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
0251ed2f 60 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
63586d2f
AD
61
62 #vxlan interface
1de0abc0 63 my $vxlan_iface = "vxlan_$vnetid";
63586d2f
AD
64 my @iface_config = ();
65 push @iface_config, "vxlan-id $tag";
63586d2f
AD
66 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
67 push @iface_config, "bridge-learning off";
68 push @iface_config, "bridge-arp-nd-suppress on";
69
70 push @iface_config, "mtu $mtu" if $mtu;
1de0abc0 71 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
63586d2f
AD
72
73 #vnet bridge
74 @iface_config = ();
7024ec2b
AD
75
76 my @subnets = PVE::Tools::split_list($vnet->{subnets}) if $vnet->{subnets};
77 foreach my $subnet (@subnets) {
78 next if !defined($subnet_cfg->{ids}->{$subnet});
79 push @iface_config, "address $subnet_cfg->{ids}->{$subnet}->{gateway}" if $subnet_cfg->{ids}->{$subnet}->{gateway};
80 }
81
63586d2f 82 push @iface_config, "hwaddress $mac" if $mac;
1de0abc0 83 push @iface_config, "bridge_ports $vxlan_iface";
63586d2f
AD
84 push @iface_config, "bridge_stp off";
85 push @iface_config, "bridge_fd 0";
86 push @iface_config, "mtu $mtu" if $mtu;
87 push @iface_config, "alias $alias" if $alias;
88 push @iface_config, "ip-forward on" if $ipv4;
89 push @iface_config, "ip6-forward on" if $ipv6;
90 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
1de0abc0 91 push @iface_config, "vrf $vrf_iface" if $vrf_iface;
63586d2f
AD
92 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
93
1de0abc0 94 if ($vrf_iface) {
63586d2f
AD
95 #vrf interface
96 @iface_config = ();
97 push @iface_config, "vrf-table auto";
1de0abc0 98 push(@{$config->{$vrf_iface}}, @iface_config) if !$config->{$vrf_iface};
63586d2f
AD
99
100 if ($vrfvxlan) {
101 #l3vni vxlan interface
1de0abc0 102 my $iface_vrf_vxlan = "vrfvx_$zoneid";
63586d2f
AD
103 @iface_config = ();
104 push @iface_config, "vxlan-id $vrfvxlan";
105 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
106 push @iface_config, "bridge-learning off";
107 push @iface_config, "bridge-arp-nd-suppress on";
108 push @iface_config, "mtu $mtu" if $mtu;
1de0abc0 109 push(@{$config->{$iface_vrf_vxlan}}, @iface_config) if !$config->{$iface_vrf_vxlan};
63586d2f
AD
110
111 #l3vni bridge
1de0abc0 112 my $brvrf = "vrfbr_$zoneid";
63586d2f 113 @iface_config = ();
1de0abc0 114 push @iface_config, "bridge-ports $iface_vrf_vxlan";
63586d2f
AD
115 push @iface_config, "bridge_stp off";
116 push @iface_config, "bridge_fd 0";
117 push @iface_config, "mtu $mtu" if $mtu;
1de0abc0 118 push @iface_config, "vrf $vrf_iface";
63586d2f
AD
119 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
120 }
121 }
122
123 return $config;
124}
125
126sub on_update_hook {
a2b32a94
AD
127 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
128
129 # verify that controller exist
130 my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
131 if (!defined($controller_cfg->{ids}->{$controller})) {
132 die "controller $controller don't exist";
133 } else {
134 die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
135 }
63586d2f 136
7cb9714d 137 #vrf-vxlan need to be defined
a2b32a94
AD
138
139 my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
140 # verify that vrf-vxlan is not already declared in another zone
141 foreach my $id (keys %{$zone_cfg->{ids}}) {
142 next if $id eq $zoneid;
143 die "vrf-vxlan $vrfvxlan is already declared in $id"
144 if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
63586d2f
AD
145 }
146}
147
1d44ce70
AD
148sub verify_tag {
149 my ($class, $tag) = @_;
150
151 raise_param_exc({ tag => "missing vxlan tag"}) if !defined($tag);
152 raise_param_exc({ tag => "vxlan tag max value is 16777216"}) if $tag > 16777216;
153}
154
63586d2f
AD
1551;
156
157