def setUp(self): """ Starts the thread which launches ryu apps Create a testing bridge, add a port, setup the port interfaces. Then launch the ryu apps for testing pipelined. Gets the references to apps launched by using futures. """ warnings.simplefilter('ignore') loop_mock = MagicMock() # 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') self._servicer = SMFAssociationServerTest(loop_mock) 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)) sessiod_interface_stub = SetInterfaceForUserPlaneStub(channel) config_mock = { 'enodeb_iface': 'eth1', 'clean_restart': True, '5G_feature_set': {'enable': True}, '5G_feature_set': {'node_identifier': '192.168.220.1'}, 'bridge_name': self.BRIDGE, } self._ng_node_mgr = NodeStateManager(loop_mock, sessiod_interface_stub, config_mock)
def send_periodic_session_update( upf_session_config_state: UPFSessionConfigState, setinterface_stub: SetInterfaceForUserPlaneStub): """ Make RPC call to send periodic messages to smf about sessions state. """ try: setinterface_stub.SetUPFSessionsConfig(upf_session_config_state) return True except grpc.RpcError as err: logging.error("send_periodic_session_update error[%s] %s", err.code(), err.details()) return False
def send_node_state_association_request(node_state_info: UPFNodeState, setinterface_stub: SetInterfaceForUserPlaneStub): """ Make RPC call to send Node Association Setup/Release request to sessionD (SMF) """ try: setinterface_stub.SetUPFNodeState(node_state_info, DEFAULT_GRPC_TIMEOUT) return True except grpc.RpcError as err: logging.error( "send_node_state_association_request error[%s] %s", err.code(), err.details()) return False
def send_paging_intiated_notification( paging_info: UPFPagingInfo, setinterface_stub: SetInterfaceForUserPlaneStub, ): """ Make RPC call to send paging initiated notification to sessionD """ try: setinterface_stub.SetPagingInitiated(paging_info, DEFAULT_GRPC_TIMEOUT) except grpc.RpcError as err: logging.error( "send_paging_intiated_notification error[%s] %s", err.code(), err.details(), )
def send_periodic_session_update( upf_session_config_state: UPFSessionConfigState, setinterface_stub: SetInterfaceForUserPlaneStub, ): """ Make RPC call to send periodic messages to smf about sessions state. """ try: setinterface_stub.SetUPFSessionsConfig(upf_session_config_state, DEFAULT_GRPC_TIMEOUT) return True except grpc.RpcError as err: logging.error( "send_periodic_session_update error[%s] %s", err.code(), err.details(), extra=EXCLUDE_FROM_ERROR_MONITORING if indicates_connection_error(err) else None, ) return False
def load(self): """ Instantiates and schedules the Ryu app eventlets in the service eventloop. """ # Some setups might not use REDIS if (self._magma_service.config['redis_enabled']): # Wait for redis as multiple controllers rely on it while not redisAvailable(self.rule_id_mapper.redis_cli): logging.warning("Pipelined waiting for redis...") time.sleep(1) else: self.rule_id_mapper._rule_nums_by_rule = {} self.rule_id_mapper._rules_by_rule_num = {} self.session_rule_version_mapper._version_by_imsi_and_rule = {} self.interface_to_prefix_mapper._prefix_by_interface = {} self.tunnel_id_mapper._tunnel_map = {} manager = AppManager.get_instance() manager.load_apps([app.module for app in self._apps]) contexts = manager.create_contexts() contexts['rule_id_mapper'] = self.rule_id_mapper contexts[ 'session_rule_version_mapper'] = self.session_rule_version_mapper contexts[ 'interface_to_prefix_mapper'] = self.interface_to_prefix_mapper contexts['tunnel_id_mapper'] = self.tunnel_id_mapper contexts['app_futures'] = {app.name: Future() for app in self._apps} contexts['internal_ip_allocator'] = \ InternalIPAllocator(self._magma_service.config) contexts['config'] = self._magma_service.config contexts['mconfig'] = self._magma_service.mconfig contexts['loop'] = self._magma_service.loop contexts['service_manager'] = self sessiond_chan = ServiceRegistry.get_rpc_channel( 'sessiond', ServiceRegistry.LOCAL) mobilityd_chan = ServiceRegistry.get_rpc_channel( 'mobilityd', ServiceRegistry.LOCAL) contexts['rpc_stubs'] = { 'mobilityd': MobilityServiceStub(mobilityd_chan), 'sessiond': LocalSessionManagerStub(sessiond_chan), } if self._5G_flag_enable: contexts['rpc_stubs'].update({'sessiond_setinterface': \ SetInterfaceForUserPlaneStub(sessiond_chan)}) # Instantiate and schedule apps for app in manager.instantiate_apps(**contexts): # Wrap the eventlet in asyncio so it will stop when the loop is # stopped future = aioeventlet.wrap_greenthread(app, self._magma_service.loop) # Schedule the eventlet for evaluation in service loop asyncio.ensure_future(future) # In development mode, run server so that if environment.is_dev_mode(): server_thread = of_rest_server.start(manager) future = aioeventlet.wrap_greenthread(server_thread, self._magma_service.loop) asyncio.ensure_future(future)