Example #1
0
    def test_ip_network(self):
        network_1 = self.useFixture(
            ip_network.ExclusiveIPNetwork(
                '240.0.0.1', '240.255.255.254', '24')).network
        network_2 = self.useFixture(
            ip_network.ExclusiveIPNetwork(
                '240.0.0.1', '240.255.255.254', '24')).network

        self.assertIsInstance(network_1, netaddr.IPNetwork)
        self.assertEqual(network_1.cidr, network_1)
        self.assertNotEqual(network_1, network_2)
Example #2
0
 def _create_external_network_and_subnet(self, tenant_id):
     network = self.safe_client.create_network(
         tenant_id, name='public', external=True)
     cidr = self.useFixture(
         ip_network.ExclusiveIPNetwork(
             "240.0.0.0", "240.255.255.255", "24")).network
     subnet = self.safe_client.create_subnet(tenant_id, network['id'], cidr)
     return network, subnet
 def test_create_subnet_ipv4(self):
     cidr = self.useFixture(
         ip_network.ExclusiveIPNetwork(
             '240.0.0.0', '240.255.255.255', '24')).network
     subnet = self._create_subnet(self._project_id, self._network['id'],
                                  cidr)
     subnet = self._show_subnet(subnet['id'])
     self.assertEqual(subnet['subnet']['gateway_ip'],
                      str(netaddr.IPNetwork(cidr).network + 1))
 def test_create_subnet_ipv6_slaac(self):
     cidr = self.useFixture(
         ip_network.ExclusiveIPNetwork(
             '2001:db8::', '2001:db8::ffff', '64')).network
     subnet = self._create_subnet(self._project_id, self._network['id'],
                                  cidr, ipv6_address_mode='slaac',
                                  ipv6_ra_mode='slaac')
     subnet = self._show_subnet(subnet['id'])
     self.assertEqual(subnet['subnet']['gateway_ip'],
                      str(netaddr.IPNetwork(cidr).network))
Example #5
0
    def test_north_south_traffic(self):
        # This function creates an external network which is connected to
        # central_external_bridge and spawns an external_vm on it.
        # The external_vm is configured with the gateway_ip (both v4 & v6
        # addresses) of external subnet. Later, it creates a tenant router,
        # a tenant network and two tenant subnets (v4 and v6). The tenant
        # router is associated with tenant network and external network to
        # provide north-south connectivity to the VMs.
        # We validate the following in this testcase.
        # 1. SNAT support: using ping from tenant VM to external_vm
        # 2. Floating IP support: using ping from external_vm to VM floating ip
        # 3. IPv6 ext connectivity: using ping6 from tenant vm to external_vm.
        tenant_id = uuidutils.generate_uuid()
        ext_net, ext_sub = self._create_external_network_and_subnet(tenant_id)
        external_vm = self.useFixture(
            machine_fixtures.FakeMachine(
                self.environment.central_external_bridge,
                common_utils.ip_to_cidr(ext_sub['gateway_ip'], 24)))
        # Create an IPv6 subnet in the external network
        v6network = self.useFixture(
            ip_network.ExclusiveIPNetwork("2001:db8:1234::1",
                                          "2001:db8:1234::10", "64")).network
        ext_v6sub = self.safe_client.create_subnet(tenant_id, ext_net['id'],
                                                   v6network)

        router = self.safe_client.create_router(tenant_id,
                                                external_network=ext_net['id'])

        # Configure the gateway_ip of external v6subnet on the external_vm.
        external_vm.ipv6_cidr = common_utils.ip_to_cidr(
            ext_v6sub['gateway_ip'], 64)

        # Configure an IPv6 downstream route to the v6Address of router gw port
        for fixed_ip in router['external_gateway_info']['external_fixed_ips']:
            if netaddr.IPNetwork(fixed_ip['ip_address']).version == 6:
                external_vm.set_default_gateway(fixed_ip['ip_address'])

        vm = self._create_net_subnet_and_vm(
            tenant_id, ['20.0.0.0/24', '2001:db8:aaaa::/64'],
            self.environment.hosts[1], router)

        # ping external vm to test snat
        vm.block_until_ping(external_vm.ip)

        fip = self.safe_client.create_floatingip(tenant_id, ext_net['id'],
                                                 vm.ip, vm.neutron_port['id'])

        # ping floating ip from external vm
        external_vm.block_until_ping(fip['floating_ip_address'])

        # Verify VM is able to reach the router interface.
        vm.block_until_ping(vm.gateway_ipv6)
        # Verify north-south connectivity using ping6 to external_vm.
        vm.block_until_ping(external_vm.ipv6)
