Esempio n. 1
0
 def _get_of_port(self, port_id):
     ovsdb = utils.OvsDBParser()
     interfaces = ovsdb.list_interfaces()
     for item in interfaces:
         external_ids = item.get('external_ids')
         if external_ids is not None:
             iface_id = external_ids.get('iface-id')
             if iface_id == port_id:
                 return item.get('ofport')
     return None
Esempio n. 2
0
    def test_remote_port(self):
        if cfg.CONF.core_plugin == DF_PLUGIN:
            return

        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'network1'})
        self.assertTrue(network.exists())

        subnet_info = {
            'network_id': network_id,
            'cidr': '192.168.150.0/24',
            'gateway_ip': '192.168.150.1',
            'ip_version': 4,
            'name': 'subnet1',
            'enable_dhcp': True
        }
        subnet = self.store(
            objects.SubnetTestObj(self.neutron,
                                  self.nb_api,
                                  network_id=network_id))
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        port = self.store(
            objects.PortTestObj(self.neutron, self.nb_api, network_id))
        port_body = {
            'admin_state_up': True,
            'name': 'port1',
            'network_id': network_id,
            'binding:profile': {
                'port_key': 'remote_port',
                'host_ip': '10.10.10.10'
            }
        }
        port.create(port=port_body)
        self.assertTrue(port.exists())

        ovsdb = utils.OvsDBParser()
        utils.wait_until_true(
            lambda: self._get_wanted_tunnel_port(ovsdb, '10.10.10.10'),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=2,
            exception=Exception('Could not get wanted tunnel port'))

        port.close()
        self.assertFalse(port.exists())

        utils.wait_until_none(
            lambda: ovsdb.get_tunnel_ofport('10.10.10.10'),
            timeout=const.DEFAULT_RESOURCE_READY_TIMEOUT,
            sleep=2,
            exception=Exception('Could not delete wanted tunnel port'))

        subnet.close()
        network.close()
    def test_anti_spoof_flows(self):

        network = self.store(objects.NetworkTestObj(self.neutron, self.nb_api))
        network_id = network.create(network={'name': 'test_network1'})
        self.assertTrue(network.exists())

        subnet_info = {'network_id': network_id,
                       'cidr': '192.168.130.0/24',
                       'gateway_ip': '192.168.130.1',
                       'ip_version': 4,
                       'name': 'test_subnet1',
                       'enable_dhcp': True}
        subnet = self.store(objects.SubnetTestObj(self.neutron,
                                                  self.nb_api,
                                                  network_id=network_id))
        subnet.create(subnet_info)
        self.assertTrue(subnet.exists())

        vm = self.store(objects.VMTestObj(self, self.neutron))
        vm.create(network=network)

        addresses = vm.server.addresses['test_network1']
        self.assertIsNotNone(addresses)
        ip = addresses[0]['addr']
        self.assertIsNotNone(ip)
        mac = addresses[0]['OS-EXT-IPS-MAC:mac_addr']
        self.assertIsNotNone(mac)
        port = utils.wait_until_is_and_return(
            lambda: self._get_vm_port(ip, mac),
            exception=Exception('No port assigned to VM')
        )

        ovsdb = utils.OvsDBParser()
        of_port = ovsdb.get_ofport(port.get_id())
        self.assertIsNotNone(of_port)

        # Check if the associating flows were installed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, of_port
        )
        self._check_all_flows_existed(expected_flow_list)

        vm.server.stop()
        vm.close()

        time.sleep(utils.DEFAULT_CMD_TIMEOUT)

        # Check if the associating flows were removed.
        expected_flow_list = self._get_anti_spoof_expected_flows(
            ip, mac, of_port
        )
        self._check_not_flow_existed(expected_flow_list)
Esempio n. 4
0
 def _get_of_port(self, port_id):
     ovsdb = utils.OvsDBParser()
     return ovsdb.get_ofport(port_id)