예제 #1
0
    def test_connectivity(self):
        """Test connectivity with trunk and sub ports.

        In this test we create a vm that has a trunk on net1 and a vm peer on
        the same network. We check connectivity between the peer and the vm.
        We create a sub port on net2 and a peer, check connectivity again.

        """
        vlan_net1 = helpers.get_not_used_vlan(self.tester.bridge, VLAN_RANGE)
        vlan_net2 = helpers.get_not_used_vlan(self.tester.bridge, VLAN_RANGE)
        trunk_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        sub_port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        sub_port_segmentation_id = helpers.get_not_used_vlan(
            self.tester.bridge, VLAN_RANGE)
        LOG.debug("Using %(n1)d vlan tag as local vlan ID for net1 and %(n2)d "
                  "for local vlan ID for net2", {
                      'n1': vlan_net1, 'n2': vlan_net2})
        self.tester.set_peer_tag(vlan_net1)
        self.trunk_manager.create_trunk(self.trunk.trunk_id,
                                        self.trunk.port_id,
                                        trunk_mac)

        # tag the patch port, this should be done by the ovs agent but we mock
        # it for this test
        conn_testers.OVSBaseConnectionTester.set_tag(
            self.trunk.patch_port_int_name, self.tester.bridge, vlan_net1)

        self.tester.wait_for_connection(self.tester.INGRESS)
        self.tester.wait_for_connection(self.tester.EGRESS)

        self.tester.add_vlan_interface_and_peer(sub_port_segmentation_id,
                                                self.net2_cidr)
        conn_testers.OVSBaseConnectionTester.set_tag(
            self.tester._peer2.port.name, self.tester.bridge, vlan_net2)

        sub_port = trunk_manager.SubPort(self.trunk.trunk_id,
                                         uuidutils.generate_uuid(),
                                         sub_port_mac,
                                         sub_port_segmentation_id)

        self.trunk_manager.add_sub_port(sub_port.trunk_id,
                                        sub_port.port_id,
                                        sub_port.port_mac,
                                        sub_port.segmentation_id)
        # tag the patch port, this should be done by the ovs agent but we mock
        # it for this test
        conn_testers.OVSBaseConnectionTester.set_tag(
            sub_port.patch_port_int_name, self.tester.bridge, vlan_net2)

        self.tester.wait_for_sub_port_connectivity(self.tester.INGRESS)
        self.tester.wait_for_sub_port_connectivity(self.tester.EGRESS)

        self.trunk_manager.remove_sub_port(sub_port.trunk_id,
                                           sub_port.port_id)
        self.tester.wait_for_sub_port_no_connectivity(self.tester.INGRESS)
        self.tester.wait_for_sub_port_no_connectivity(self.tester.EGRESS)

        self.trunk_manager.remove_trunk(self.trunk.trunk_id,
                                        self.trunk.port_id)
        self.tester.wait_for_no_connection(self.tester.INGRESS)
