예제 #1
0
    def setUp(self):
        cfg.CONF.set_override('enable_distributed_routing',
                              True,
                              group='AGENT')
        super(OVSFlowTestCase, self).setUp()
        self.phys_br = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.br_phys = self.br_phys_cls(self.phys_br.br_name)
        self.br_phys.set_secure_mode()
        self.br_phys.setup_controllers(cfg.CONF)
        self.router_addr = '192.168.0.1/24'
        self.namespace = self.useFixture(
            net_helpers.NamespaceFixture()).name
        self.phys_p = self.useFixture(
            net_helpers.OVSPortFixture(self.br_phys, self.namespace)).port

        self.tun_br = self.useFixture(net_helpers.OVSBridgeFixture()).bridge
        self.br_tun = self.br_tun_cls(self.tun_br.br_name)
        self.br_tun.set_secure_mode()
        self.br_tun.setup_controllers(cfg.CONF)
        self.tun_p = self.br_tun.add_patch_port(
            common_utils.get_rand_device_name(
                prefix=cfg.CONF.OVS.tun_peer_patch_port),
            common_utils.get_rand_device_name(
                prefix=cfg.CONF.OVS.int_peer_patch_port))
        self.br_tun.setup_default_table(self.tun_p, True)
예제 #2
0
    def setUp(self):
        super(InNamespaceTest, self).setUp()
        self.namespace = self.useFixture(net_helpers.NamespaceFixture()).name

        ip = ip_lib.IPWrapper()
        root_dev_name = neutron_utils.get_rand_device_name()
        netns_dev_name = neutron_utils.get_rand_device_name()
        self.root_dev, self.netns_dev = ip.add_veth(
            root_dev_name, netns_dev_name, namespace2=self.namespace)
        self.addCleanup(self.root_dev.link.delete)
예제 #3
0
    def test_install_flood_to_tun(self):
        attrs = {
            'remote_ip': '192.0.2.1',  # RFC 5737 TEST-NET-1
            'local_ip': '198.51.100.1',  # RFC 5737 TEST-NET-2
        }
        kwargs = {'vlan': 777, 'tun_id': 888}
        port_name = common_utils.get_rand_device_name(net_helpers.PORT_PREFIX)
        ofport = self.br_tun.add_tunnel_port(port_name, attrs['remote_ip'],
                                             attrs['local_ip'])
        self.br_tun.install_flood_to_tun(ports=[ofport], **kwargs)
        test_packet = ("icmp,in_port=%d," % self.tun_p +
                       "dl_src=12:34:56:ab:cd:ef,dl_dst=12:34:56:78:cc:dd,"
                       "nw_src=192.168.0.1,nw_dst=192.168.0.2,nw_ecn=0,"
                       "nw_tos=0,nw_ttl=128,icmp_type=8,icmp_code=0,"
                       "dl_vlan=%(vlan)d,dl_vlan_pcp=0" % kwargs)
        trace = self._run_trace(self.tun_br.br_name, test_packet)
        self.assertTrue(("tun_id=0x%(tun_id)x" % kwargs) in
                        trace["Final flow"])
        self.assertTrue("vlan_tci=0x0000," in trace["Final flow"])

        self.br_tun.delete_flood_to_tun(kwargs['vlan'])

        trace = self._run_trace(self.tun_br.br_name, test_packet)
        self.assertEqual(" unchanged", trace["Final flow"])
        self.assertTrue("drop" in trace["Datapath actions"])
예제 #4
0
 def test_add_patch_port(self):
     local = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     peer = 'remotepeer'
     self.br.add_patch_port(local, peer)
     self.assertEqual(self.ovs.db_get_val('Interface', local, 'type'),
                      'patch')
     options = self.ovs.db_get_val('Interface', local, 'options')
     self.assertEqual(peer, options['peer'])
예제 #5
0
 def _test_add_tunnel_port(self, attrs):
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     self.br.add_tunnel_port(port_name, attrs['remote_ip'],
                             attrs['local_ip'])
     self.assertEqual('gre',
                      self.ovs.db_get_val('Interface', port_name, 'type'))
     options = self.ovs.db_get_val('Interface', port_name, 'options')
     for attr, val in attrs.items():
         self.assertEqual(val, options[attr])
예제 #6
0
 def test_add_tunnel_port_custom_port(self):
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     self.br.add_tunnel_port(
         port_name,
         self.get_test_net_address(1),
         self.get_test_net_address(2),
         tunnel_type=const.TYPE_VXLAN,
         vxlan_udp_port=12345)
     options = self.ovs.db_get_val('Interface', port_name, 'options')
     self.assertEqual("12345", options['dst_port'])
