self.vxlan_mode = lconst.VXLAN_NONE
if cfg.CONF.VXLAN.enable_vxlan:
device = self.get_local_ip_device(self.local_ip)
+ self.validate_vxlan_group_with_local_ip()
self.local_int = device.name
self.check_vxlan_support()
# Store network mapping to segments
{'brq': bridge, 'net': physnet})
sys.exit(1)
+ def validate_vxlan_group_with_local_ip(self):
+ if not cfg.CONF.VXLAN.vxlan_group:
+ return
+ try:
+ ip_addr = netaddr.IPAddress(self.local_ip)
+ # Ensure the configured group address/range is valid and multicast
+ group_net = netaddr.IPNetwork(cfg.CONF.VXLAN.vxlan_group)
+ if not group_net.is_multicast():
+ raise ValueError()
+ if not ip_addr.version == group_net.version:
+ raise ValueError()
+ except (netaddr.core.AddrFormatError, ValueError):
+ LOG.error(_LE("Invalid VXLAN Group: %(group)s, must be an address "
+ "or network (in CIDR notation) in a multicast "
+ "range of the same address family as local_ip: "
+ "%(ip)s"),
+ {'group': cfg.CONF.VXLAN.vxlan_group,
+ 'ip': self.local_ip})
+ sys.exit(1)
+
def get_local_ip_device(self, local_ip):
"""Return the device with local_ip on the host."""
device = self.ip.get_device_by_ip(local_ip)
"incorrect vxlan device name"), segmentation_id)
def get_vxlan_group(self, segmentation_id):
- try:
- # Ensure the configured group address/range is valid and multicast
- net = netaddr.IPNetwork(cfg.CONF.VXLAN.vxlan_group)
- if not net.is_multicast():
- raise ValueError()
- # Map the segmentation ID to (one of) the group address(es)
- return str(net.network +
- (int(segmentation_id) & int(net.hostmask)))
- except (netaddr.core.AddrFormatError, ValueError):
- LOG.warning(_LW("Invalid VXLAN Group: %s, must be an address "
- "or network (in CIDR notation) in a multicast "
- "range"),
- cfg.CONF.VXLAN.vxlan_group)
+ net = netaddr.IPNetwork(cfg.CONF.VXLAN.vxlan_group)
+ # Map the segmentation ID to (one of) the group address(es)
+ return str(net.network +
+ (int(segmentation_id) & int(net.hostmask)))
def get_deletable_bridges(self):
bridge_list = bridge_lib.get_bridge_names()
from neutron.tests import base
LOCAL_IP = '192.168.0.33'
+LOCAL_IPV6 = '2001:db8:1::33'
+VXLAN_GROUPV6 = 'ff05::/120'
PORT_1 = 'abcdef01-12ddssdfds-fdsfsd'
DEVICE_1 = 'tapabcdef01-12'
NETWORK_ID = '57653b20-ed5b-4ed0-a31d-06f84e3fd909'
mock.patch.object(ip_lib, 'device_exists', return_value=True),\
mock.patch.object(linuxbridge_neutron_agent.LinuxBridgeManager,
'check_vxlan_support'):
+ cfg.CONF.set_override('local_ip', LOCAL_IP, 'VXLAN')
return linuxbridge_neutron_agent.LinuxBridgeManager(
bridge_mappings, interface_mappings)
'neutron.agent.firewall.NoopFirewallDriver',
group='SECURITYGROUP')
cfg.CONF.set_default('quitting_rpc_timeout', 10, 'AGENT')
+ cfg.CONF.set_override('local_ip', LOCAL_IP, 'VXLAN')
self.get_devices_p = mock.patch.object(ip_lib.IPWrapper, 'get_devices')
self.get_devices = self.get_devices_p.start()
self.get_devices.return_value = [ip_lib.IPDevice('eth77')]
self.assertEqual(1, log.call_count)
exit.assert_called_once_with(1)
+ def _test_vxlan_group_validation(self, bad_local_ip, bad_vxlan_group):
+ with mock.patch.object(ip_lib.IPWrapper,
+ 'get_device_by_ip',
+ return_value=FAKE_DEFAULT_DEV),\
+ mock.patch.object(sys, 'exit') as exit,\
+ mock.patch.object(linuxbridge_neutron_agent.LOG,
+ 'error') as log:
+ self.lbm.local_ip = bad_local_ip
+ cfg.CONF.set_override('vxlan_group', bad_vxlan_group, 'VXLAN')
+ self.lbm.validate_vxlan_group_with_local_ip()
+ self.assertEqual(1, log.call_count)
+ exit.assert_called_once_with(1)
+
+ def test_vxlan_group_validation_with_mismatched_local_ip(self):
+ self._test_vxlan_group_validation(LOCAL_IP, VXLAN_GROUPV6)
+
+ def test_vxlan_group_validation_with_unicast_group(self):
+ self._test_vxlan_group_validation(LOCAL_IP, '240.0.0.0')
+
+ def test_vxlan_group_validation_with_invalid_cidr(self):
+ self._test_vxlan_group_validation(LOCAL_IP, '224.0.0.1/')
+
+ def test_vxlan_group_validation_with_v6_unicast_group(self):
+ self._test_vxlan_group_validation(LOCAL_IPV6, '2001:db8::')
+
def test_get_existing_bridge_name(self):
phy_net = 'physnet0'
self.assertEqual('br-eth2',
self.assertEqual('239.1.2.0', self.lbm.get_vxlan_group(vn_id))
vn_id = 257
self.assertEqual('239.1.2.1', self.lbm.get_vxlan_group(vn_id))
- cfg.CONF.set_override('vxlan_group', '240.0.0.0', 'VXLAN')
- self.assertIsNone(self.lbm.get_vxlan_group(vn_id))
- cfg.CONF.set_override('vxlan_group', '224.0.0.1/', 'VXLAN')
- self.assertIsNone(self.lbm.get_vxlan_group(vn_id))
+
+ def test_get_vxlan_group_with_ipv6(self):
+ cfg.CONF.set_override('local_ip', LOCAL_IPV6, 'VXLAN')
+ self.lbm.local_ip = LOCAL_IPV6
+ cfg.CONF.set_override('vxlan_group', VXLAN_GROUPV6, 'VXLAN')
+ vn_id = p_const.MAX_VXLAN_VNI
+ self.assertEqual('ff05::ff', self.lbm.get_vxlan_group(vn_id))
+ vn_id = 256
+ self.assertEqual('ff05::', self.lbm.get_vxlan_group(vn_id))
+ vn_id = 257
+ self.assertEqual('ff05::1', self.lbm.get_vxlan_group(vn_id))
def test_get_deletable_bridges(self):
br_list = ["br-int", "brq1", "brq2", "brq-user"]
class TestLinuxBridgeRpcCallbacks(base.BaseTestCase):
def setUp(self):
- cfg.CONF.set_override('local_ip', LOCAL_IP, 'VXLAN')
super(TestLinuxBridgeRpcCallbacks, self).setUp()
class FakeLBAgent(object):