예제 #2
0
    def test_connectivity(self):
        """Test connectivity with trunk and sub ports.

        In this test we create a vm that has a trunk on net1 and a vm peer on
        the same network. We check connectivity between the peer and the vm.
        We create a sub port on net2 and a peer, check connectivity again.

        """
        vlan_net1 = helpers.get_not_used_vlan(self.tester.bridge, VLAN_RANGE)
        vlan_net2 = helpers.get_not_used_vlan(self.tester.bridge, VLAN_RANGE)
        trunk_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        sub_port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        sub_port_segmentation_id = helpers.get_not_used_vlan(
            self.tester.bridge, VLAN_RANGE)
        LOG.debug("Using %(n1)d vlan tag as local vlan ID for net1 and %(n2)d "
                  "for local vlan ID for net2", {
                      'n1': vlan_net1, 'n2': vlan_net2})
        self.tester.set_peer_tag(vlan_net1)
        self.trunk_manager.create_trunk(self.trunk.trunk_id,
                                        self.trunk.port_id,
                                        trunk_mac)

        # tag the patch port, this should be done by the ovs agent but we mock
        # it for this test
        conn_testers.OVSBaseConnectionTester.set_tag(
            self.trunk.patch_port_int_name, self.tester.bridge, vlan_net1)

        self.tester.wait_for_connection(self.tester.INGRESS)
        self.tester.wait_for_connection(self.tester.EGRESS)

        self.tester.add_vlan_interface_and_peer(sub_port_segmentation_id,
                                                self.net2_cidr)
        conn_testers.OVSBaseConnectionTester.set_tag(
            self.tester._peer2.port.name, self.tester.bridge, vlan_net2)

        sub_port = trunk_manager.SubPort(self.trunk.trunk_id,
                                         uuidutils.generate_uuid(),
                                         sub_port_mac,
                                         sub_port_segmentation_id)

        self.trunk_manager.add_sub_port(sub_port.trunk_id,
                                        sub_port.port_id,
                                        sub_port.port_mac,
                                        sub_port.segmentation_id)
        # tag the patch port, this should be done by the ovs agent but we mock
        # it for this test
        conn_testers.OVSBaseConnectionTester.set_tag(
            sub_port.patch_port_int_name, self.tester.bridge, vlan_net2)

        self.tester.wait_for_sub_port_connectivity(self.tester.INGRESS)
        self.tester.wait_for_sub_port_connectivity(self.tester.EGRESS)

        self.trunk_manager.remove_sub_port(sub_port.trunk_id,
                                           sub_port.port_id)
        self.tester.wait_for_sub_port_no_connectivity(self.tester.INGRESS)
        self.tester.wait_for_sub_port_no_connectivity(self.tester.EGRESS)

        self.trunk_manager.remove_trunk(self.trunk.trunk_id,
                                        self.trunk.port_id)
        self.tester.wait_for_no_connection(self.tester.INGRESS)
예제 #3
0
 def _generate_private_interface_for_router(self, subnet):
     subnet_id = _uuid()
     return {
         'id':
         _uuid(),
         'admin_state_up':
         True,
         'network_id':
         _uuid(),
         'mtu':
         1500,
         'mac_address':
         n_utils.get_random_mac(MAC_BASE),
         'subnets': [{
             'ipv6_ra_mode': None,
             'cidr': str(subnet),
             'gateway_ip': str(subnet[1]),
             'id': subnet_id,
             'ipv6_address_mode': None
         }],
         'fixed_ips': [{
             'subnet_id': subnet_id,
             'prefixlen': 24,
             'ip_address': str(subnet[4])
         }]
     }
예제 #4
0
 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or utils.get_rand_name(),
                   ip_cidrs or ["%s/24" % TEST_IP],
                   mac_address or
                   net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or utils.get_rand_name())
예제 #5
0
 def _generate_private_interface_for_router(self, subnet):
     subnet_id = _uuid()
     return {
         'id': _uuid(),
         'admin_state_up': True,
         'network_id': _uuid(),
         'mtu': 1500,
         'mac_address': n_utils.get_random_mac(MAC_BASE),
         'subnets': [
             {
                 'ipv6_ra_mode': None,
                 'cidr': str(subnet),
                 'gateway_ip': str(subnet[1]),
                 'id': subnet_id,
                 'ipv6_address_mode': None
             }
         ],
         'fixed_ips': [
             {
                 'subnet_id': subnet_id,
                 'prefixlen': 24,
                 'ip_address': str(subnet[4])
             }
         ]
     }
예제 #6
0
 def generate_device_details(self, name=None, ip_cidrs=None,
                             mac_address=None, namespace=None):
     return Device(name or utils.get_rand_name(),
                   ip_cidrs or ["%s/24" % TEST_IP],
                   mac_address or
                   net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
                   namespace or utils.get_rand_name())