예제 #7
0
파일: checks.py 프로젝트: cubeek/neutron
def ovs_conntrack_supported():
    br_name = common_utils.get_rand_device_name(prefix="ovs-test-")

    with ovs_lib.OVSBridge(br_name) as br:
        try:
            br.add_protocols(*["OpenFlow%d" % i for i in range(10, 15)])
        except RuntimeError as e:
            LOG.debug("Exception while checking ovs conntrack support: %s", e)
            return False
    return ofctl_arg_supported(cmd='add-flow', ct_state='+trk', actions='drop')
예제 #8
0
def create_patch_ports(source, destination):
    """Hook up two OVS bridges.

    The result is two patch ports, each end connected to a bridge.
    The two patch port names will start with 'patch-', followed by identical
    four characters. For example patch-xyzw-fedora, and patch-xyzw-ubuntu,
    where fedora and ubuntu are random strings.

    :param source: Instance of OVSBridge
    :param destination: Instance of OVSBridge
    """
    common = common_utils.get_rand_name(max_length=4, prefix='')
    prefix = '%s-%s-' % (PATCH_PREFIX, common)

    source_name = common_utils.get_rand_device_name(prefix=prefix)
    destination_name = common_utils.get_rand_device_name(prefix=prefix)

    source.add_patch_port(source_name, destination_name)
    destination.add_patch_port(destination_name, source_name)
예제 #9
0
 def setUp(self):
     super(ImplIdlTestCase, self).setUp()
     self.config(group='OVS', ovsdb_interface='native')
     self.ovs = ovs_lib.BaseOVS()
     self.brname = utils.get_rand_device_name(net_helpers.BR_PREFIX)
     # Make sure exceptions pass through by calling do_post_commit directly
     mock.patch.object(
         impl_idl.NeutronOVSDBTransaction, "post_commit",
         side_effect=impl_idl.NeutronOVSDBTransaction.do_post_commit,
         autospec=True).start()
예제 #10
0
 def test_replace_port(self):
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     self.br.replace_port(port_name, ('type', 'internal'))
     self.assertTrue(self.br.port_exists(port_name))
     self.assertEqual('internal',
                      self.br.db_get_val('Interface', port_name, 'type'))
     self.br.replace_port(port_name, ('type', 'internal'),
                          ('external_ids', {'test': 'test'}))
     self.assertTrue(self.br.port_exists(port_name))
     self.assertEqual('test', self.br.db_get_val('Interface', port_name,
                                                 'external_ids')['test'])
예제 #11
0
파일: config.py 프로젝트: openstack/neutron
    def __init__(self, env_desc, host_desc, temp_dir, local_ip):
        super(SRIOVConfigFixture, self).__init__(
            env_desc, host_desc, temp_dir,
            base_filename='sriov_agent.ini')

        device1 = utils.get_rand_device_name(prefix='ens5')
        device2 = utils.get_rand_device_name(prefix='ens6')
        phys_dev_mapping = '%s:%s,%s:%s' % (PHYSICAL_NETWORK_NAME, device1,
                                            PHYSICAL_NETWORK_NAME, device2)
        rp_bandwidths = '%s:%s:%s,%s:%s:%s' % (device1,
                                               MINIMUM_BANDWIDTH_EGRESS_KBPS,
                                               MINIMUM_BANDWIDTH_INGRESS_KBPS,
                                               device2,
                                               MINIMUM_BANDWIDTH_EGRESS_KBPS,
                                               MINIMUM_BANDWIDTH_INGRESS_KBPS)
        self.config.update({
            'sriov_nic': {
                'physical_device_mappings': phys_dev_mapping,
                'resource_provider_bandwidths': rp_bandwidths,
            }
        })
예제 #12
0
 def test_add_tunnel_port_tos(self):
     attrs = {
         'remote_ip': self.get_test_net_address(1),
         'local_ip': self.get_test_net_address(2),
         'tos': 'inherit',
     }
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     self.br.add_tunnel_port(port_name, attrs['remote_ip'],
                             attrs['local_ip'], tos=attrs['tos'])
     self.assertEqual('gre',
                      self.ovs.db_get_val('Interface', port_name, 'type'))
     options = self.ovs.db_get_val('Interface', port_name, 'options')
     for attr, val in attrs.items():
         self.assertEqual(val, options[attr])
    def _add_new_bridge_and_restart_agent(self, host):
        l2_agent = host.l2_agent
        l2_agent_config = l2_agent.agent_cfg_fixture.config

        if 'ovs' in host.agents:
            new_dev = utils.get_rand_device_name(prefix='br-new')
            self._change_agent_conf_and_restart_agent(
                l2_agent_config['ovs'], l2_agent, self.BR_MAPPINGS, new_dev)
            physnets = self._get_physnet_names_from_mapping(
                l2_agent_config['ovs'][self.BR_MAPPINGS])
            br_phys_new = host.useFixture(
                net_helpers.OVSBridgeFixture(new_dev)).bridge
            host.connect_to_central_network_via_vlans(br_phys_new)
        elif 'sriov' in host.agents:
            new_dev = utils.get_rand_device_name(prefix='ens7')
            self._change_agent_conf_and_restart_agent(
                l2_agent_config['sriov_nic'], l2_agent,
                'physical_device_mappings', new_dev)
            physnets = self._get_physnet_names_from_mapping(
                l2_agent_config['sriov_nic']['physical_device_mappings'])

        l2_agent.restart()
        return physnets