Example #6
0
 def _get_network_range(self):
     # NOTE(slaweq): We need to choose IP address on which rabbitmq will be
     # available because LinuxBridge agents are spawned in their own
     # namespaces and need to know where the rabbitmq server is listening.
     # For ovs agent it is not necessary because agents are spawned in
     # globalscope together with rabbitmq server so default localhost
     # address is fine for them
     for desc in self.hosts_desc:
         if desc.l2_agent_type == constants.AGENT_TYPE_LINUXBRIDGE:
             return self.useFixture(
                 ip_network.ExclusiveIPNetwork(
                     "240.0.0.0", "240.255.255.255", "24")).network
    def _get_network_range(self):
        # for bare MPLS all compute nodes must be in the same subnet
        if self.env_desc.ipvpn_encap == 'bare-mpls':
            self._dont_be_paranoid()
            return self.useFixture(
                ip_network.ExclusiveIPNetwork("240.0.0.0", "240.255.255.255",
                                              "24")).network

        r = super(BaGPipeEnvironment, self)._get_network_range()
        if r:
            self._dont_be_paranoid()
            return r
Example #8
0
    def setUp(self):
        super(TestRouterPortRebind, self).setUp()

        self.tenant_id = uuidutils.generate_uuid()
        self.ext_net = self.safe_client.create_network(self.tenant_id,
                                                       external=True)
        ext_cidr = self.useFixture(
            ip_network.ExclusiveIPNetwork("240.0.0.0", "240.255.255.255",
                                          "24")).network
        self.safe_client.create_subnet(self.tenant_id, self.ext_net['id'],
                                       ext_cidr)
        self.router = self.safe_client.create_router(
            self.tenant_id, external_network=self.ext_net['id'])
Example #9
0
    def test_create_subnet_ipv4_with_subnetpool(self):
        subnetpool_cidr = self.useFixture(
            ip_network.ExclusiveIPNetwork(
                '240.0.0.0', '240.255.255.255', '16')).network
        subnetpool = self._create_subnetpool(self._project_id, 8, 24, 24,
                                             [subnetpool_cidr])
        subnets = list(subnetpool_cidr.subnet(24))

        # Request from subnetpool.
        subnet = self._create_subnet(self._project_id, self._network['id'],
                                     subnetpool_id=subnetpool['id'],
                                     ip_version=4)
        subnet = self._show_subnet(subnet['id'])
        self.assertEqual(subnet['subnet']['cidr'], str(subnets[0].cidr))
        self.assertEqual(subnet['subnet']['gateway_ip'],
                         str(subnets[0].network + 1))

        # Request from subnetpool with gateway_ip.
        gateway_ip = subnets[1].ip + 10
        subnet = self._create_subnet(self._project_id, self._network['id'],
                                     subnetpool_id=subnetpool['id'],
                                     ip_version=4, gateway_ip=gateway_ip)
        subnet = self._show_subnet(subnet['id'])
        self.assertEqual(subnet['subnet']['cidr'], str(subnets[1].cidr))
        self.assertEqual(subnet['subnet']['gateway_ip'], str(gateway_ip))

        # Request from subnetpool with incorrect gateway_ip (cannot be the
        # network broadcast IP).
        gateway_ip = subnets[2].ip
        self.assertRaises(nclient_exceptions.Conflict,
                          self._create_subnet, self._project_id,
                          self._network['id'], subnetpool_id=subnetpool['id'],
                          ip_version=4, gateway_ip=gateway_ip)

        # Request from subnetpool using a correct gateway_ip from the same
        # CIDR; that means this subnet has not been allocated yet.
        gateway_ip += 1
        subnet = self._create_subnet(self._project_id, self._network['id'],
                                     subnetpool_id=subnetpool['id'],
                                     ip_version=4, gateway_ip=gateway_ip)
        subnet = self._show_subnet(subnet['id'])
        self.assertEqual(subnet['subnet']['cidr'], str(subnets[2].cidr))
        self.assertEqual(subnet['subnet']['gateway_ip'], str(gateway_ip))