예제 #7
0
    def _setup_port_binding(self, **kwargs):
        with self.ctx.session.begin(subtransactions=True):
            mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
            port_id = uuidutils.generate_uuid()
            network_id = kwargs.get('network_id', TEST_NETWORK_ID)
            device_owner = kwargs.get('device_owner', '')
            device_id = kwargs.get('device_id', '')
            host = kwargs.get('host', helpers.HOST)

            self.ctx.session.add(models_v2.Port(
                id=port_id, network_id=network_id, mac_address=mac,
                admin_state_up=True, status=constants.PORT_STATUS_ACTIVE,
                device_id=device_id, device_owner=device_owner))

            port_binding_cls = models.PortBinding
            binding_kwarg = {'port_id': port_id,
                             'host': host,
                             'vif_type': portbindings.VIF_TYPE_UNBOUND,
                             'vnic_type': portbindings.VNIC_NORMAL}

            if device_owner == constants.DEVICE_OWNER_DVR_INTERFACE:
                port_binding_cls = models.DistributedPortBinding
                binding_kwarg['router_id'] = TEST_ROUTER_ID
                binding_kwarg['status'] = constants.PORT_STATUS_DOWN

            self.ctx.session.add(port_binding_cls(**binding_kwarg))

            if network_id == TEST_HA_NETWORK_ID:
                agent = self.get_l3_agent_by_host(host)
                l3_hamode.L3HARouterAgentPortBinding(
                    self.ctx, port_id=port_id, router_id=device_id,
                    l3_agent_id=agent['id'], state=kwargs.get(
                        'host_state', n_const.HA_ROUTER_STATE_ACTIVE)).create()
예제 #8
0
    def test_delete_neigh_entries(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"])
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        device = self.manage_device(attr)

        # trying to delete a non-existent entry shouldn't raise an error
        device.neigh.delete(TEST_IP_NEIGH, mac_address)
예제 #9
0
    def test_delete_neigh_entries(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]
        )
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        device = self.manage_device(attr)

        # trying to delete a non-existent entry shouldn't raise an error
        device.neigh.delete(TEST_IP_NEIGH, mac_address)
def convert_to_mac_if_none(data):
    """Convert to a random mac address if data is None

    :param data: The data value
    :return: Random mac address if data is None, else return data.
    """
    if data is None:
        return net_utils.get_random_mac(cfg.CONF.base_mac.split(':'))

    return data
def convert_to_mac_if_none(data):
    """Convert to a random mac address if data is None

    :param data: The data value
    :return: Random mac address if data is None, else return data.
    """
    if data is None:
        return net_utils.get_random_mac(cfg.CONF.base_mac.split(':'))

    return data
예제 #12
0
 def setUp(self):
     super(TrunkParentPortTestCase, self).setUp()
     trunk_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     self.trunk = trunk_manager.TrunkParentPort(trunk_id, port_id, port_mac)
     self.trunk.bridge = self.useFixture(
         net_helpers.OVSTrunkBridgeFixture(
             self.trunk.bridge.br_name)).bridge
     self.br_int = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
예제 #13
0
파일: tools.py 프로젝트: rcbops/neutron
def get_random_ip_address(version=4):
    if version == 4:
        ip_string = '10.%d.%d.%d' % (random.randint(
            3, 254), random.randint(3, 254), random.randint(3, 254))
        return netaddr.IPAddress(ip_string)
    else:
        ip = netutils.get_ipv6_addr_by_EUI64(
            '2001:db8::/64',
            net.get_random_mac(['fe', '16', '3e', '00', '00', '00']))
        return ip
예제 #14
0
 def setUp(self):
     super(TrunkParentPortTestCase, self).setUp()
     trunk_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     self.trunk = trunk_manager.TrunkParentPort(trunk_id, port_id, port_mac)
     self.trunk.bridge = self.useFixture(
         net_helpers.OVSTrunkBridgeFixture(
             self.trunk.bridge.br_name)).bridge
     self.br_int = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
예제 #15
0
 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': net.get_random_mac(
                 'fa:16:3e:00:00:00'.split(':')),
             'fixed_ips': [{
                 'ip_address': '10.%d.%d.%d' % (
                      random.randint(3, 254),
                      random.randint(3, 254),
                      random.randint(3, 254))}],
             'vif_name': utils.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
예제 #16
0
파일: base.py 프로젝트: eayunstack/neutron
 def _create_test_port_dict(self):
     return {'id': uuidutils.generate_uuid(),
             'mac_address': net.get_random_mac(
                 'fa:16:3e:00:00:00'.split(':')),
             'fixed_ips': [{
                 'ip_address': '10.%d.%d.%d' % (
                      random.randint(3, 254),
                      random.randint(3, 254),
                      random.randint(3, 254))}],
             'vif_name': utils.get_rand_name(
                 self.driver.DEV_NAME_LEN, self.driver.DEV_NAME_PREFIX)}
