]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/EvpnPlugin.pm
fixup: drop trailing whitespaces
[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 mtu => { optional => 1 },
36 };
37 }
38
39 # Plugin implementation
40 sub generate_sdn_config {
41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
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
49 my $vrf_iface = "vrf_$zoneid";
50 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
51
52 die "missing vxlan tag" if !$tag;
53 warn "vlan-aware vnet can't be enabled with evpn plugin" if $vnet->{vlanaware};
54
55 my @peers = split(',', $controller->{'peers'});
56 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
57
58 my $mtu = 1450;
59 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
60 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
61
62 #vxlan interface
63 my $vxlan_iface = "vxlan_$vnetid";
64 my @iface_config = ();
65 push @iface_config, "vxlan-id $tag";
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;
71 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
72
73 #vnet bridge
74 @iface_config = ();
75 push @iface_config, "address $ipv4" if $ipv4;
76 push @iface_config, "address $ipv6" if $ipv6;
77 push @iface_config, "hwaddress $mac" if $mac;
78 push @iface_config, "bridge_ports $vxlan_iface";
79 push @iface_config, "bridge_stp off";
80 push @iface_config, "bridge_fd 0";
81 push @iface_config, "mtu $mtu" if $mtu;
82 push @iface_config, "alias $alias" if $alias;
83 push @iface_config, "ip-forward on" if $ipv4;
84 push @iface_config, "ip6-forward on" if $ipv6;
85 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
86 push @iface_config, "vrf $vrf_iface" if $vrf_iface;
87 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
88
89 if ($vrf_iface) {
90 #vrf interface
91 @iface_config = ();
92 push @iface_config, "vrf-table auto";
93 push(@{$config->{$vrf_iface}}, @iface_config) if !$config->{$vrf_iface};
94
95 if ($vrfvxlan) {
96 #l3vni vxlan interface
97 my $iface_vrf_vxlan = "vrfvx_$zoneid";
98 @iface_config = ();
99 push @iface_config, "vxlan-id $vrfvxlan";
100 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
101 push @iface_config, "bridge-learning off";
102 push @iface_config, "bridge-arp-nd-suppress on";
103 push @iface_config, "mtu $mtu" if $mtu;
104 push(@{$config->{$iface_vrf_vxlan}}, @iface_config) if !$config->{$iface_vrf_vxlan};
105
106 #l3vni bridge
107 my $brvrf = "vrfbr_$zoneid";
108 @iface_config = ();
109 push @iface_config, "bridge-ports $iface_vrf_vxlan";
110 push @iface_config, "bridge_stp off";
111 push @iface_config, "bridge_fd 0";
112 push @iface_config, "mtu $mtu" if $mtu;
113 push @iface_config, "vrf $vrf_iface";
114 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
115 }
116 }
117
118 return $config;
119 }
120
121 sub on_update_hook {
122 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
123
124 # verify that controller exist
125 my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
126 if (!defined($controller_cfg->{ids}->{$controller})) {
127 die "controller $controller don't exist";
128 } else {
129 die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
130 }
131
132 #vrf-vxlan need to be defined
133
134 my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
135 # verify that vrf-vxlan is not already declared in another zone
136 foreach my $id (keys %{$zone_cfg->{ids}}) {
137 next if $id eq $zoneid;
138 die "vrf-vxlan $vrfvxlan is already declared in $id"
139 if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
140 }
141 }
142
143 1;
144
145