]> git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/VxlanPlugin.pm
b3ed05f15e3da529e9f998ddac1e992f7017e9b1
[pve-network.git] / PVE / Network / SDN / Zones / VxlanPlugin.pm
1 package PVE::Network::SDN::Zones::VxlanPlugin;
2
3 use strict;
4 use warnings;
5 use PVE::Network::SDN::Zones::Plugin;
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::Plugin');
11
12 PVE::JSONSchema::register_format('pve-sdn-vxlanrange', \&pve_verify_sdn_vxlanrange);
13 sub pve_verify_sdn_vxlanrange {
14 my ($vxlanstr) = @_;
15
16 PVE::Network::SDN::Zones::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
17
18 return $vxlanstr;
19 }
20
21 sub type {
22 return 'vxlan';
23 }
24
25 sub properties {
26 return {
27 'peers' => {
28 description => "peers address list.",
29 type => 'string', format => 'ip-list'
30 },
31 };
32 }
33
34 sub options {
35
36 return {
37 nodes => { optional => 1},
38 peers => { optional => 0 },
39 mtu => { optional => 1 },
40 };
41 }
42
43 # Plugin implementation
44 sub generate_sdn_config {
45 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $interfaces_config, $config) = @_;
46
47 my $tag = $vnet->{tag};
48 my $alias = $vnet->{alias};
49 my $ipv4 = $vnet->{ipv4};
50 my $ipv6 = $vnet->{ipv6};
51 my $mac = $vnet->{mac};
52 my $multicastaddress = $plugin_config->{'multicast-address'};
53 my @peers = split(',', $plugin_config->{'peers'}) if $plugin_config->{'peers'};
54 my $vxlan_iface = "vxlan_$vnetid";
55
56 die "missing vxlan tag" if !$tag;
57
58 my ($ifaceip, $iface) = PVE::Network::SDN::Zones::Plugin::find_local_ip_interface_peers(\@peers);
59
60 my $mtu = 1450;
61 $mtu = $interfaces_config->{$iface}->{mtu} - 50 if $interfaces_config->{$iface}->{mtu};
62 $mtu = $plugin_config->{mtu} if $plugin_config->{mtu};
63
64 #vxlan interface
65 my @iface_config = ();
66 push @iface_config, "vxlan-id $tag";
67
68 foreach my $address (@peers) {
69 next if $address eq $ifaceip;
70 push @iface_config, "vxlan_remoteip $address";
71 }
72
73
74 push @iface_config, "mtu $mtu" if $mtu;
75 push(@{$config->{$vxlan_iface}}, @iface_config) if !$config->{$vxlan_iface};
76
77 #vnet bridge
78 @iface_config = ();
79 push @iface_config, "address $ipv4" if $ipv4;
80 push @iface_config, "address $ipv6" if $ipv6;
81 push @iface_config, "hwaddress $mac" if $mac;
82 push @iface_config, "bridge_ports $vxlan_iface";
83 push @iface_config, "bridge_stp off";
84 push @iface_config, "bridge_fd 0";
85 push @iface_config, "mtu $mtu" if $mtu;
86 push @iface_config, "alias $alias" if $alias;
87 push(@{$config->{$vnetid}}, @iface_config) if !$config->{$vnetid};
88
89 return $config;
90 }
91
92 1;
93
94