예제 #17
0
def get_random_ip_address(version=4):
    if version == 4:
        ip_string = '10.%d.%d.%d' % (random.randint(3, 254),
                                     random.randint(3, 254),
                                     random.randint(3, 254))
        return netaddr.IPAddress(ip_string)
    else:
        ip = netutils.get_ipv6_addr_by_EUI64(
            '2001:db8::/64',
            net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])
        )
        return ip
예제 #18
0
 def generate_router_info(self):
     self.info = copy.deepcopy(FAKE_ROUTER)
     self.info['id'] = _uuid()
     self.info['_interfaces'] = [
         self._generate_private_interface_for_router(subnet)
         for subnet in self.private_nets]
     self.info['gw_port']['id'] = _uuid()
     self.info['gw_port']['fixed_ips'][0]['ip_address'] = str(
         self.public_net)
     self.info['gw_port']['mac_address'] = (
         n_utils.get_random_mac(MAC_BASE))
     self.info['ha'] = False
예제 #19
0
    def _flush_neigh(self, version, ip_to_flush, ips_expected):
        attr = self.generate_device_details(
            ip_cidrs=['%s/24' % TEST_IP, 'fd00::1/64'],
            namespace=utils.get_rand_name(20, 'ns-'))
        device = self.manage_device(attr)
        for test_ip, nud_state in TEST_IP_NUD_STATES:
            mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
            device.neigh.add(test_ip, mac_address, nud_state)

        device.neigh.flush(version, ip_to_flush)
        ips = {e['dst'] for e in device.neigh.dump(version)}
        self.assertEqual(ips_expected, ips)
 def setUp(self):
     super(SubPortTestCase, self).setUp()
     trunk_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     trunk_bridge_name = utils.gen_trunk_br_name(trunk_id)
     trunk_bridge = self.useFixture(
         net_helpers.OVSTrunkBridgeFixture(trunk_bridge_name)).bridge
     segmentation_id = helpers.get_not_used_vlan(trunk_bridge, VLAN_RANGE)
     self.subport = trunk_manager.SubPort(trunk_id, port_id, port_mac,
                                          segmentation_id)
     self.subport.bridge = trunk_bridge
     self.br_int = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
예제 #21
0
 def generate_router_info(self):
     self.info = copy.deepcopy(FAKE_ROUTER)
     self.info['id'] = _uuid()
     self.info['project_id'] = _uuid()
     self.info['_interfaces'] = [
         self._generate_private_interface_for_router(subnet)
         for subnet in self.private_nets]
     self.info['gw_port']['id'] = _uuid()
     self.info['gw_port']['fixed_ips'][0]['ip_address'] = str(
         self.public_net)
     self.info['gw_port']['mac_address'] = (
         n_utils.get_random_mac(MAC_BASE))
     self.info['ha'] = False