예제 #14
0
파일: config.py 프로젝트: openstack/neutron
    def __init__(self, env_desc, host_desc, temp_dir, local_ip, **kwargs):
        super(OVSConfigFixture, self).__init__(
            env_desc, host_desc, temp_dir,
            base_filename='openvswitch_agent.ini')

        self.tunneling_enabled = self.env_desc.tunneling_enabled
        ext_dev = utils.get_rand_device_name(prefix='br-eth')
        self.config.update({
            'ovs': {
                'local_ip': local_ip,
                'integration_bridge': self._generate_integration_bridge(),
                'of_interface': host_desc.of_interface,
                'bridge_mappings': '%s:%s' % (PHYSICAL_NETWORK_NAME, ext_dev)
            },
            'securitygroup': {
                'firewall_driver': host_desc.firewall_driver,
            },
            'agent': {
                'l2_population': str(self.env_desc.l2_pop),
                'arp_responder': str(self.env_desc.arp_responder),
                'debug_iptables_rules': str(env_desc.debug_iptables)
            }
        })

        if self.tunneling_enabled:
            self.config['agent'].update({
                'tunnel_types': self.env_desc.network_type})
            self.config['ovs'].update({
                'tunnel_bridge': self._generate_tunnel_bridge(),
                'int_peer_patch_port': self._generate_int_peer(),
                'tun_peer_patch_port': self._generate_tun_peer()})
        else:
            if env_desc.report_bandwidths:
                self.config['ovs'][constants.RP_BANDWIDTHS] = \
                    '%s:%s:%s' % (ext_dev, MINIMUM_BANDWIDTH_EGRESS_KBPS,
                                  MINIMUM_BANDWIDTH_INGRESS_KBPS)

        if env_desc.qos:
            self.config['agent']['extensions'] = 'qos'
        if env_desc.log:
            self.config['agent']['extensions'] = 'log'
            test_name = kwargs.get("test_name")
            test_name = base.sanitize_log_path(test_name)
            self.config.update({
                'network_log': {
                    'local_output_log_base':
                        self._generate_temp_log_file(test_name)}
            })
예제 #15
0
파일: checks.py 프로젝트: coreycb/neutron
def ofctl_arg_supported(cmd, **kwargs):
    """Verify if ovs-ofctl binary supports cmd with **kwargs.

    :param cmd: ovs-ofctl command to use for test.
    :param **kwargs: arguments to test with the command.
    :returns: a boolean if the supplied arguments are supported.
    """
    br_name = common_utils.get_rand_device_name(prefix="br-test-")
    with ovs_lib.OVSBridge(br_name) as test_br:
        full_args = ["ovs-ofctl", cmd, test_br.br_name, ovs_lib._build_flow_expr_str(kwargs, cmd.split("-")[0])]
        try:
            agent_utils.execute(full_args, run_as_root=True)
        except RuntimeError as e:
            LOG.debug("Exception while checking supported feature via " "command %s. Exception: %s", full_args, e)
            return False
        except Exception:
            LOG.exception(_LE("Unexpected exception while checking supported" " feature via command: %s"), full_args)
            return False
        else:
            return True
예제 #16
0
 def _generate_bridge_mappings(self):
     return '%s:%s' % (PHYSICAL_NETWORK_NAME,
                       utils.get_rand_device_name(prefix='br-eth'))
예제 #17
0
 def _generate_bridge_mappings(self):
     return '%s:%s' % (PHYSICAL_NETWORK_NAME,
                       utils.get_rand_device_name(prefix='br-eth'))
예제 #18
0
 def _generate_tun_peer(self):
     return utils.get_rand_device_name(prefix='patch-int')
예제 #19
0
 def _generate_tun_peer(self):
     return utils.get_rand_device_name(prefix='patch-int')
