def get_cbsd_state(request: CBSDRequest) -> CBSDStateResult: """ Make RPC call to 'GetCBSDState' method of dp service """ try: chan = ServiceRegistry.get_rpc_channel( DP_SERVICE_NAME, ServiceRegistry.CLOUD, ) except ValueError: logger.error("Can't get RPC channel to %s", DP_SERVICE_NAME) return CBSDStateResult(radio_enabled=False) client = DPServiceStub(chan) try: msg_json = MessageToJson(request, including_default_value_fields=True, preserving_proto_field_name=True) logger.debug(f"Sending GetCBSDState request: {msg_json}") res = client.GetCBSDState(request, DEFAULT_GRPC_TIMEOUT) msg_json = MessageToJson(res, including_default_value_fields=True, preserving_proto_field_name=True) logger.debug(f"Received GetCBSDState reply: {msg_json}") except grpc.RpcError as err: logger.warning( "GetCBSDState error: [%s] %s", err.code(), err.details(), ) return CBSDStateResult(radio_enabled=False) return res
def _build_result(self, channel: DBChannel): if not channel: return CBSDStateResult(radio_enabled=False) return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=channel.low_frequency, high_frequency_hz=channel.high_frequency, max_eirp_dbm_mhz=channel.last_used_max_eirp, ), )
def _build_result(self, cbsd: Optional[DBCbsd] = None, session: Optional[Session] = None): if not cbsd: return CBSDStateResult(radio_enabled=False) grant = self._get_authorized_grant(session, cbsd) if not grant or cbsd.is_deleted: return CBSDStateResult(radio_enabled=False) return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=grant.low_frequency, high_frequency_hz=grant.high_frequency, max_eirp_dbm_mhz=grant.max_eirp, ), )
def build_grant_state_data(self, frequenzy_mhz=None, bandwidth_mhz=None, max_eirp=None) -> CBSDStateResult: frequenzy_mhz = frequenzy_mhz or self.frequency_mhz bandwidth_mhz = bandwidth_mhz or self.bandwidth_mhz max_eirp = max_eirp or self.max_eirp frequency_hz = int(1e6) * frequenzy_mhz half_bandwidth_hz = int(5e5) * bandwidth_mhz return CBSDStateResult( radio_enabled=True, carrier_aggregation_enabled=False, channel=LteChannel( low_frequency_hz=frequency_hz - half_bandwidth_hz, high_frequency_hz=frequency_hz + half_bandwidth_hz, max_eirp_dbm_mhz=max_eirp, ), channels=[ LteChannel( low_frequency_hz=frequency_hz - half_bandwidth_hz, high_frequency_hz=frequency_hz + half_bandwidth_hz, max_eirp_dbm_mhz=max_eirp, ), ], )
def test_tx_parameters_with_eirp_within_range( self, low_frequency_hz, high_frequency_hz, max_eirp_dbm_mhz, expected_bw_rbs, expected_earfcn, expected_tx_power, ) -> None: """Test that tx parameters of the enodeb are calculated correctly when eirp received from SAS is within acceptable range for the given bandwidth""" desired_config = EnodebConfiguration(FreedomFiOneTrDataModel()) channel = LteChannel( low_frequency_hz=low_frequency_hz, high_frequency_hz=high_frequency_hz, max_eirp_dbm_mhz=max_eirp_dbm_mhz, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) ff_one_update_desired_config_from_cbsd_state(state, desired_config) self.assert_config_updated( config=desired_config, bandwidth=expected_bw_rbs, earfcn=expected_earfcn, tx_power=expected_tx_power, radio_enabled=True, )
def _build_result(self, cbsd: Optional[DBCbsd] = None, session: Optional[Session] = None): logger.debug("Building GetCbsdResult") if not cbsd: return CBSDStateResult(radio_enabled=False) grants = self._get_authorized_grants(session, cbsd) if not grants or cbsd.is_deleted: return CBSDStateResult(radio_enabled=False) channels = self._build_lte_channels(grants) return CBSDStateResult( radio_enabled=True, carrier_aggregation_enabled=cbsd.carrier_aggregation_enabled, channel=channels[0], channels=channels, )
def get_state_with_grant() -> CBSDStateResult: return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=3620_000_000, high_frequency_hz=3630_000_000, max_eirp_dbm_mhz=28.0, ), )
def _build_expected_result(grant: DBGrant) -> CBSDStateResult: return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=grant.low_frequency, high_frequency_hz=grant.high_frequency, max_eirp_dbm_mhz=grant.max_eirp, ), )
def _build_expected_result(channel: DBChannel) -> CBSDStateResult: return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=channel.low_frequency, high_frequency_hz=channel.high_frequency, max_eirp_dbm_mhz=channel.last_used_max_eirp, ), )
def build_grant_state_data(self) -> CBSDStateResult: frequency_hz = int(1e6) * self.frequency_mhz half_bandwidth_hz = int(5e5) * self.bandwidth_mhz return CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=frequency_hz - half_bandwidth_hz, high_frequency_hz=frequency_hz + half_bandwidth_hz, max_eirp_dbm_mhz=self.max_eirp, ), )
def test_bandwidth_non_default_MHz(self) -> None: config = EnodebConfiguration(BaicellsQRTBTrDataModel()) channel = LteChannel( low_frequency_hz=3690_000_000, high_frequency_hz=3698_000_000, max_eirp_dbm_mhz=1, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) qrtb_update_desired_config_from_cbsd_state(state, config) self.assert_config_updated(config, '25', 56680, 1)
def test_power_spectral_density_above_range(self) -> None: config = EnodebConfiguration(BaicellsQRTBTrDataModel()) channel = LteChannel( low_frequency_hz=3550_000_000, high_frequency_hz=3560_000_000, max_eirp_dbm_mhz=38, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) with self.assertRaises(ConfigurationError): qrtb_update_desired_config_from_cbsd_state(state, config)
def test_too_low_bandwidth(self) -> None: config = EnodebConfiguration(BaicellsQRTBTrDataModel()) channel = LteChannel( low_frequency_hz=3550_000_000, high_frequency_hz=3551_000_000, max_eirp_dbm_mhz=10, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) with self.assertRaises(ConfigurationError): qrtb_update_desired_config_from_cbsd_state(state, config)
def get_cbsd_state(request: CBSDRequest) -> CBSDStateResult: """ Make RPC call to 'GetCBSDState' method of dp service """ try: chan = ServiceRegistry.get_rpc_channel( DP_SERVICE_NAME, ServiceRegistry.CLOUD, ) except ValueError: logger.error('Cant get RPC channel to %s', DP_SERVICE_NAME) return CBSDStateResult(radio_enabled=False) client = DPServiceStub(chan) try: res = client.GetCBSDState(request, DEFAULT_GRPC_TIMEOUT) except grpc.RpcError as err: logger.warning( "GetCBSDState error: [%s] %s", err.code(), err.details(), ) return CBSDStateResult(radio_enabled=False) return res
def test_tx_params_with_unsupported_bandwidths(self, low_frequency_hz, high_frequency_hz) -> None: """Test that tx parameters calculations raise an exception for unsupported bandwidth ranges""" desired_config = EnodebConfiguration(FreedomFiOneTrDataModel()) channel = LteChannel( low_frequency_hz=low_frequency_hz, high_frequency_hz=high_frequency_hz, max_eirp_dbm_mhz=5, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) with self.assertRaises(ConfigurationError): ff_one_update_desired_config_from_cbsd_state(state, desired_config)
def test_tx_parameters_with_eirp_out_of_range(self, max_eirp_dbm_mhz) -> None: """Test that tx parameters calculations raise an exception when eirp received from SAS is outside of acceptable range for the given bandwidth""" desired_config = EnodebConfiguration(FreedomFiOneTrDataModel()) channel = LteChannel( low_frequency_hz=3550_000_000, high_frequency_hz=3570_000_000, max_eirp_dbm_mhz=max_eirp_dbm_mhz, ) state = CBSDStateResult( radio_enabled=True, channel=channel, ) with self.assertRaises(ConfigurationError): ff_one_update_desired_config_from_cbsd_state(state, desired_config)
def test_omit_other_params_when_radio_disabled(self) -> None: config = EnodebConfiguration(BaicellsQRTBTrDataModel()) channel = LteChannel( low_frequency_hz=3550_000_000, high_frequency_hz=3560_000_000, max_eirp_dbm_mhz=-100, ) state = CBSDStateResult( radio_enabled=False, channel=channel, ) qrtb_update_desired_config_from_cbsd_state(state, config) self.assertEqual( config.get_parameter(ParameterName.SAS_RADIO_ENABLE, ), False, )
def _build_get_state_result() -> CBSDStateResult: return CBSDStateResult( radio_enabled=True, carrier_aggregation_enabled=False, channel=LteChannel( low_frequency_hz=3620_000_000, high_frequency_hz=3630_000_000, max_eirp_dbm_mhz=28.0, ), channels=[ LteChannel( low_frequency_hz=3620_000_000, high_frequency_hz=3630_000_000, max_eirp_dbm_mhz=28.0, ), ], )
def test_tx_params_not_set_when_radio_disabled(self): """Test that tx parameters of the enodeb are not set when ADMIN_STATE is disabled on the radio""" desired_config = EnodebConfiguration(FreedomFiOneTrDataModel()) channel = LteChannel( low_frequency_hz=3550000000, high_frequency_hz=3570000000, max_eirp_dbm_mhz=20, ) state = CBSDStateResult( radio_enabled=False, channel=channel, ) ff_one_update_desired_config_from_cbsd_state(state, desired_config) self.assertEqual(1, len(desired_config.get_parameter_names())) self.assertFalse( desired_config.get_parameter(ParameterName.ADMIN_STATE))
def test_dp_log_created_from_grpc_response(self, with_cbsd, fcc_id, network_id): # Given cbsd = None if with_cbsd: cbsd = self.session.query(DBCbsd).first() channels = [ LteChannel( low_frequency_hz=1, high_frequency_hz=2, max_eirp_dbm_mhz=3, ), LteChannel( low_frequency_hz=4, high_frequency_hz=5, max_eirp_dbm_mhz=6, ), ] message = CBSDStateResult( channels=channels, radio_enabled=True, carrier_aggregation_enabled=True, ) # When actual_log = make_dp_log( method_name=CBSD_REGISTER, message=message, cbsd=cbsd, serial_number=SOME_SERIAL_NUMBER, ) # Then expected_log = DPLog( event_timestamp=SOME_DATE, cbsd_serial_number=SOME_SERIAL_NUMBER, fcc_id=fcc_id, log_from=DP, log_message=str(message), log_name='CBSDRegisterResponse', log_to=CBSD, network_id=network_id, response_code=None, ) self.assertEqual(expected_log, actual_log)
def _build_empty_state_result() -> CBSDStateResult: return CBSDStateResult(radio_enabled=False)
from magma.enodebd.tests.test_utils.enb_acs_builder import ( EnodebAcsStateMachineBuilder, ) from magma.enodebd.tests.test_utils.enodeb_handler import EnodebHandlerTestCase from magma.enodebd.tests.test_utils.tr069_msg_builder import Tr069MessageBuilder from magma.enodebd.tr069 import models from parameterized import parameterized SRC_CONFIG_DIR = os.path.join( os.environ.get('MAGMA_ROOT'), 'lte/gateway/configs', ) MOCK_CBSD_STATE = CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=3550000000, high_frequency_hz=3570000000, max_eirp_dbm_mhz=15, ), ) TEST_SAS_URL = 'test_sas_url' TEST_SAS_CERT_SUBJECT = 'test_sas_cert_subject' class FreedomFiOneTests(EnodebHandlerTestCase): """Testing FreedomfiOne state machine""" def _get_ff_one_read_only_param_values_resp( self, ) -> models.GetParameterValuesResponse: msg = models.GetParameterValuesResponse() param_val_list = [] param_val_list.append(
from magma.enodebd.exceptions import ConfigurationError from magma.enodebd.tests.test_utils.config_builder import EnodebConfigBuilder from magma.enodebd.tests.test_utils.enb_acs_builder import ( EnodebAcsStateMachineBuilder, ) from magma.enodebd.tests.test_utils.enodeb_handler import EnodebHandlerTestCase from magma.enodebd.tests.test_utils.tr069_msg_builder import Tr069MessageBuilder from magma.enodebd.tr069 import models from parameterized import parameterized SRC_CONFIG_DIR = os.path.join( os.environ.get('MAGMA_ROOT'), 'lte/gateway/configs', ) MOCK_CBSD_STATE = CBSDStateResult( radio_enabled=True, channel=LteChannel( low_frequency_hz=3550_000_000, high_frequency_hz=3570_000_000, max_eirp_dbm_mhz=15, ), ) class FreedomFiOneTests(EnodebHandlerTestCase): def _get_freedomfi_one_read_only_param_values_response( self, ) -> models.GetParameterValuesResponse: msg = models.GetParameterValuesResponse() param_val_list = [] param_val_list.append( Tr069MessageBuilder.get_parameter_value_struct( name='Device.X_000E8F_DeviceFeature.X_000E8F_NEStatus'
def get_empty_state() -> CBSDStateResult: return CBSDStateResult(radio_enabled=False)