예제 #22
0
    def test_plug_succeeds(self):
        device_name = utils.get_rand_name()
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self.assertFalse(self.bridge.get_port_name_list())
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=self.bridge.br_name,
                            namespace=namespace)
        self.assertIn(device_name, self.bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
예제 #23
0
 def _create_dvr_mac_address_retry(self, context, host, base_mac):
     with db_api.context_manager.writer.using(context):
         mac_address = net.get_random_mac(base_mac)
         dvr_mac_binding = dvr_models.DistributedVirtualRouterMacAddress(
             host=host, mac_address=mac_address)
         context.session.add(dvr_mac_binding)
         LOG.debug("Generated DVR mac for host %(host)s "
                   "is %(mac_address)s",
                   {'host': host, 'mac_address': mac_address})
     dvr_macs = self.get_dvr_mac_address_list(context)
     # TODO(vivek): improve scalability of this fanout by
     # sending a single mac address rather than the entire set
     self.notifier.dvr_mac_address_update(context, dvr_macs)
     return self._make_dvr_mac_address_dict(dvr_mac_binding)
예제 #24
0
 def _create_dvr_mac_address_retry(self, context, host, base_mac):
     with db_api.context_manager.writer.using(context):
         mac_address = net.get_random_mac(base_mac)
         dvr_mac_binding = dvr_models.DistributedVirtualRouterMacAddress(
             host=host, mac_address=mac_address)
         context.session.add(dvr_mac_binding)
         LOG.debug("Generated DVR mac for host %(host)s "
                   "is %(mac_address)s",
                   {'host': host, 'mac_address': mac_address})
     dvr_macs = self.get_dvr_mac_address_list(context)
     # TODO(vivek): improve scalability of this fanout by
     # sending a single mac address rather than the entire set
     self.notifier.dvr_mac_address_update(context, dvr_macs)
     return self._make_dvr_mac_address_dict(dvr_mac_binding)
예제 #25
0
 def setUp(self):
     super(SubPortTestCase, self).setUp()
     trunk_id = uuidutils.generate_uuid()
     port_id = uuidutils.generate_uuid()
     port_mac = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
     trunk_bridge_name = utils.gen_trunk_br_name(trunk_id)
     trunk_bridge = self.useFixture(
         net_helpers.OVSTrunkBridgeFixture(trunk_bridge_name)).bridge
     segmentation_id = helpers.get_not_used_vlan(
         trunk_bridge, VLAN_RANGE)
     self.subport = trunk_manager.SubPort(
         trunk_id, port_id, port_mac, segmentation_id)
     self.subport.bridge = trunk_bridge
     self.br_int = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
예제 #26
0
    def test_plug_succeeds(self):
        device_name = utils.get_rand_name()
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        self.assertFalse(self.bridge.get_port_name_list())
        self.interface.plug(network_id=uuidutils.generate_uuid(),
                            port_id=uuidutils.generate_uuid(),
                            device_name=device_name,
                            mac_address=mac_address,
                            bridge=self.bridge.br_name,
                            namespace=namespace)
        self.assertIn(device_name, self.bridge.get_port_name_list())
        self.assertTrue(ip_lib.device_exists(device_name, namespace))
예제 #27
0
    def _create_dvr_mac_address_retry(self, context, host, base_mac):
        with db_api.CONTEXT_WRITER.using(context):
            mac_address = net.get_random_mac(base_mac)
            dvr_mac_binding = router.DVRMacAddress(
                context, host=host, mac_address=netaddr.EUI(mac_address))
            dvr_mac_binding.create()
            LOG.debug("Generated DVR mac for host %(host)s "
                      "is %(mac_address)s",
                      {'host': host, 'mac_address': mac_address})

        dvr_macs = self.get_dvr_mac_address_list(context)
        # TODO(vivek): improve scalability of this fanout by
        # sending a single mac address rather than the entire set
        self.notifier.dvr_mac_address_update(context, dvr_macs)
        return self._make_dvr_mac_address_dict(dvr_mac_binding)
예제 #28
0
    def _create_dvr_mac_address_retry(self, context, host, base_mac):
        with db_api.CONTEXT_WRITER.using(context):
            mac_address = net.get_random_mac(base_mac)
            dvr_mac_binding = router.DVRMacAddress(
                context, host=host, mac_address=netaddr.EUI(mac_address))
            dvr_mac_binding.create()
            LOG.debug("Generated DVR mac for host %(host)s "
                      "is %(mac_address)s",
                      {'host': host, 'mac_address': mac_address})

        dvr_macs = self.get_dvr_mac_address_list(context)
        # TODO(vivek): improve scalability of this fanout by
        # sending a single mac address rather than the entire set
        self.notifier.dvr_mac_address_update(context, dvr_macs)
        return self._make_dvr_mac_address_dict(dvr_mac_binding)
예제 #29
0
 def test_arp_correct_protection_allowed_address_pairs(self):
     smac = self.source.port.link.address
     port = {'mac_address': '00:11:22:33:44:55',
             'allowed_address_pairs': [{'mac_address': smac,
                                        'ip_address': self.source.ip}]}
     # make sure a large number of allowed address pairs works
     for i in range(100000):
         port['allowed_address_pairs'].append(
             {'mac_address': net.get_random_mac(
                  'fa:16:3e:00:00:00'.split(':')),
              'ip_address': '10.10.10.10'})
     self._add_arp_protection(self.source, ['1.2.2.2'], port)
     self._add_arp_protection(self.destination, [self.destination.ip])
     arping(self.source.namespace, self.destination.ip)
     arping(self.destination.namespace, self.source.ip)
예제 #30
0
 def setUp(self):
     super(MACAddressFieldTest, self).setUp()
     self.field = common_types.MACAddressField()
     mac1 = tools.get_random_EUI()
     mac2 = tools.get_random_EUI()
     self.coerce_good_values = [(mac1, mac1), (mac2, mac2)]
     self.coerce_bad_values = [
         'XXXX', 'ypp', 'g3:vvv',
         # the field type is strict and does not allow to pass strings, even
         # if they represent a valid MAC address
         net.get_random_mac('fe:16:3e:00:00:00'.split(':')),
     ]
     self.to_primitive_values = ((a1, str(a2))
                                 for a1, a2 in self.coerce_good_values)
     self.from_primitive_values = ((a2, a1)
                                   for a1, a2 in self.to_primitive_values)
예제 #31
0
    def setUp(self):
        """Prepare resources.

        Set up trunk_dict representing incoming data from Neutron-server when
        fetching for trunk details. Another resource trunk_br represents the
        trunk bridge which its creation is simulated when creating a port in l2
        agent framework.
        """
        super(OVSDBHandlerTestCase, self).setUp()
        trunk_id = uuidutils.generate_uuid()
        self.trunk_dict = {
            'id': trunk_id,
            'mac_address': net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
            'sub_ports': []}
        self.trunk_port_name = generate_tap_device_name()
        self.trunk_br = trunk_manager.TrunkBridge(trunk_id)
        self.ovsdb_handler = self._prepare_mocked_ovsdb_handler()
예제 #32
0
    def setUp(self):
        """Prepare resources.

        Set up trunk_dict representing incoming data from Neutron-server when
        fetching for trunk details. Another resource trunk_br represents the
        trunk bridge which its creation is simulated when creating a port in l2
        agent framework.
        """
        super(OVSDBHandlerTestCase, self).setUp()
        trunk_id = uuidutils.generate_uuid()
        self.trunk_dict = {
            'id': trunk_id,
            'mac_address': net.get_random_mac('fa:16:3e:00:00:00'.split(':')),
            'sub_ports': []}
        self.trunk_port_name = generate_tap_device_name()
        self.trunk_br = trunk_manager.TrunkBridge(trunk_id)
        self.ovsdb_handler = self._prepare_mocked_ovsdb_handler()
예제 #33
0
    def test_get_neigh_entries(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]
        )
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        device = self.manage_device(attr)
        device.neigh.add(TEST_IP_NEIGH, mac_address)

        expected_neighs = [{'dst': TEST_IP_NEIGH,
                            'lladdr': mac_address,
                            'device': attr.name}]

        neighs = device.neigh.dump(4)
        self.assertItemsEqual(expected_neighs, neighs)
        self.assertIsInstance(neighs, list)

        device.neigh.delete(TEST_IP_NEIGH, mac_address)
        neighs = device.neigh.dump(4, dst=TEST_IP_NEIGH, lladdr=mac_address)
        self.assertEqual([], neighs)
