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, )
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 _new_ip_allocator(self, block): """ Creates and sets up an IPAllocator with the given IPv6 block. """ store = MobilityStore(fakeredis.FakeStrictRedis(), False, 3980) allocator = IPv6AllocatorPool(store, 'RANDOM') allocator.add_ip_block(block) return allocator
def _new_ip_allocator(self, block): """ Creates and sets up an IPAllocator with the given IPv6 block. """ store = MobilityStore(get_default_client(), False, 3980) allocator = IPv6AllocatorPool(store, 'RANDOM') allocator.add_ip_block(block) return 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) 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)
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'
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)
def main(): """ main() for MobilityD """ service = MagmaService('mobilityd', mconfigs_pb2.MobilityD()) # Load service configs and mconfig config = service.config mconfig = service.mconfig multi_apn = config.get('multi_apn', mconfig.multi_apn_ip_alloc) static_ip_enabled = config.get('static_ip', mconfig.static_ip_enabled) allocator_type = mconfig.ip_allocator_type dhcp_iface = config.get('dhcp_iface', 'dhcp0') dhcp_retry_limit = config.get('retry_limit', 300) # TODO: consider adding gateway mconfig to decide whether to # persist to Redis client = get_default_client() store = MobilityStore(client, config.get('persist_to_redis', False), config.get('redis_port', 6380)) chan = ServiceRegistry.get_rpc_channel('subscriberdb', ServiceRegistry.LOCAL) ipv4_allocator = _get_ipv4_allocator(store, allocator_type, static_ip_enabled, multi_apn, dhcp_iface, dhcp_retry_limit, SubscriberDBStub(chan)) # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ipv6_allocation_type = config['ipv6_ip_allocator_type'] ipv6_allocator = IPv6AllocatorPool( store=store, session_prefix_alloc_mode=ipv6_allocation_type) # Load IPAddressManager ip_address_man = IPAddressManager(ipv4_allocator, ipv6_allocator, store) # Add all servicers to the server mobility_service_servicer = MobilityServiceRpcServicer( ip_address_man, mconfig.ip_block, config.get('ipv6_prefix_block')) mobility_service_servicer.add_to_server(service.rpc_server) # Run the service loop service.run() # Cleanup the service service.close()
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)
def main(): """ main() for MobilityD """ service = MagmaService('mobilityd', mconfigs_pb2.MobilityD()) # Load service configs and mconfig config = service.config mconfig = service.mconfig multi_apn = config.get('multi_apn', mconfig.multi_apn_ip_alloc) static_ip_enabled = config.get('static_ip', mconfig.static_ip_enabled) allocator_type = mconfig.ip_allocator_type dhcp_iface = config.get('dhcp_iface', 'dhcp0') dhcp_retry_limit = config.get('retry_limit', 300) # TODO: consider adding gateway mconfig to decide whether to # persist to Redis client = get_default_client() store = MobilityStore(client, config.get('persist_to_redis', False), config.get('redis_port', 6380)) chan = ServiceRegistry.get_rpc_channel('subscriberdb', ServiceRegistry.LOCAL) ipv4_allocator = _get_ipv4_allocator(store, allocator_type, static_ip_enabled, multi_apn, dhcp_iface, dhcp_retry_limit, SubscriberDBStub(chan)) # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ipv6_prefix_allocation_type = mconfig.ipv6_prefix_allocation_type or \ DEFAULT_IPV6_PREFIX_ALLOC_MODE ipv6_allocator = IPv6AllocatorPool( store=store, session_prefix_alloc_mode=ipv6_prefix_allocation_type) # Load IPAddressManager ip_address_man = IPAddressManager(ipv4_allocator, ipv6_allocator, store) # Add all servicers to the server mobility_service_servicer = MobilityServiceRpcServicer( ip_address_man, config.get('print_grpc_payload', False)) mobility_service_servicer.add_to_server(service.rpc_server) # Load IPv4 and IPv6 blocks from the configurable mconfig file # No dynamic reloading support for now, assume restart after updates logging.info('Adding IPv4 block') ipv4_block = _get_ip_block(mconfig.ip_block) if ipv4_block is not None: try: mobility_service_servicer.add_ip_block(ipv4_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv4 block: %s", ipv4_block) logging.info('Adding IPv6 block') ipv6_block = _get_ip_block(mconfig.ipv6_block) if ipv6_block is not None: try: mobility_service_servicer.add_ip_block(ipv6_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv6 block: %s", ipv6_block) # Run the service loop service.run() # Cleanup the service service.close()
def main(): """Start mobilityd""" service = MagmaService('mobilityd', mconfigs_pb2.MobilityD()) # Optionally pipe errors to Sentry sentry_init(service_name=service.name) # Load service configs and mconfig config = service.config mconfig = service.mconfig multi_apn = config.get('multi_apn', mconfig.multi_apn_ip_alloc) static_ip_enabled = config.get('static_ip', mconfig.static_ip_enabled) allocator_type = mconfig.ip_allocator_type dhcp_iface = config.get('dhcp_iface', 'dhcp0') dhcp_retry_limit = config.get('retry_limit', RETRY_LIMIT) # TODO: consider adding gateway mconfig to decide whether to # persist to Redis client = get_default_client() store = MobilityStore( client, config.get('persist_to_redis', False), config.get('redis_port', DEFAULT_REDIS_PORT), ) chan = ServiceRegistry.get_rpc_channel( 'subscriberdb', ServiceRegistry.LOCAL, ) ipv4_allocator = _get_ipv4_allocator( store, allocator_type, static_ip_enabled, multi_apn, dhcp_iface, dhcp_retry_limit, SubscriberDBStub(chan), ) # Init IPv6 allocator, for now only IP_POOL mode is supported for IPv6 ipv6_allocator = IPv6AllocatorPool( store=store, session_prefix_alloc_mode=_get_value_or_default( mconfig.ipv6_prefix_allocation_type, DEFAULT_IPV6_PREFIX_ALLOC_MODE, ), ) # Load IPAddressManager ip_address_man = IPAddressManager(ipv4_allocator, ipv6_allocator, store) # Load IPv4 and IPv6 blocks from the configurable mconfig file # No dynamic reloading support for now, assume restart after updates ipv4_block = _get_ip_block(mconfig.ip_block, "IPv4") if ipv4_block is not None: logging.info('Adding IPv4 block') try: allocated_ip_blocks = ip_address_man.list_added_ip_blocks() if ipv4_block not in allocated_ip_blocks: # Cleanup previously allocated IP blocks ip_address_man.remove_ip_blocks(*allocated_ip_blocks, force=True) ip_address_man.add_ip_block(ipv4_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv4 block: %s", ipv4_block) ipv6_block = _get_ip_block(mconfig.ipv6_block, "IPv6") if ipv6_block is not None: logging.info('Adding IPv6 block') try: allocated_ipv6_block = ip_address_man.get_assigned_ipv6_block() if ipv6_block != allocated_ipv6_block: ip_address_man.add_ip_block(ipv6_block) except OverlappedIPBlocksError: logging.warning("Overlapped IPv6 block: %s", ipv6_block) # Add all servicers to the server mobility_service_servicer = MobilityServiceRpcServicer( ip_address_man, config.get('print_grpc_payload', False), ) mobility_service_servicer.add_to_server(service.rpc_server) service.run() # Cleanup the service service.close()