]> git.proxmox.com Git - pve-network.git/blame - PVE/Network/SDN/Zones/EvpnPlugin.pm
qinq: use new model + ovs/classic bridge support
[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 {
ba7ac021 41 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $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
7cb9714d 49 my $vrf = $zoneid;
63586d2f
AD
50 my $vrfvxlan = $plugin_config->{'vrf-vxlan'};
51
52 die "missing vxlan tag" if !$tag;
63586d2f 53
4405f2de 54 my @peers = split(',', $controller->{'peers'});
1f543c5f 55 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
63586d2f
AD
56
57 my $mtu = 1450;
ba7ac021 58 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
0251ed2f 59 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
63586d2f
AD
60
61 #vxlan interface
62 my @iface_config = ();
63 push @iface_config, "vxlan-id $tag";
64
65 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
66 push @iface_config, "bridge-learning off";
67 push @iface_config, "bridge-arp-nd-suppress on";
68
69 push @iface_config, "mtu $mtu" if $mtu;
70 push(@{$config->{"vxlan$vnetid"}}, @iface_config) if !$config->{"vxlan$vnetid"};
71
72 #vnet bridge
73 @iface_config = ();
74 push @iface_config, "address $ipv4" if $ipv4;
75 push @iface_config, "address $ipv6" if $ipv6;
76 push @iface_config, "hwaddress $mac" if $mac;
77 push @iface_config, "bridge_ports vxlan$vnetid";
78 push @iface_config, "bridge_stp off";
79 push @iface_config, "bridge_fd 0";
80 push @iface_config, "mtu $mtu" if $mtu;
81 push @iface_config, "alias $alias" if $alias;
82 push @iface_config, "ip-forward on" if $ipv4;
83 push @iface_config, "ip6-forward on" if $ipv6;
84 push @iface_config, "arp-accept on" if $ipv4||$ipv6;
85 push @iface_config, "vrf $vrf" if $vrf;
86 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
87
88 if ($vrf) {
89 #vrf interface
90 @iface_config = ();
91 push @iface_config, "vrf-table auto";
92 push(@{$config->{$vrf}}, @iface_config) if !$config->{$vrf};
93
94 if ($vrfvxlan) {
95 #l3vni vxlan interface
7cb9714d 96 my $iface_vxlan = "vxvrf$vrf";
63586d2f
AD
97 @iface_config = ();
98 push @iface_config, "vxlan-id $vrfvxlan";
99 push @iface_config, "vxlan-local-tunnelip $ifaceip" if $ifaceip;
100 push @iface_config, "bridge-learning off";
101 push @iface_config, "bridge-arp-nd-suppress on";
102 push @iface_config, "mtu $mtu" if $mtu;
103 push(@{$config->{$iface_vxlan}}, @iface_config) if !$config->{$iface_vxlan};
104
105 #l3vni bridge
106 my $brvrf = "br$vrf";
107 @iface_config = ();
108 push @iface_config, "bridge-ports $iface_vxlan";
109 push @iface_config, "bridge_stp off";
110 push @iface_config, "bridge_fd 0";
111 push @iface_config, "mtu $mtu" if $mtu;
112 push @iface_config, "vrf $vrf";
113 push(@{$config->{$brvrf}}, @iface_config) if !$config->{$brvrf};
114 }
115 }
116
117 return $config;
118}
119
120sub on_update_hook {
a2b32a94
AD
121 my ($class, $zoneid, $zone_cfg, $controller_cfg) = @_;
122
123 # verify that controller exist
124 my $controller = $zone_cfg->{ids}->{$zoneid}->{controller};
125 if (!defined($controller_cfg->{ids}->{$controller})) {
126 die "controller $controller don't exist";
127 } else {
128 die "$controller is not a evpn controller type" if $controller_cfg->{ids}->{$controller}->{type} ne 'evpn';
129 }
63586d2f 130
7cb9714d 131 #vrf-vxlan need to be defined
a2b32a94
AD
132
133 my $vrfvxlan = $zone_cfg->{ids}->{$zoneid}->{'vrf-vxlan'};
134 # verify that vrf-vxlan is not already declared in another zone
135 foreach my $id (keys %{$zone_cfg->{ids}}) {
136 next if $id eq $zoneid;
137 die "vrf-vxlan $vrfvxlan is already declared in $id"
138 if (defined($zone_cfg->{ids}->{$id}->{'vrf-vxlan'}) && $zone_cfg->{ids}->{$id}->{'vrf-vxlan'} eq $vrfvxlan);
63586d2f
AD
139 }
140}
141
1421;
143
144