예제 #34
0
    def test_crud(self):
        mac_addresses = ['FA:16:3E:00:00:01', 'FA:16:3E:00:00:02']

        for mac in mac_addresses:
            mac = netaddr.EUI(mac)
            self._add_row(id=uuidutils.generate_uuid(), mac=mac)
            obj = self._get_one(mac)
            self.assertEqual(mac, obj['mac'])
            random_mac = netaddr.EUI(net.get_random_mac(
                ['fe', '16', '3e', '00', '00', '00']))
            self._update_row(mac, random_mac)
            obj = self._get_one(random_mac)
            self.assertEqual(random_mac, obj['mac'])

        objs = self._get_all()
        self.assertEqual(len(mac_addresses), len(objs))
        self._delete_rows()
        objs = self._get_all()
        self.assertEqual(0, len(objs))
예제 #35
0
    def test_get_neigh_entries(self):
        attr = self.generate_device_details(
            ip_cidrs=["%s/24" % TEST_IP, "fd00::1/64"]
        )
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))
        device = self.manage_device(attr)
        device.neigh.add(TEST_IP_NEIGH, mac_address)

        expected_neighs = [{'dst': TEST_IP_NEIGH,
                            'lladdr': mac_address,
                            'device': attr.name}]

        neighs = device.neigh.dump(4)
        self.assertItemsEqual(expected_neighs, neighs)
        self.assertIsInstance(neighs, list)

        device.neigh.delete(TEST_IP_NEIGH, mac_address)
        neighs = device.neigh.dump(4, dst=TEST_IP_NEIGH, lladdr=mac_address)
        self.assertEqual([], neighs)
