From 4774916ae94d6a47d9f66373caf1032df1bddb71 Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Wed, 31 Oct 2018 11:59:12 +0100 Subject: [PATCH] F #2161 Support 2 modes for vxlan multicast and EVPN Co-authored-by: Jan Orel (cherry picked from commit 107f86b556f8cbb394dddca1f7af71a7cdb96b27) --- src/vnm_mad/remotes/OpenNebulaNetwork.conf | 15 +++++++- src/vnm_mad/remotes/vxlan/vxlan.rb | 44 +++++++++++++++++----- 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.conf b/src/vnm_mad/remotes/OpenNebulaNetwork.conf index 505ebd2b56..973eadd521 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.conf +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.conf @@ -51,6 +51,10 @@ # VXLAN Options ################################################################################ +# Multicast protocol for multi destination BUM traffic. Options: +# - multicast, for IP multicast +# - evpn, for BGP EVPN control plane +:vxlan_mode: multicast # Base multicast address for each VLAN. The mc address is :vxlan_mc + :vlan_id :vxlan_mc: 239.0.0.0 # Time To Live (TTL) should be > 1 in routed multicast networks (IGMP) @@ -58,6 +62,16 @@ # Default MTU for the VXLAN interface :vxlan_mtu: 1500 +# Tunnel endpoint communication type. Only for evpn vxlan_mode. +# - dev, tunnel endpoint communication is sent to PHYDEV +# - local_ip, first ip addr of PHYDEV is used as address for the communication +:vxlan_tep: dev + +# Additional ip link options, uncomment the following to disable learning for +# EVPN mode +# :ip_link_conf: +# :nolearning: + ################################################################################ # Security Group Options ################################################################################ @@ -98,4 +112,3 @@ # :ip_link_conf: # :udp6zerocsumrx: # :tos: 3 - diff --git a/src/vnm_mad/remotes/vxlan/vxlan.rb b/src/vnm_mad/remotes/vxlan/vxlan.rb index 47f6cb1965..788308c16a 100644 --- a/src/vnm_mad/remotes/vxlan/vxlan.rb +++ b/src/vnm_mad/remotes/vxlan/vxlan.rb @@ -24,14 +24,30 @@ module VXLAN # This function creates and activate a VLAN device ############################################################################ def create_vlan_dev - begin - ipaddr = IPAddr.new @nic[:conf][:vxlan_mc] - rescue - ipaddr = IPAddr.new "239.0.0.0" - end + vxlan_mode = @nic[:conf][:vxlan_mode] || 'multicast' + group = "" - mc = ipaddr.to_i + @nic[@attr_vlan_id].to_i - mcs = IPAddr.new(mc, Socket::AF_INET).to_s + if vxlan_mode.downcase == 'evpn' + vxlan_tep = @nic[:conf][:vxlan_tep] || 'dev' + + if vxlan_tep.downcase == 'dev' + tep = "dev #{@nic[:phydev]}" + else + tep = "local #{get_interface_first_ip(@nic[:phydev])}" + end + else + begin + ipaddr = IPAddr.new @nic[:conf][:vxlan_mc] + rescue + ipaddr = IPAddr.new "239.0.0.0" + end + + mc = ipaddr.to_i + @nic[@attr_vlan_id].to_i + mcs = IPAddr.new(mc, Socket::AF_INET).to_s + + group = "group #{mcs}" + tep = "dev #{@nic[:phydev]}" + end mtu = @nic[:mtu] ? "mtu #{@nic[:mtu]}" : "mtu #{@nic[:conf][:vxlan_mtu]}" ttl = @nic[:conf][:vxlan_ttl] ? "ttl #{@nic[:conf][:vxlan_ttl]}" : "" @@ -50,8 +66,8 @@ module VXLAN end OpenNebula.exec_and_log("#{command(:ip)} link add #{@nic[@attr_vlan_dev]}"\ - " #{mtu} type vxlan id #{@nic[@attr_vlan_id]} group #{mcs} #{ttl}"\ - " dev #{@nic[:phydev]} #{ip_link_conf}") + " #{mtu} type vxlan id #{@nic[@attr_vlan_id]} #{group} #{ttl}"\ + " #{tep} #{ip_link_conf}") OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[@attr_vlan_dev]} up") end @@ -72,4 +88,14 @@ module VXLAN nil end + + def get_interface_first_ip(name) + text = %x(#{command(:ip)} addr show dev #{name}) + return nil if $?.exitstatus != 0 + + text.each_line do |line| + m = line.match(/^\s*inet6? ([a-f:\d\.]+)/i) + return m[1] if m + end + end end