Esempio n. 1
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
Esempio n. 2
0
 def _new_ip_allocator(self, recycling_interval):
     """
     Creates and sets up an IPAllocator with the given recycling interval.
     """
     store = MobilityStore(fakeredis.FakeStrictRedis())
     ip_allocator = IpAllocatorPool(store)
     ip_allocator_static = IPAllocatorStaticWrapper(
         store,
         MockedSubscriberDBStub(),
         ip_allocator,
     )
     ipv4_allocator = IPAllocatorMultiAPNWrapper(
         store,
         subscriberdb_rpc_stub=MockedSubscriberDBStub(),
         ip_allocator=ip_allocator_static,
     )
     ipv6_allocator = IPv6AllocatorPool(
         store,
         session_prefix_alloc_mode='RANDOM',
     )
     self._allocator = IPAddressManager(
         ipv4_allocator,
         ipv6_allocator,
         store,
         recycling_interval,
     )
     self._allocator.add_ip_block(self._block)
Esempio n. 3
0
 def _new_ip_allocator(self, recycling_interval):
     """
     Creates and sets up an IPAllocator with the given recycling interval.
     """
     store = MobilityStore(get_default_client(), False, 3980)
     store.dhcp_gw_info.read_default_gw()
     ip_allocator = IpAllocatorPool(store)
     ipv6_allocator = IPv6AllocatorPool(store,
                                        session_prefix_alloc_mode='RANDOM')
     self._allocator = IPAddressManager(ip_allocator, ipv6_allocator, store,
                                        recycling_interval)
     self._allocator.add_ip_block(self._block)
Esempio n. 4
0
    def setUp(self):
        # Bind the rpc server to a free port
        thread_pool = futures.ThreadPoolExecutor(max_workers=10)
        self._rpc_server = grpc.server(thread_pool)
        port = self._rpc_server.add_insecure_port('0.0.0.0:0')

        store = MobilityStore(get_default_client(), False, 3980)
        store.dhcp_gw_info.read_default_gw()
        ip_allocator = IpAllocatorPool(store)
        ipv6_allocator = IPv6AllocatorPool(
            store,
            session_prefix_alloc_mode='RANDOM',
        )
        self._allocator = IPAddressManager(
            ip_allocator,
            ipv6_allocator,
            store,
        )

        # Add the servicer
        self._servicer = MobilityServiceRpcServicer(self._allocator, False)
        self._servicer.add_to_server(self._rpc_server)
        self._rpc_server.start()

        # Create a rpc stub
        channel = grpc.insecure_channel('0.0.0.0:{}'.format(port))
        self._stub = MobilityServiceStub(channel)

        # variables shared across tests
        self._netaddr = '192.168.0.0'
        self._prefix_len = 28
        ip_bytes = bytes(map(int, self._netaddr.split('.')))
        self._block_msg = IPBlock(
            version=IPBlock.IPV4,
            net_address=ip_bytes,
            prefix_len=self._prefix_len,
        )
        self._ipv6_block = ipaddress.ip_network('fdee:5:6c::/48')
        self._ipv6_netaddr = self._ipv6_block.network_address.packed
        self._ipv6_block_msg = IPBlock(
            version=IPBlock.IPV6,
            net_address=self._ipv6_netaddr,
            prefix_len=self._ipv6_block.prefixlen,
        )
        self._block = ipaddress.ip_network(
            "%s/%s" % (self._netaddr, self._prefix_len),
        )
        self._sid0 = SIDUtils.to_pb('IMSI0')
        self._sid1 = SIDUtils.to_pb('IMSI1')
        self._sid2 = SIDUtils.to_pb('IMSI2')
        self._apn0 = 'Internet'
        self._apn1 = 'IMS'
Esempio n. 5
0
    def _new_ip_allocator(self, recycling_interval):
        """
        Creates and sets up an IPAllocator with the given recycling interval.
        """

        store = MobilityStore(get_default_client(), False, 3980)
        ip_allocator = IpAllocatorPool(store)
        ipv4_allocator = IPAllocatorStaticWrapper(
            store,
            subscriberdb_rpc_stub=MockedSubscriberDBStub(),
            ip_allocator=ip_allocator)
        ipv6_allocator = IPv6AllocatorPool(store,
                                           session_prefix_alloc_mode='RANDOM')
        self._allocator = IPAddressManager(ipv4_allocator, ipv6_allocator,
                                           store, recycling_interval)
        self._allocator.add_ip_block(self._block)
Esempio n. 6
0
 def _new_ip_allocator(self, recycling_interval):
     """
     Creates and sets up an IPAllocator with the given recycling interval.
     """
     store = MobilityStore(fakeredis.FakeStrictRedis())
     store.dhcp_gw_info.read_default_gw()
     ip_allocator = IpAllocatorPool(store)
     ipv6_allocator = IPv6AllocatorPool(
         store,
         session_prefix_alloc_mode='RANDOM',
     )
     self._allocator = IPAddressManager(
         ip_allocator,
         ipv6_allocator,
         store,
         recycling_interval,
     )
     self._allocator.add_ip_block(self._block)