[pve-devel] [PATCH pve-network 4/6] add vxlan multicast plugin

Alexandre Derumier aderumier at odiso.com
Wed Mar 27 18:24:08 CET 2019


/etc/pve/network/transports.cfg

vxlanmulticast: vxlanmulticastzone1
                uplink-id 1
                multicast-address 225.20.21.1
                vxlan-allowed 4-5

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Network/VxlanMulticastPlugin.pm | 85 +++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)
 create mode 100644 PVE/Network/VxlanMulticastPlugin.pm

diff --git a/PVE/Network/VxlanMulticastPlugin.pm b/PVE/Network/VxlanMulticastPlugin.pm
new file mode 100644
index 0000000..1343849
--- /dev/null
+++ b/PVE/Network/VxlanMulticastPlugin.pm
@@ -0,0 +1,85 @@
+package PVE::Network::VxlanMulticastPlugin;
+
+use strict;
+use warnings;
+use PVE::Network::Plugin;
+
+use base('PVE::Network::Plugin');
+
+PVE::JSONSchema::register_format('pve-network-vxlanrange', \&pve_verify_network_vxlanrange);
+sub pve_verify_network_vxlanrange {
+   my ($vxlanstr) = @_;
+
+   PVE::Network::Plugin::parse_tag_number_or_range($vxlanstr, '16777216');
+
+   return $vxlanstr;
+}
+
+sub type {
+    return 'vxlanmulticast';
+}
+
+sub properties {
+    return {
+        'vxlan-allowed' => {
+            type => 'string', format => 'pve-network-vxlanrange',
+            description => "Allowed vlan range",
+        },
+        'multicast-address' => {
+            description => "Multicast address.",
+            type => 'string',  #fixme: format 
+        },
+
+    };
+}
+
+sub options {
+
+    return {
+	'uplink-id' => { fixed => 1 },
+        'multicast-address' => { fixed => 1 },
+        'vxlan-allowed' => { optional => 1 },
+    };
+}
+
+# Plugin implementation
+sub generate_network_config {
+    my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $interfaces, $uplinks) = @_;
+
+    my $tag = $vnet->{tag};
+    my $mtu = $vnet->{mtu};
+    my $multicastaddress = $plugin_config->{'multicast-address'};
+    my $uplink = $plugin_config->{'uplink-id'};
+    my $vxlanallowed = $plugin_config->{'vxlan-allowed'};
+
+    die "missing vxlan tag" if !$tag;
+    die "uplink $uplink is not defined" if !$uplinks->{$uplink};
+    my $iface = $uplinks->{$uplink};
+
+    eval {
+	PVE::Network::Plugin::parse_tag_number_or_range($vxlanallowed, '16777216', $tag) if $vxlanallowed;
+    };
+    if($@) {
+	die "vlan $tag is not allowed in transport $zoneid";
+    }
+
+    my $config = "\n";
+    $config .= "auto vxlan$vnetid\n";
+    $config .= "iface vxlan$vnetid inet manual\n";
+    $config .= "       vxlan-id $tag\n" if $tag;
+    $config .= "       vxlan-svcnodeip $multicastaddress\n" if $multicastaddress;
+    $config .= "       vxlan-physdev $iface\n" if $iface;
+    $config .= "\n";
+    $config .= "auto $vnetid\n";
+    $config .= "iface $vnetid inet manual\n";
+    $config .= "        bridge_ports vxlan$vnetid\n";
+    $config .= "        bridge_stp off\n";
+    $config .= "        bridge_fd 0\n";
+    $config .= "        mtu $mtu\n" if $mtu;
+
+    return $config;
+}
+
+1;
+
+
-- 
2.11.0



More information about the pve-devel mailing list