From 33b30089f5537d8259195d9b4f22bda4918c6695 Mon Sep 17 00:00:00 2001 From: Javi Fontan Date: Thu, 3 Nov 2016 15:45:31 +0100 Subject: [PATCH] F #4888: Check if bridge contains incorrect vlan --- src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb | 13 ++++++++++ src/vnm_mad/remotes/OpenNebulaNetwork.conf | 4 +++ src/vnm_mad/remotes/lib/vlan.rb | 25 +++++++++++++++++++ src/vnm_mad/remotes/vxlan/vxlan_driver.rb | 13 ++++++++++ 4 files changed, 55 insertions(+) diff --git a/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb b/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb index 282d6afd0e..691ade0310 100644 --- a/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb +++ b/src/vnm_mad/remotes/802.1Q/vlan_tag_driver.rb @@ -51,4 +51,17 @@ class VLANTagDriver < VNMMAD::VLANDriver OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up") end + + def get_interface_vlan(name) + text = %x(#{command(:ip)} -d link show #{name}) + return nil if $?.exitstatus != 0 + + text.each_line do |line| + m = line.match(/vlan protocol 802.1Q id (\d+)/) + + return m[1] if m + end + + nil + end end diff --git a/src/vnm_mad/remotes/OpenNebulaNetwork.conf b/src/vnm_mad/remotes/OpenNebulaNetwork.conf index 9c58fb556a..16ae01a7eb 100644 --- a/src/vnm_mad/remotes/OpenNebulaNetwork.conf +++ b/src/vnm_mad/remotes/OpenNebulaNetwork.conf @@ -14,6 +14,10 @@ # limitations under the License. # #--------------------------------------------------------------------------- # +# Set to true to check that no other vlans are connected to the bridge. +# Works with 802.1Q and VXLAN. +:validate_vlan_id: false + ################################################################################ # Open vSwitch Options ################################################################################ diff --git a/src/vnm_mad/remotes/lib/vlan.rb b/src/vnm_mad/remotes/lib/vlan.rb index 578ef10814..a63f3f0094 100644 --- a/src/vnm_mad/remotes/lib/vlan.rb +++ b/src/vnm_mad/remotes/lib/vlan.rb @@ -46,6 +46,9 @@ module VNMMAD # Create the bridge. create_bridge + # Check that no other vlans are connected to this bridge + validate_vlan_id + # Return if vlan device is already in the bridge. next if @bridges[@nic[:bridge]].include? @nic[:vlan_dev] @@ -149,5 +152,27 @@ module VNMMAD bridges end + + def get_interface_vlan(name) + nil + end + + def validate_vlan_id + @bridges[@nic[:bridge]].each do |interface| + vlan = get_interface_vlan(interface) + + if vlan && vlan.to_s != @nic[:vlan_id] + OpenNebula.log_error("The interface #{interface} has "\ + "vlan_id = #{vlan} but the network is configured "\ + "with vlan_id = #{@nic[:vlan_id]}") + + msg = "Interface with an incorrect vlan_id is already in "\ + "the bridge" + OpenNebula.error_message(msg) + + exit(-1) + end + end + end end end diff --git a/src/vnm_mad/remotes/vxlan/vxlan_driver.rb b/src/vnm_mad/remotes/vxlan/vxlan_driver.rb index 3ca84b1ee7..509c7c24e1 100644 --- a/src/vnm_mad/remotes/vxlan/vxlan_driver.rb +++ b/src/vnm_mad/remotes/vxlan/vxlan_driver.rb @@ -54,4 +54,17 @@ class VXLANDriver < VNMMAD::VLANDriver OpenNebula.exec_and_log("#{command(:ip)} link set #{@nic[:vlan_dev]} up") end + + def get_interface_vlan(name) + text = %x(#{command(:ip)} -d link show #{name}) + return nil if $?.exitstatus != 0 + + text.each_line do |line| + m = line.match(/^\s*vxlan id (\d+)/) + + return m[1] if m + end + + nil + end end