Beispiel #1
0
    def test_change_ap_vpn_no_clash(self):
        """ attaches a user AS with VPN from one AP to another AP, checks port clashes """
        seed = 6
        ap1 = AS.objects.get(as_id=testtopo_vpns_as_ids[0])
        ap2 = AS.objects.get(as_id=testtopo_vpns_as_ids[1])

        # create two user ases:
        user_as1, att_confs1 = create_and_check_random_useras(
            self, seed + 1, [ap1.as_id], VPNChoice.ALL)
        user_as2, _ = create_and_check_random_useras(self, seed + 2,
                                                     [ap2.as_id],
                                                     VPNChoice.ALL)

        # ensure that we use the same public port on the server side:
        ap_public_port = 55555
        # unlikely to already be in use, check anyway (testing the test):
        assert ap_public_port not in value_set(ap1.hosts.get().interfaces,
                                               'public_port')
        assert ap_public_port not in value_set(ap2.hosts.get().interfaces,
                                               'public_port')
        # now set the public port on AP side for both user-AS - AP links.
        user_as1.interfaces.get().remote_interface().update(
            public_port=ap_public_port)
        user_as2.interfaces.get().remote_interface().update(
            public_port=ap_public_port)

        # switch user_as1 from AP1 to AP2 and check the correctness of the topology,
        # in particular, the ports must not clash.
        att_confs1[0].attachment_point = ap2.attachment_point_info
        att_confs1[0].link.refresh_from_db()
        update_useras(self, user_as1, att_confs1)
Beispiel #2
0
 def _find_client_ip(self):
     used_ips = {self.server_vpn_ip} | value_set(VPNClient.objects.filter(vpn=self), 'ip')
     subnet = ipaddress.ip_network(self.subnet)
     for ip in subnet.hosts():
         if str(ip) not in used_ips:
             return ip
     raise RuntimeError('No free client IP available')
Beispiel #3
0
 def _find_vpn_subnet(self):
     """
     Find the next free IP subnet in form 10.10.x.0/24
     """
     existing_vpns = value_set(VPN.objects.all(), 'subnet')
     return find_free_subnet(ipaddress.ip_network('10.10.0.0/16'), 24,
                             existing_vpns)
Beispiel #4
0
 def find_public_port(self):
     """
     Find an unused public port for an AS interface on this Host
     """
     used_ports = value_set(self.interfaces, 'public_port')
     for candidate_port in range(DEFAULT_PUBLIC_PORT, MAX_PORT):
         if candidate_port not in used_ports:
             return candidate_port
Beispiel #5
0
 def find_interface_id(self):
     """
     Find an unused interface id
     """
     existing_ids = value_set(self.interfaces, 'interface_id')
     for candidate_id in range(1, MAX_INTERFACE_ID):
         if candidate_id not in existing_ids:
             return candidate_id
     raise RuntimeError('Interface IDs exhausted')