예제 #36
0
    def setUp(self):
        super(TestTaasPlugin, self).setUp()
        mock.patch.object(n_rpc, 'Connection', auto_spec=True).start()
        mock.patch.object(taas_agent_api, 'TaasAgentApi',
                          auto_spec=True).start()
        self.driver = mock.MagicMock()
        mock.patch('neutron.services.service_base.load_drivers',
                   return_value=({
                       'dummy_provider': self.driver
                   }, 'dummy_provider')).start()
        mock.patch('neutron.db.servicetype_db.ServiceTypeManager.get_instance',
                   return_value=mock.MagicMock()).start()
        self._plugin = taas_plugin.TaasPlugin()
        self._context = context.get_admin_context()

        self._project_id = self._tenant_id = 'tenant-X'
        self._network_id = uuidutils.generate_uuid()
        self._host_id = 'host-A'
        self._port_id = uuidutils.generate_uuid()
        self._port_details = {
            'tenant_id': self._tenant_id,
            'binding:host_id': self._host_id,
            'mac_address':
            n_utils.get_random_mac('fa:16:3e:00:00:00'.split(':')),
        }
        self._tap_service = {
            'tenant_id': self._tenant_id,
            'name': 'MyTap',
            'description': 'This is my tap service',
            'port_id': self._port_id,
            'project_id': self._project_id,
        }
        self.vlan_filter = "1-5,9,18,27-30,99-108,4000-4095"
        self._tap_flow = {
            'description': 'This is my tap flow',
            'direction': 'BOTH',
            'name': 'MyTapFlow',
            'source_port': self._port_id,
            'tenant_id': self._tenant_id,
            'project_id': self._project_id,
            'vlan_filter': self.vlan_filter,
        }
예제 #37
0
    def setUp(self):
        super(TestTaasPlugin, self).setUp()
        mock.patch.object(n_rpc, 'Connection', auto_spec=True).start()
        mock.patch.object(taas_agent_api,
                          'TaasAgentApi', auto_spec=True).start()
        self.driver = mock.MagicMock()
        mock.patch('neutron.services.service_base.load_drivers',
                   return_value=({'dummy_provider': self.driver},
                                 'dummy_provider')).start()
        mock.patch('neutron.db.servicetype_db.ServiceTypeManager.get_instance',
                   return_value=mock.MagicMock()).start()
        self._plugin = taas_plugin.TaasPlugin()
        self._context = context.get_admin_context()

        self._project_id = self._tenant_id = 'tenant-X'
        self._network_id = uuidutils.generate_uuid()
        self._host_id = 'host-A'
        self._port_id = uuidutils.generate_uuid()
        self._port_details = {
            'tenant_id': self._tenant_id,
            'binding:host_id': self._host_id,
            'mac_address': n_utils.get_random_mac(
                'fa:16:3e:00:00:00'.split(':')),
        }
        self._tap_service = {
            'tenant_id': self._tenant_id,
            'name': 'MyTap',
            'description': 'This is my tap service',
            'port_id': self._port_id,
            'project_id': self._project_id,
        }
        self.vlan_filter = "1-5,9,18,27-30,99-108,4000-4095"
        self._tap_flow = {
            'description': 'This is my tap flow',
            'direction': 'BOTH',
            'name': 'MyTapFlow',
            'source_port': self._port_id,
            'tenant_id': self._tenant_id,
            'project_id': self._project_id,
            'vlan_filter': self.vlan_filter,
        }
예제 #38
0
    def _test_mtu_set_after_action(self, device_name, br_name, namespace,
                                   action=None):
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))

        plug = functools.partial(
            self.interface.plug,
            network_id=uuidutils.generate_uuid(),
            port_id=uuidutils.generate_uuid(),
            device_name=device_name,
            mac_address=mac_address,
            bridge=self.bridge_name,
            namespace=namespace)
        plug(mtu=1500)
        self.assertTrue(ip_lib.device_exists(device_name, namespace))

        action = action or plug
        for mtu in (1450, 1500, 9000, 9000, 1450):
            action(mtu=mtu)
            self.assertEqual(
                mtu,
                ip_lib.IPDevice(device_name, namespace=namespace).link.mtu)