Example #10
0
 def _create_external_subnet(self, tenant_id, network_id):
     cidr = self.useFixture(
         ip_network.ExclusiveIPNetwork("240.0.0.0", "240.255.255.255",
                                       "24")).network
     subnet = self.safe_client.create_subnet(tenant_id, network_id, cidr)
     return subnet
    def setUp(self):
        host_desc = [
            environment.HostDescription(
                l2_agent_type=constants.AGENT_TYPE_OVS,
                firewall_driver='openvswitch',
                # VM needs to receive the RA notification
                # from radvd which is handled by router and L3 agent.
                l3_agent=True,
                dhcp_agent=False) for _ in range(self.number_of_hosts)
        ]
        env_desc = environment.EnvironmentDescription(
            mech_drivers='openvswitch', enable_traditional_dhcp=False)
        env = environment.Environment(env_desc, host_desc)
        super(OvsDHCPExtensionTestCase, self).setUp(env)
        self.tenant_id = uuidutils.generate_uuid()

        network = self.safe_client.create_network(self.tenant_id,
                                                  name='public',
                                                  external=True)
        cidr = self.useFixture(
            ip_network.ExclusiveIPNetwork("240.0.0.0", "240.255.255.255",
                                          "24")).network
        self.safe_client.create_subnet(self.tenant_id, network['id'], cidr)

        router = self.safe_client.create_router(self.tenant_id,
                                                external_network=network['id'])

        self.network = self.safe_client.create_network(self.tenant_id,
                                                       'network-test')
        subnet_routes_v4 = [{
            "destination": "1.1.1.0/24",
            "nexthop": "10.0.0.100"
        }, {
            "destination": "2.2.2.2/32",
            "nexthop": "10.0.0.101"
        }]
        self.subnet_v4 = self.safe_client.create_subnet(
            self.tenant_id,
            self.network['id'],
            cidr='10.0.0.0/24',
            gateway_ip='10.0.0.1',
            name='subnet-v4-test',
            host_routes=subnet_routes_v4)

        router_interface_info = self.safe_client.add_router_interface(
            router['id'], self.subnet_v4['id'])
        self.block_until_port_status_active(router_interface_info['port_id'])

        subnet_routes_v6 = [{
            "destination": "2001:4860:4860::8888/128",
            "nexthop": "fda7:a5cc:3460:1::1"
        }, {
            "destination": "1234:5678:abcd::/64",
            "nexthop": "fda7:a5cc:3460:1::fff"
        }]
        self.subnet_v6 = self.safe_client.create_subnet(
            self.tenant_id,
            self.network['id'],
            cidr='fda7:a5cc:3460:1::/64',
            gateway_ip='fda7:a5cc:3460:1::1',
            enable_dhcp=True,
            ipv6_address_mode="dhcpv6-stateful",
            ipv6_ra_mode="dhcpv6-stateful",
            ip_version=6,
            name='subnet-v6-test',
            host_routes=subnet_routes_v6)

        # Need router radvd to send IPv6 address prefix to make the default
        # route work.
        router_interface_info = self.safe_client.add_router_interface(
            router['id'], self.subnet_v6['id'])
        self.block_until_port_status_active(router_interface_info['port_id'])