예제 #20
0
 def _generate_integration_bridge(self):
     return utils.get_rand_device_name(prefix='br-int')
예제 #21
0
파일: checks.py 프로젝트: zl2017/neutron
def ovs_geneve_supported(from_ip='192.0.2.3', to_ip='192.0.2.4'):
    name = common_utils.get_rand_device_name(prefix='genevetest-')
    with ovs_lib.OVSBridge(name) as br:
        port = br.add_tunnel_port(from_ip, to_ip, const.TYPE_GENEVE)
        return port != ovs_lib.INVALID_OFPORT
예제 #22
0
파일: checks.py 프로젝트: cubeek/neutron
def ovs_geneve_supported(from_ip='192.0.2.3', to_ip='192.0.2.4'):
    name = common_utils.get_rand_device_name(prefix='genevetest-')
    with ovs_lib.OVSBridge(name) as br:
        port = br.add_tunnel_port(from_ip, to_ip, n_consts.TYPE_GENEVE)
        return port != ovs_lib.INVALID_OFPORT
예제 #23
0
 def create_ovs_port(self, *interface_attrs):
     # Convert ((a, b), (c, d)) to {a: b, c: d} and add 'type' by default
     attrs = collections.OrderedDict(interface_attrs)
     attrs.setdefault('type', 'internal')
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     return (port_name, self.br.add_port(port_name, *attrs.items()))
예제 #24
0
 def get_veth_name(name):
     if name.startswith(VETH0_PREFIX):
         return common_utils.get_rand_device_name(VETH0_PREFIX)
     if name.startswith(VETH1_PREFIX):
         return common_utils.get_rand_device_name(VETH1_PREFIX)
     return name
예제 #25
0
 def _generate_integration_bridge(self):
     return utils.get_rand_device_name(prefix='br-int')
예제 #26
0
 def _generate_tunnel_bridge(self):
     return utils.get_rand_device_name(prefix='br-tun')
예제 #27
0
 def _generate_bridge_mappings(self):
     return 'physnet1:%s' % utils.get_rand_device_name(prefix='br-eth')
예제 #28
0
def iproute2_vxlan_supported():
    ip = ip_lib.IPWrapper()
    name = common_utils.get_rand_device_name(prefix='vxlantest-')
    port = ip.add_vxlan(name, 3000)
    ip.del_veth(name)
    return name == port.name
예제 #29
0
 def _generate_tunnel_bridge(self):
     return utils.get_rand_device_name(prefix='br-tun')
예제 #30
0
 def get_veth_name(name):
     if name.startswith(VETH0_PREFIX):
         return common_utils.get_rand_device_name(VETH0_PREFIX)
     if name.startswith(VETH1_PREFIX):
         return common_utils.get_rand_device_name(VETH1_PREFIX)
     return name
예제 #31
0
 def _generate_external_bridge(self):
     return utils.get_rand_device_name(prefix='br-ex')
예제 #32
0
 def _generate_external_bridge(self):
     return utils.get_rand_device_name(prefix='br-ex')
예제 #33
0
파일: checks.py 프로젝트: cubeek/neutron
def ovs_vxlan_supported(from_ip='192.0.2.1', to_ip='192.0.2.2'):
    name = common_utils.get_rand_device_name(prefix='vxlantest-')
    with ovs_lib.OVSBridge(name) as br:
        port = br.add_tunnel_port(from_ip, to_ip, n_consts.TYPE_VXLAN)
        return port != ovs_lib.INVALID_OFPORT
예제 #34
0
 def create_ovs_port(self, *interface_attrs):
     # Convert ((a, b), (c, d)) to {a: b, c: d} and add 'type' by default
     attrs = collections.OrderedDict(interface_attrs)
     attrs.setdefault('type', 'internal')
     port_name = utils.get_rand_device_name(net_helpers.PORT_PREFIX)
     return (port_name, self.br.add_port(port_name, *attrs.items()))
예제 #35
0
파일: checks.py 프로젝트: cubeek/neutron
def iproute2_vxlan_supported():
    ip = ip_lib.IPWrapper()
    name = common_utils.get_rand_device_name(prefix='vxlantest-')
    port = ip.add_vxlan(name, 3000)
    ip.del_veth(name)
    return name == port.name
예제 #36
0
파일: checks.py 프로젝트: zl2017/neutron
def ovs_vxlan_supported(from_ip='192.0.2.1', to_ip='192.0.2.2'):
    name = common_utils.get_rand_device_name(prefix='vxlantest-')
    with ovs_lib.OVSBridge(name) as br:
        port = br.add_tunnel_port(from_ip, to_ip, const.TYPE_VXLAN)
        return port != ovs_lib.INVALID_OFPORT