def test_parse_stats(self): """ Test that example statistics from eNodeB can be parsed, and metrics updated """ # Example performance metrics structure, sent by eNodeB pm_file_example = pkg_resources.resource_string( __name__, 'pm_file_example.xml') root = ElementTree.fromstring(pm_file_example) mgr = StatsManager() mgr.parse_pm_xml(root) # Check that metrics were correctly populated # See '<V i="5">123</V>' in pm_file_example rrc_estab_attempts = metrics.STAT_RRC_ESTAB_ATT.collect() self.assertEqual(rrc_estab_attempts[0].samples[0][2], 123) # See '<V i="7">99</V>' in pm_file_example rrc_estab_successes = metrics.STAT_RRC_ESTAB_SUCC.collect() self.assertEqual(rrc_estab_successes[0].samples[0][2], 99) # See '<SV>654</SV>' in pm_file_example rrc_reestab_att_reconf_fail = \ metrics.STAT_RRC_REESTAB_ATT_RECONF_FAIL.collect() self.assertEqual(rrc_reestab_att_reconf_fail[0].samples[0][2], 654) # See '<SV>65537</SV>' in pm_file_example erab_rel_req_radio_conn_lost = \ metrics.STAT_ERAB_REL_REQ_RADIO_CONN_LOST.collect() self.assertEqual(erab_rel_req_radio_conn_lost[0].samples[0][2], 65537)
def main(): """ Top-level function for enodebd """ service = MagmaService('enodebd', mconfigs_pb2.EnodebD()) logger.init() # Optionally pipe errors to Sentry sentry_init(service_name=service.name, sentry_mconfig=service.shared_mconfig.sentry_config) # State machine manager for tracking multiple connected eNB devices. state_machine_manager = StateMachineManager(service) # Statistics manager stats_mgr = StatsManager(state_machine_manager) stats_mgr.run() # Start TR-069 thread server_thread = Thread( target=tr069_server, args=(state_machine_manager, ), daemon=True, ) server_thread.start() print_grpc_payload = service.config.get('print_grpc_payload', False) # Add all servicers to the server enodebd_servicer = EnodebdRpcServicer( state_machine_manager, print_grpc_payload, ) enodebd_servicer.add_to_server(service.rpc_server) # Register function to get service status def get_enodebd_status(): return get_service_status_old(state_machine_manager) service.register_get_status_callback(get_enodebd_status) # Register a callback function for GetOperationalStates service303 function def get_enodeb_operational_states() -> List[State]: return get_operational_states( state_machine_manager, service.mconfig, print_grpc_payload, ) service.register_operational_states_callback(get_enodeb_operational_states) # Set eNodeBD iptables rules due to exposing public IP to eNodeB service.loop.create_task(set_enodebd_iptables_rule()) # Run the service loop service.run() # Cleanup the service service.close()
def build_acs_state_machine( cls, device: EnodebDeviceName = EnodebDeviceName.BAICELLS, ) -> EnodebAcsStateMachine: # Build the state_machine stats_mgr = StatsManager() service = cls.build_magma_service(device) handler_class = get_device_handler_from_name(device) acs_state_machine = handler_class(service, stats_mgr) return acs_state_machine
def _build_acs_state_machine(self) -> BaicellsHandler: # Build the state_machine stats_mgr = StatsManager() event_loop = asyncio.get_event_loop() mconfig = self._get_mconfig() service_config = self._get_service_config() with mock.patch('magma.common.service.MagmaService') as MockService: MockService.config = service_config MockService.mconfig = mconfig MockService.loop = event_loop acs_state_machine = BaicellsHandler(MockService, stats_mgr) return acs_state_machine
class StatsManagerTest(TestCase): """ Tests for eNodeB statistics manager """ def setUp(self) -> None: service = EnodebConfigBuilder.get_service_config() self.enb_acs_manager = StateMachineManager(service) self.mgr = StatsManager(self.enb_acs_manager) self.is_clear_stats_called = False def tearDown(self): self.mgr = None def test_check_rf_tx(self): """ Check that stats are cleared when transmit is disabled on eNB """ handler = EnodebAcsStateMachineBuilder \ .build_acs_state_machine(EnodebDeviceName.BAICELLS) with mock.patch( 'magma.enodebd.devices.baicells.BaicellsHandler.is_enodeb_connected', return_value=True): handler.device_cfg.set_parameter(ParameterName.RF_TX_STATUS, True) handler.device_cfg.set_parameter(ParameterName.SERIAL_NUMBER, '123454') with mock.patch('magma.enodebd.stats_manager.StatsManager' '._clear_stats') as func: self.mgr._check_rf_tx_for_handler(handler) func.assert_not_called() handler.device_cfg.set_parameter(ParameterName.RF_TX_STATUS, False) self.mgr._check_rf_tx_for_handler(handler) func.assert_any_call() def test_parse_stats(self): """ Test that example statistics from eNodeB can be parsed, and metrics updated """ # Example performance metrics structure, sent by eNodeB pm_file_example = pkg_resources.resource_string( __name__, 'pm_file_example.xml') root = ElementTree.fromstring(pm_file_example) self.mgr._parse_pm_xml(root) # Check that metrics were correctly populated # See '<V i="5">123</V>' in pm_file_example rrc_estab_attempts = metrics.STAT_RRC_ESTAB_ATT.collect() self.assertEqual(rrc_estab_attempts[0].samples[0][2], 123) # See '<V i="7">99</V>' in pm_file_example rrc_estab_successes = metrics.STAT_RRC_ESTAB_SUCC.collect() self.assertEqual(rrc_estab_successes[0].samples[0][2], 99) # See '<SV>654</SV>' in pm_file_example rrc_reestab_att_reconf_fail = \ metrics.STAT_RRC_REESTAB_ATT_RECONF_FAIL.collect() self.assertEqual(rrc_reestab_att_reconf_fail[0].samples[0][2], 654) # See '<SV>65537</SV>' in pm_file_example erab_rel_req_radio_conn_lost = \ metrics.STAT_ERAB_REL_REQ_RADIO_CONN_LOST.collect() self.assertEqual(erab_rel_req_radio_conn_lost[0].samples[0][2], 65537)
def setUp(self) -> None: service = EnodebConfigBuilder.get_service_config() self.enb_acs_manager = StateMachineManager(service) self.mgr = StatsManager(self.enb_acs_manager) self.is_clear_stats_called = False