예제 #39
0
    def _test_mtu_set_after_action(self, device_name, br_name, namespace,
                                   action=None):
        mac_address = net.get_random_mac('fa:16:3e:00:00:00'.split(':'))

        plug = functools.partial(
            self.interface.plug,
            network_id=uuidutils.generate_uuid(),
            port_id=uuidutils.generate_uuid(),
            device_name=device_name,
            mac_address=mac_address,
            bridge=self.bridge_name,
            namespace=namespace)
        plug(mtu=1500)
        self.assertTrue(ip_lib.device_exists(device_name, namespace))

        action = action or plug
        for mtu in (1450, 1500, 9000, 9000, 1450):
            action(mtu=mtu)
            self.assertEqual(
                mtu,
                ip_lib.IPDevice(device_name, namespace=namespace).link.mtu)
예제 #40
0
    def test_5_octets_prefix_replaces_1_part(self, mock_rnd):
        mac = net.get_random_mac(['aa', 'bb', 'cc', 'dd', 'ee', '00'])

        self.assertEqual('aa:bb:cc:dd:ee:11', mac)

        mock_rnd.assert_called_with(0x00, 0xff)
예제 #41
0
def get_random_mac():
    """Generate a random mac address starting with fe:16:3e"""
    return net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])
예제 #42
0
    def test_no_prefix_replaces_all_parts(self, mock_rnd):
        mac = net.get_random_mac(['00', '00', '00', '00', '00', '00'])

        self.assertEqual('a2:a2:a2:a2:a2:a2', mac)

        mock_rnd.assert_called_with(0x00, 0xff)
예제 #43
0
파일: tools.py 프로젝트: rcbops/neutron
def get_random_mac():
    """Generate a random mac address starting with fe:16:3e"""
    return net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])
예제 #44
0
파일: tools.py 프로젝트: rcbops/neutron
def get_random_EUI():
    return netaddr.EUI(net.get_random_mac(['fe', '16', '3e', '00', '00',
                                           '00']))
예제 #45
0
def get_random_mac(base_mac):
    return net.get_random_mac(base_mac)
예제 #46
0
 def _generate_mac():
     return net.get_random_mac(cfg.CONF.base_mac.split(':'))
예제 #47
0
    def test_1_octets_prefix_replaces_5_parts(self, mock_rnd):
        mac = net.get_random_mac(['aa', '00', '00', '00', '00', '00'])

        self.assertEqual('aa:01:02:03:04:05', mac)

        mock_rnd.assert_called_with(0x00, 0xff)
예제 #48
0
def get_random_EUI():
    return netaddr.EUI(
        net.get_random_mac(['fe', '16', '3e', '00', '00', '00'])
    )
예제 #49
0
    def test_full_prefix_does_nothing(self):
        mac = net.get_random_mac(['aa', 'bb', 'cc', 'dd', 'ee', 'ff'])

        self.assertEqual('aa:bb:cc:dd:ee:ff', mac)
예제 #50
0
    def test_5_octets_prefix_replaces_1_part(self, mock_rnd):
        mac = net.get_random_mac(['aa', 'bb', 'cc', 'dd', 'ee', '00'])

        self.assertEqual('aa:bb:cc:dd:ee:11', mac)

        mock_rnd.assert_called_with(0x00, 0xff)
예제 #51
0
    def test_full_prefix_does_nothing(self):
        mac = net.get_random_mac(['aa', 'bb', 'cc', 'dd', 'ee', 'ff'])

        self.assertEqual('aa:bb:cc:dd:ee:ff', mac)
예제 #52
0
def get_random_mac(base_mac):
    return net.get_random_mac(base_mac)
예제 #53
0
    def test_1_octets_prefix_replaces_5_parts(self, mock_rnd):
        mac = net.get_random_mac(['aa', '00', '00', '00', '00', '00'])

        self.assertEqual('aa:01:02:03:04:05', mac)

        mock_rnd.assert_called_with(0x00, 0xff)
예제 #54
0
 def _generate_mac():
     return net.get_random_mac(cfg.CONF.base_mac.split(':'))
예제 #55
0
    def test_no_prefix_replaces_all_parts(self, mock_rnd):
        mac = net.get_random_mac(['00', '00', '00', '00', '00', '00'])

        self.assertEqual('a2:a2:a2:a2:a2:a2', mac)

        mock_rnd.assert_called_with(0x00, 0xff)