Пример #1
0
    def setUp(self):
        self._br = "t_up_br0"

        setup_dhcp_server = SCRIPT_PATH + "scripts/setup-test-dhcp-srv.sh"
        subprocess.check_call([setup_dhcp_server, "t0"])

        setup_uplink_br = [
            SCRIPT_PATH + "scripts/setup-uplink-br.sh",
            self._br,
            "t0uplink_p0",
            "t0_dhcp1",
        ]
        subprocess.check_call(setup_uplink_br)

        store = MobilityStore(fakeredis.FakeStrictRedis())
        ipv4_allocator = IPAllocatorDHCP(
            store,
            iface='t0uplink_p0',
            retry_limit=50,
        )
        ipv6_allocator = IPv6AllocatorPool(
            store,
            session_prefix_alloc_mode='RANDOM',
        )
        self._dhcp_allocator = IPAddressManager(
            ipv4_allocator,
            ipv6_allocator,
            store,
            recycling_interval=2,
        )
Пример #2
0
def _get_ipv4_allocator(store: MobilityStore, allocator_type: int,
                        static_ip_enabled: bool, multi_apn: bool,
                        dhcp_iface: str, dhcp_retry_limit: int,
                        subscriberdb_rpc_stub: SubscriberDBStub = None):
    # Read default GW, this is required for static IP allocation.
    store.dhcp_gw_info.read_default_gw()

    if allocator_type == mconfigs_pb2.MobilityD.IP_POOL:
        ip_allocator = IpAllocatorPool(store)
    elif allocator_type == mconfigs_pb2.MobilityD.DHCP:
        ip_allocator = IPAllocatorDHCP(store=store,
                                       iface=dhcp_iface,
                                       retry_limit=dhcp_retry_limit)
    else:
        raise ValueError(
            "Unknown IP allocator type: %s" % allocator_type)

    if static_ip_enabled:
        ip_allocator = IPAllocatorStaticWrapper(
            store=store, subscriberdb_rpc_stub=subscriberdb_rpc_stub,
            ip_allocator=ip_allocator)

    if multi_apn:
        ip_allocator = IPAllocatorMultiAPNWrapper(store=store,
                                                  subscriberdb_rpc_stub=subscriberdb_rpc_stub,
                                                  ip_allocator=ip_allocator)

    logging.info("Using allocator: %s static ip: %s multi_apn %s",
                 allocator_type,
                 static_ip_enabled,
                 multi_apn)
    return ip_allocator