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)
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
def _get_ipv6_allocator( store: MobilityStore, allocator_type: int, static_ip_enabled: bool, mconfig: any, ipv6_prefixlen: int, subscriberdb_rpc_stub: SubscriberDBStub = None, ): # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ip_allocator = IPv6AllocatorPool( store=store, session_prefix_alloc_mode=_get_value_or_default( mconfig.ipv6_prefix_allocation_type, DEFAULT_IPV6_PREFIX_ALLOC_MODE, ), ipv6_prefixlen=ipv6_prefixlen, ) if static_ip_enabled: ip_allocator = IPAllocatorStaticWrapper( store=store, subscriberdb_rpc_stub=subscriberdb_rpc_stub, ip_allocator=ip_allocator, ipv6=True, ) logging.info( "IPv6 allocator: %s static ip: %s ", allocator_type, static_ip_enabled, ) return ip_allocator
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)