コード例 #1
0
ファイル: configuration_init.py プロジェクト: talkhasib/magma
def _set_misc_static_params(
    device_cfg: EnodebConfiguration,
    cfg: EnodebConfiguration,
    data_model: DataModel,
) -> None:
    """
    Set the following parameters:
     - Local gateway enable
     - GPS enable
    """
    _set_param_if_present(
        cfg,
        data_model,
        ParameterName.LOCAL_GATEWAY_ENABLE,
        0,
    )
    _set_param_if_present(cfg, data_model, ParameterName.GPS_ENABLE, True)
    # For BaiCells eNodeBs, IPSec enable may be either integer or bool.
    # Set to false/0 depending on the current type
    if data_model.is_parameter_present(ParameterName.IP_SEC_ENABLE):
        try:
            int(device_cfg.get_parameter(ParameterName.IP_SEC_ENABLE))
            cfg.set_parameter(ParameterName.IP_SEC_ENABLE, value=0)
        except ValueError:
            cfg.set_parameter(ParameterName.IP_SEC_ENABLE, value=False)

    _set_param_if_present(cfg, data_model, ParameterName.CELL_RESERVED, False)
    _set_param_if_present(
        cfg,
        data_model,
        ParameterName.MME_POOL_ENABLE,
        False,
    )
コード例 #2
0
def _set_tdd_subframe_config(
    device_cfg: EnodebConfiguration,
    cfg: EnodebConfiguration,
    subframe_assignment: Any,
    special_subframe_pattern: Any,
) -> None:
    """
    Set the following parameters:
     - Subframe assignment
     - Special subframe pattern
    """
    # Don't try to set if this is not TDD mode
    if device_cfg.get_parameter(ParameterName.DUPLEX_MODE_CAPABILITY) != \
            'TDDMode':
        return

    config_assert(subframe_assignment in range(0, 6 + 1),
                  'Invalid TDD subframe assignment (%d)' % subframe_assignment)
    config_assert(
        special_subframe_pattern in range(0, 9 + 1),
        'Invalid TDD special subframe pattern (%d)' % special_subframe_pattern)

    cfg.set_parameter(ParameterName.SUBFRAME_ASSIGNMENT, subframe_assignment)
    cfg.set_parameter(ParameterName.SPECIAL_SUBFRAME_PATTERN,
                      special_subframe_pattern)
コード例 #3
0
def _set_cell_id(
    cfg: EnodebConfiguration,
    cell_id: int,
) -> None:
    config_assert(cell_id in range(0, 268435456),
                  'Cell Identity should be from 0 - (2^28 - 1)')
    cfg.set_parameter(ParameterName.CELL_ID, cell_id)
コード例 #4
0
ファイル: acs_state_utils.py プロジェクト: willoughbyrm/magma
def process_inform_message(
    inform: Any,
    data_model: DataModel,
    device_cfg: EnodebConfiguration,
) -> None:
    """
    Modifies the device configuration based on what is received in the Inform
    message. Will raise an error if it turns out that the data model we are
    using is incorrect. This is decided based on the device OUI and
    software-version that is reported in the Inform message.

    Args:
        inform: Inform Tr069 message
        device_handler: The state machine we are using for our device
    """
    param_values_by_path = _get_param_values_by_path(inform)
    param_name_list = data_model.get_parameter_names()
    name_to_val = {}
    for name in param_name_list:
        path = data_model.get_parameter(name).path
        if path in param_values_by_path:
            value = param_values_by_path[path]
            name_to_val[name] = value

    for name, val in name_to_val.items():
        device_cfg.set_parameter(name, val)
コード例 #5
0
ファイル: baicells_qrtb.py プロジェクト: talkhasib/magma
def qrtb_update_desired_config_from_cbsd_state(
        state: CBSDStateResult, config: EnodebConfiguration) -> None:
    """
    Call grpc endpoint on the Domain Proxy to update the desired config based on sas grant

    Args:
        state (CBSDStateResult): state result as received from DP
        config (EnodebConfiguration): configuration to update
    """
    logger.debug("Updating desired config based on sas grant")
    config.set_parameter(ParameterName.SAS_RADIO_ENABLE, state.radio_enabled)

    if not state.radio_enabled:
        return

    earfcn = calc_earfcn(state.channel.low_frequency_hz,
                         state.channel.high_frequency_hz)
    bandwidth_mhz = calc_bandwidth_mhz(state.channel.low_frequency_hz,
                                       state.channel.high_frequency_hz)
    bandwidth_rbs = calc_bandwidth_rbs(bandwidth_mhz)
    psd = _calc_psd(state.channel.max_eirp_dbm_mhz)

    params_to_set = {
        ParameterName.SAS_RADIO_ENABLE: True,
        ParameterName.BAND: BAND,
        ParameterName.DL_BANDWIDTH: bandwidth_rbs,
        ParameterName.UL_BANDWIDTH: bandwidth_rbs,
        ParameterName.EARFCNDL: earfcn,
        ParameterName.EARFCNUL: earfcn,
        ParameterName.POWER_SPECTRAL_DENSITY: psd,
    }

    for param, value in params_to_set.items():
        config.set_parameter(param, value)
コード例 #6
0
ファイル: acs_state_utils.py プロジェクト: ssanadhya/magma
def process_inform_message(
    inform: Any,
    data_model: DataModel,
    device_cfg: EnodebConfiguration,
) -> None:
    """
    Modifies the device configuration based on what is received in the Inform
    message. Will raise an error if it turns out that the data model we are
    using is incorrect. This is decided based on the device OUI and
    software-version that is reported in the Inform message.

    Args:
        inform: Inform Tr069 message
        device_handler: The state machine we are using for our device
    """
    param_values_by_path = _get_param_values_by_path(inform)
    param_name_list = data_model.get_parameter_names()
    name_to_val = {}
    for name in param_name_list:
        path = data_model.get_parameter(name).path
        if path in param_values_by_path:
            value = param_values_by_path[path]
            name_to_val[name] = value

    for name, val in name_to_val.items():
        device_cfg.set_parameter(name, val)

    # In case the SerialNumber does not come in the inform ParameterList
    # it can still be present in the Inform structure, fill it in.
    if (hasattr(inform, 'DeviceId')
            and hasattr(inform.DeviceId, 'SerialNumber')):
        device_cfg.set_parameter(ParameterName.SERIAL_NUMBER,
                                 inform.DeviceId.SerialNumber)
コード例 #7
0
ファイル: baicells_qrtb.py プロジェクト: talkhasib/magma
    def postprocess(self, mconfig: Any, service_cfg: Any,
                    desired_cfg: EnodebConfiguration) -> None:
        """
        Add some params to the desired config

        Args:
            mconfig (Any): mconfig
            service_cfg (Any): service config
            desired_cfg (EnodebConfiguration): desired config
        """
        desired_cfg.set_parameter(ParameterName.SAS_ENABLED, 1)

        desired_cfg.set_parameter_for_object(
            ParameterName.PLMN_N_CELL_RESERVED % 1,
            True,  # noqa: WPS345,WPS425
            ParameterName.PLMN_N % 1,  # noqa: WPS345
        )
        parameters_to_delete = [
            ParameterName.RADIO_ENABLE,
            ParameterName.POWER_SPECTRAL_DENSITY,
            ParameterName.EARFCNDL,
            ParameterName.EARFCNUL,
            ParameterName.BAND,
            ParameterName.DL_BANDWIDTH,
            ParameterName.UL_BANDWIDTH,
            ParameterName.SAS_RADIO_ENABLE,
        ]
        for p in parameters_to_delete:
            if desired_cfg.has_parameter(p):
                desired_cfg.delete_parameter(p)
コード例 #8
0
def _set_param_if_present(
    cfg: EnodebConfiguration,
    data_model: DataModel,
    param: ParameterName,
    value: Any,
) -> None:
    if data_model.is_parameter_present(param):
        cfg.set_parameter(param, value)
コード例 #9
0
def _set_management_server(cfg: EnodebConfiguration) -> None:
    """
    Set the following parameters:
     - Periodic inform enable
     - Periodic inform interval (hard-coded)
    """
    cfg.set_parameter(ParameterName.PERIODIC_INFORM_ENABLE, True)
    # In seconds
    cfg.set_parameter(ParameterName.PERIODIC_INFORM_INTERVAL, 5)
コード例 #10
0
ファイル: configuration_init.py プロジェクト: wlm328cs/magma
def build_desired_config(
    mconfig: Any,
    service_config: Any,
    device_config: EnodebConfiguration,
    data_model: DataModel,
    post_processor: EnodebConfigurationPostProcessor,
) -> EnodebConfiguration:
    """
    Factory for initializing DESIRED data model configuration.

    When working with the configuration of an eNodeB, we track the
    current state of configuration for that device, as well as what
    configuration we want to set on the device.
    Args:
        mconfig: Managed configuration, eNodeB protobuf message
        service_config:
    Returns:
        Desired data model configuration for the device
    """
    cfg_desired = EnodebConfiguration(data_model)

    # Determine configuration parameters
    _set_management_server(cfg_desired)

    # Attempt to load device configuration from YANG before service mconfig
    enb_config = _get_enb_yang_config(device_config) or \
                 _get_enb_config(mconfig, device_config)

    _set_earfcn_freq_band_mode(device_config, cfg_desired, data_model,
                               enb_config.earfcndl)
    if enb_config.subframe_assignment is not None:
        _set_tdd_subframe_config(device_config, cfg_desired,
            enb_config.subframe_assignment,
            enb_config.special_subframe_pattern)
    _set_pci(cfg_desired, enb_config.pci)
    _set_plmnids_tac(cfg_desired, enb_config.plmnid_list, enb_config.tac)
    _set_bandwidth(cfg_desired, data_model, enb_config.bandwidth_mhz)
    _set_cell_id(cfg_desired, enb_config.cell_id)
    _set_perf_mgmt(
        cfg_desired,
        get_ip_from_if(service_config['tr069']['interface']),
        service_config['tr069']['perf_mgmt_port'])
    _set_misc_static_params(device_config, cfg_desired, data_model)
    if enb_config.mme_address is not None and enb_config.mme_port is not None:
        _set_s1_connection(cfg_desired,
                           enb_config.mme_address,
                           enb_config.mme_port)
    else:
        _set_s1_connection(
            cfg_desired, get_ip_from_if(service_config['s1_interface']))

    # Enable LTE if we should
    cfg_desired.set_parameter(ParameterName.ADMIN_STATE,
                              enb_config.allow_enodeb_transmit)

    post_processor.postprocess(cfg_desired)
    return cfg_desired
コード例 #11
0
ファイル: configuration_init.py プロジェクト: sarathbrp/magma
def build_desired_config(
    mconfig: Any,
    service_config: Any,
    device_config: EnodebConfiguration,
    data_model: DataModel,
    post_processor: EnodebConfigurationPostProcessor,
) -> EnodebConfiguration:
    """
    Factory for initializing DESIRED data model configuration.

    When working with the configuration of an eNodeB, we track the
    current state of configuration for that device, as well as what
    configuration we want to set on the device.
    Args:
        mconfig: Managed configuration, eNodeB protobuf message
        service_config:
    Returns:
        Desired data model configuration for the device
    """
    cfg_desired = EnodebConfiguration(data_model)

    # Determine configuration parameters
    _set_management_server(cfg_desired)
    if mconfig.tdd_config is not None and str(mconfig.tdd_config) != '':
        _set_earfcn_freq_band_mode(device_config, cfg_desired, data_model,
                                   mconfig.tdd_config.earfcndl)
        _set_tdd_subframe_config(device_config, cfg_desired,
                                 mconfig.tdd_config.subframe_assignment,
                                 mconfig.tdd_config.special_subframe_pattern)
    elif mconfig.fdd_config is not None and str(mconfig.fdd_config) != '':
        _set_earfcn_freq_band_mode(device_config, cfg_desired, data_model,
                                   mconfig.fdd_config.earfcndl)
    else:
        # back-compat: use legacy fields if tdd/fdd aren't set
        _set_earfcn_freq_band_mode(device_config, cfg_desired, data_model,
                                   mconfig.earfcndl)
        _set_tdd_subframe_config(device_config, cfg_desired,
                                 mconfig.subframe_assignment,
                                 mconfig.special_subframe_pattern)

    _set_pci(cfg_desired, mconfig.pci)
    _set_plmnids_tac(cfg_desired, mconfig.plmnid_list, mconfig.tac)
    _set_bandwidth(cfg_desired, data_model, mconfig.bandwidth_mhz)
    _set_s1_connection(cfg_desired,
                       get_ip_from_if(service_config['s1_interface']))
    _set_perf_mgmt(cfg_desired,
                   get_ip_from_if(service_config['tr069']['interface']),
                   service_config['tr069']['perf_mgmt_port'])
    _set_misc_static_params(device_config, cfg_desired, data_model)

    # Enable LTE if we should
    cfg_desired.set_parameter(ParameterName.ADMIN_STATE,
                              mconfig.allow_enodeb_transmit)

    post_processor.postprocess(cfg_desired)
    return cfg_desired
コード例 #12
0
def _set_pci(
    cfg: EnodebConfiguration,
    pci: Any,
) -> None:
    """
    Set the following parameters:
     - PCI
    """
    if pci not in range(0, 504 + 1):
        raise ConfigurationError('Invalid PCI (%d)' % pci)
    cfg.set_parameter(ParameterName.PCI, pci)
コード例 #13
0
ファイル: configuration_init.py プロジェクト: wlm328cs/magma
def _set_plmnids_tac(
    cfg: EnodebConfiguration,
    plmnids: Union[int, str],
    tac: Any,
) -> None:
    """
    Set the following parameters:
     - PLMNID list (including all child parameters)

    Input 'plmnids' is comma-separated list of PLMNIDs
    """
    # Convert int PLMNID to string
    if type(plmnids) == int:
        plmnid_str = str(plmnids)
    else:
        config_assert(type(plmnids) == str, 'PLMNID must be string')
        plmnid_str = plmnids

    # Multiple PLMNIDs will be supported using comma-separated list.
    # Currently, just one supported
    for char in plmnid_str:
        config_assert(char in '0123456789, ',
                      'Unhandled character (%s) in PLMNID' % char)
    plmnid_list = plmnid_str.split(',')

    # TODO - add support for multiple PLMNIDs
    config_assert(len(plmnid_list) == 1,
                  'Exactly one PLMNID must be configured')

    # Validate PLMNIDs
    plmnid_list[0] = plmnid_list[0].strip()
    config_assert(len(plmnid_list[0]) <= 6,
                  'PLMNID must be length <=6 (%s)' % plmnid_list[0])

    # We just need one PLMN element in the config. Delete all others.
    for i in range(1, 2):#data_model.get_num_plmns() + 1):
        object_name = ParameterName.PLMN_N % i
        enable_plmn = i == 1
        cfg.add_object(object_name)
        cfg.set_parameter_for_object(ParameterName.PLMN_N_ENABLE % i,
                                     enable_plmn,
                                     object_name)
        if enable_plmn:
            cfg.set_parameter_for_object(
                ParameterName.PLMN_N_CELL_RESERVED % i,
                False, object_name)
            cfg.set_parameter_for_object(ParameterName.PLMN_N_PRIMARY % i,
                                         enable_plmn,
                                         object_name)
            cfg.set_parameter_for_object(ParameterName.PLMN_N_PLMNID % i,
                                         plmnid_list[i - 1],
                                         object_name)
    cfg.set_parameter(ParameterName.TAC, tac)
コード例 #14
0
def _set_bandwidth(
    cfg: EnodebConfiguration,
    data_model: DataModel,
    bandwidth_mhz: Any,
) -> None:
    """
    Set the following parameters:
     - DL bandwidth
     - UL bandwidth
    """
    cfg.set_parameter(ParameterName.DL_BANDWIDTH, bandwidth_mhz)
    _set_param_if_present(cfg, data_model, ParameterName.UL_BANDWIDTH,
                          bandwidth_mhz)
コード例 #15
0
def _set_s1_connection(
    cfg: EnodebConfiguration,
    mme_ip: Any,
    mme_port: Any = DEFAULT_S1_PORT,
) -> None:
    """
    Set the following parameters:
     - MME IP
     - MME port (defalts to 36412 as per TR-196 recommendation)
    """
    config_assert(type(mme_ip) == str, 'Invalid MME IP type')
    config_assert(type(mme_port) == int, 'Invalid MME Port type')
    cfg.set_parameter(ParameterName.MME_IP, mme_ip)
    cfg.set_parameter(ParameterName.MME_PORT, mme_port)
コード例 #16
0
    def postprocess(self, mconfig: Any, service_cfg: Any,
                    desired_cfg: EnodebConfiguration) -> None:
        """
        Add some params to the desired config

        Args:
            mconfig (Any): mconfig
            service_cfg (Any): service config
            desired_cfg (EnodebConfiguration): desired config
        """
        desired_cfg.set_parameter(ParameterName.SAS_ENABLED, 1)
        # Set Cell reservation for both cells
        desired_cfg.set_parameter_for_object(
            ParameterName.PLMN_N_CELL_RESERVED % 1,
            True,  # noqa: WPS345,WPS425
            ParameterName.PLMN_N % 1,  # noqa: WPS345
        )
        desired_cfg.set_parameter(
            CarrierAggregationParameters.CA_PLMN_CELL_RESERVED,
            True,
        )

        # Make sure FAPService.1. is Primary
        desired_cfg.set_parameter_for_object(
            ParameterName.PLMN_N_PRIMARY % 1,
            True,  # noqa: WPS345,WPS425
            ParameterName.PLMN_N % 1,  # noqa: WPS345
        )
        desired_cfg.set_parameter(
            CarrierAggregationParameters.CA_PLMN_PRIMARY,
            False,
        )

        # Enable both cells
        desired_cfg.set_parameter_for_object(
            ParameterName.PLMN_N_ENABLE % 1,
            True,  # noqa: WPS345,WPS425
            ParameterName.PLMN_N % 1,  # noqa: WPS345
        )
        desired_cfg.set_parameter(
            CarrierAggregationParameters.CA_PLMN_ENABLE,
            True,
        )

        parameters_to_delete = [
            ParameterName.RADIO_ENABLE,
            ParameterName.POWER_SPECTRAL_DENSITY,
            ParameterName.EARFCNDL,
            ParameterName.EARFCNUL,
            ParameterName.BAND,
            ParameterName.DL_BANDWIDTH,
            ParameterName.UL_BANDWIDTH,
            ParameterName.SAS_RADIO_ENABLE,
        ]
        for p in parameters_to_delete:
            if desired_cfg.has_parameter(p):
                desired_cfg.delete_parameter(p)
コード例 #17
0
ファイル: freedomfi_one.py プロジェクト: avast1268/magma
    def postprocess(
        self,
        mconfig: Any,
        service_cfg: Any,
        desired_cfg: EnodebConfiguration,
    ) -> None:
        # TODO: Get this config from the domain proxy
        # TODO @amarpad, set these when DProxy integration is done.
        # For now the radio will directly talk to the SAS and get these
        # attributes.
        desired_cfg.delete_parameter(ParameterName.EARFCNDL)
        desired_cfg.delete_parameter(ParameterName.DL_BANDWIDTH)
        desired_cfg.delete_parameter(ParameterName.UL_BANDWIDTH)

        # go through misc parameters and set them to default.
        for name, val in FreedomFiOneMiscParameters.defaults.items():
            desired_cfg.set_parameter(name, val)

        # Bump up the parameter key version
        self.acs.parameter_version_inc()

        # Workaround a bug in Sercomm firmware in release 3920, 3921
        # where the meaning of CellReservedForOperatorUse is wrong.
        # Set to True to ensure the PLMN is not reserved
        num_plmns = self.acs.data_model.get_num_plmns()
        for i in range(1, num_plmns + 1):
            object_name = ParameterName.PLMN_N % i
            desired_cfg.set_parameter_for_object(
                param_name=ParameterName.PLMN_N_CELL_RESERVED % i,
                value=True,
                object_name=object_name,
            )

        if self.WEB_UI_ENABLE_LIST_KEY in service_cfg:
            serial_nos = service_cfg.get(self.WEB_UI_ENABLE_LIST_KEY)
            if self.acs.device_cfg.has_parameter(
                    ParameterName.SERIAL_NUMBER, ):
                if self.acs.get_parameter(ParameterName.SERIAL_NUMBER) in \
                        serial_nos:
                    desired_cfg.set_parameter(
                        FreedomFiOneMiscParameters.WEB_UI_ENABLE,
                        True,
                    )
            else:
                # This should not happen
                EnodebdLogger.error("Serial number unknown for device")

        if self.SAS_KEY not in service_cfg:
            return

        sas_cfg = service_cfg[self.SAS_KEY]
        sas_param_names = self.acs.data_model.get_sas_param_names()
        for name, val in sas_cfg.items():
            if name not in sas_param_names:
                EnodebdLogger.warning("Ignoring attribute %s", name)
                continue
            desired_cfg.set_parameter(name, val)
コード例 #18
0
ファイル: freedomfi_one.py プロジェクト: markjen/magma
    def postprocess(
        self,
        mconfig: Any,
        service_cfg: Any,
        desired_cfg: EnodebConfiguration,
    ) -> None:
        # TODO: Get this config from the domain proxy
        # TODO @amarpad, set these when DProxy integration is done.
        # For now the radio will directly talk to the SAS and get these
        # attributes.
        desired_cfg.delete_parameter(ParameterName.EARFCNDL)
        desired_cfg.delete_parameter(ParameterName.DL_BANDWIDTH)
        desired_cfg.delete_parameter(ParameterName.UL_BANDWIDTH)

        # go through misc parameters and set them to default.
        for name, val in FreedomFiOneMiscParameters.defaults.items():
            desired_cfg.set_parameter(name, val)

        # Bump up the parameter key version
        self.acs.parameter_version_inc()

        if self.WEB_UI_ENABLE_LIST_KEY in service_cfg:
            serial_nos = service_cfg.get(self.WEB_UI_ENABLE_LIST_KEY)
            if self.acs.device_cfg.has_parameter(
                    ParameterName.SERIAL_NUMBER, ):
                if self.acs.get_parameter(ParameterName.SERIAL_NUMBER) in \
                        serial_nos:
                    desired_cfg.set_parameter(
                        FreedomFiOneMiscParameters.WEB_UI_ENABLE,
                        True,
                    )
            else:
                # This should not happen
                EnodebdLogger.error("Serial number unknown for device")

        if self.SAS_KEY not in service_cfg:
            return

        sas_cfg = service_cfg[self.SAS_KEY]
        sas_param_names = self.acs.data_model.get_sas_param_names()
        for name, val in sas_cfg.items():
            if name not in sas_param_names:
                EnodebdLogger.warning("Ignoring attribute %s", name)
                continue
            desired_cfg.set_parameter(name, val)
コード例 #19
0
def _set_perf_mgmt(
    cfg: EnodebConfiguration,
    perf_mgmt_ip: str,
    perf_mgmt_port: int,
) -> None:
    """
    Set the following parameters:
     - Perf mgmt enable
     - Perf mgmt upload interval
     - Perf mgmt upload URL
    """
    cfg.set_parameter(ParameterName.PERF_MGMT_ENABLE, True)
    # Upload interval supported values (in secs):
    # [60, 300, 900, 1800, 3600]
    # Note: eNodeB crashes have been experienced with 60-sec interval.
    # Hence using 300sec
    cfg.set_parameter(ParameterName.PERF_MGMT_UPLOAD_INTERVAL, 300)
    cfg.set_parameter(ParameterName.PERF_MGMT_UPLOAD_URL,
                      'http://%s:%d/' % (perf_mgmt_ip, perf_mgmt_port))
コード例 #20
0
ファイル: baicells_rts.py プロジェクト: GANESH-WAVELABS/magma
 def postprocess(self, desired_cfg: EnodebConfiguration) -> None:
     desired_cfg.set_parameter(ParameterName.CELL_BARRED, False)
コード例 #21
0
ファイル: cavium.py プロジェクト: GANESH-WAVELABS/magma
 def postprocess(self, desired_cfg: EnodebConfiguration) -> None:
     desired_cfg.set_parameter(ParameterName.CELL_BARRED, True)
     desired_cfg.set_parameter(ParameterName.ADMIN_STATE, True)
コード例 #22
0
class EnodebConfigurationFactoryTest(TestCase):
    def setUp(self):
        self.data_model = BaicellsTrDataModel()
        self.cfg = EnodebConfiguration(BaicellsTrDataModel())
        self.device_cfg = EnodebConfiguration(BaicellsTrDataModel())

    def tearDown(self):
        self.data_model = None
        self.cfg = None
        self.device_cfg = None

    def test_set_pci(self):
        pci = 3
        _set_pci(self.cfg, pci)
        self.assertEqual(self.cfg.get_parameter(ParameterName.PCI), pci,
                         'PCI value should be same as what was set')
        with self.assertRaises(ConfigurationError):
            _set_pci(self.cfg, 505)

    def test_set_bandwidth(self):
        mhz = 15
        _set_bandwidth(self.cfg, self.data_model, mhz)
        self.assertEqual(self.cfg.get_parameter(ParameterName.DL_BANDWIDTH),
                         mhz,
                         'Should have set %s' % ParameterName.DL_BANDWIDTH)
        self.assertEqual(self.cfg.get_parameter(ParameterName.UL_BANDWIDTH),
                         mhz,
                         'Should have set %s' % ParameterName.UL_BANDWIDTH)

    def test_set_tdd_subframe_config(self):
        # Not TDD mode, should not try to set anything
        self.device_cfg.set_parameter(ParameterName.DUPLEX_MODE_CAPABILITY,
                                      'Not TDDMode')
        subframe = 0
        special_subframe = 0
        _set_tdd_subframe_config(self.device_cfg, self.cfg, subframe,
                                 special_subframe)
        self.assertTrue(ParameterName.SUBFRAME_ASSIGNMENT not in
                        self.cfg.get_parameter_names())

        # Invalid subframe assignment
        self.device_cfg.set_parameter(ParameterName.DUPLEX_MODE_CAPABILITY,
                                      'TDDMode')
        _set_tdd_subframe_config(self.device_cfg, self.cfg, subframe,
                                 special_subframe)
        self.assertIn(ParameterName.SUBFRAME_ASSIGNMENT,
                      self.cfg.get_parameter_names(),
                      'Expected a subframe assignment')

    def test_set_management_server(self):
        _set_management_server(self.cfg)
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_ENABLE), True,
            'Expected periodic inform enable to be true')
        self.assertTrue(
            isinstance(
                self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_INTERVAL),
                int), 'Expected periodic inform interval to ani integer')

    def test_set_s1_connection(self):
        invalid_mme_ip = 1234
        invalid_mme_port = '8080'
        mme_ip = '192.168.0.1'
        mme_port = 8080

        # MME IP should be a string
        with self.assertRaises(ConfigurationError):
            _set_s1_connection(self.cfg, invalid_mme_ip, mme_port)

        # MME Port should be an integer
        with self.assertRaises(ConfigurationError):
            _set_s1_connection(self.cfg, mme_ip, invalid_mme_port)

        # Check the ip and port are sort properly
        _set_s1_connection(self.cfg, mme_ip, mme_port)
        self.assertEqual(self.cfg.get_parameter(ParameterName.MME_IP), mme_ip,
                         'Expected mme ip to be set')
        self.assertEqual(self.cfg.get_parameter(ParameterName.MME_PORT),
                         mme_port, 'Expected mme port to be set')

    def test_set_perf_mgmt(self):
        mgmt_ip = '192.168.0.1'
        mgmt_upload_interval = 300
        mgmt_port = 8080
        _set_perf_mgmt(self.cfg, mgmt_ip, mgmt_port)
        self.assertTrue(self.cfg.get_parameter(ParameterName.PERF_MGMT_ENABLE),
                        'Expected perf mgmt to be enabled')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_INTERVAL),
            mgmt_upload_interval, 'Expected upload interval to be set')
        expected_url = 'http://192.168.0.1:8080/'
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_URL),
            expected_url, 'Incorrect Url')

    def test_set_misc_static_params(self):
        # IPSec enable as integer
        self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 0)
        self.data_model.set_parameter_presence(ParameterName.GPS_ENABLE, True)
        _set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
        self.assertTrue(
            isinstance(self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE),
                       int),
            'Should support an integer IP_SEC_ENABLE parameter')

        # IPSec enable as boolean
        self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 'False')
        _set_misc_static_params(self.device_cfg, self.cfg, self.data_model)
        self.assertTrue(
            isinstance(self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE),
                       bool),
            'Should support a boolean IP_SEC_ENABLE parameter')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.LOCAL_GATEWAY_ENABLE), 0,
            'Should be disabled')
        self.assertEqual(self.cfg.get_parameter(ParameterName.CELL_RESERVED),
                         False, 'Should be disabled')
        self.assertEqual(self.cfg.get_parameter(ParameterName.MME_POOL_ENABLE),
                         False, 'Should be disabled')

    def test_set_plmnids_tac(self):
        # We only handle a single PLMNID for now
        plmnids = '1, 2, 3, 4'
        tac = 1
        with self.assertRaises(ConfigurationError):
            _set_plmnids_tac(self.cfg, plmnids, tac)

        # Max PLMNID length is 6 characters
        plmnids = '1234567'
        with self.assertRaises(ConfigurationError):
            _set_plmnids_tac(self.cfg, plmnids, tac)

        # Check that only one PLMN element is enabled
        plmnids = '1'
        _set_plmnids_tac(self.cfg, plmnids, tac)
        self.assertTrue(
            self.cfg.get_parameter_for_object(ParameterName.PLMN_N_ENABLE % 1,
                                              ParameterName.PLMN_N % 1),
            'First PLMN should be enabled')
        self.assertFalse(self.cfg.has_object(ParameterName.PLMN_N % 2),
                         'Second PLMN should be disabled')

    def test_set_earafcn_freq_band_mode(self):
        # Invalid earfcndl
        with self.assertRaises(ConfigurationError):
            invalid_earfcndl = -1
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg,
                                       self.data_model, invalid_earfcndl)

        # Duplex_mode is TDD but capability is FDD
        with self.assertRaises(ConfigurationError):
            self.device_cfg.set_parameter(ParameterName.DUPLEX_MODE_CAPABILITY,
                                          'FDDMode')
            earfcndl = 38650  # Corresponds to TDD
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg,
                                       self.data_model, earfcndl)

        # Duplex_mode is FDD but capability is TDD
        with self.assertRaises(ConfigurationError):
            self.device_cfg.set_parameter(ParameterName.DUPLEX_MODE_CAPABILITY,
                                          'TDDMode')
            earfcndl = 0  # Corresponds to FDD
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg,
                                       self.data_model, earfcndl)

    def test_get_enb_config(self):
        mconfig = EnodebConfigBuilder.get_mconfig()
        enb_config = _get_enb_config(mconfig, self.device_cfg)
        self.assertTrue(enb_config.earfcndl == 39150,
                        "Should give earfcndl from default eNB config")

        mconfig = EnodebConfigBuilder.get_multi_enb_mconfig()
        self.device_cfg.set_parameter(ParameterName.SERIAL_NUMBER,
                                      '120200002618AGP0003')
        enb_config = _get_enb_config(mconfig, self.device_cfg)
        self.assertTrue(enb_config.earfcndl == 39151,
                        "Should give earfcndl from specific eNB config")
コード例 #23
0
class EnodebConfigurationTest(TestCase):
    def setUp(self):
        self.config = EnodebConfiguration(CaviumTrDataModel)

    def tearDown(self):
        self.config = None

    def test_data_model(self) -> None:
        data_model = self.config.data_model
        expected = CaviumTrDataModel
        self.assertEqual(data_model, expected, 'Data model fetch incorrect')

    def test_get_has_set_parameter(self) -> None:
        param = ParameterName.ADMIN_STATE
        self.config.set_parameter(param, True)
        self.assertTrue(self.config.has_parameter(param),
                        'Expected to have parameter')
        param_value = self.config.get_parameter(param)
        expected = True
        self.assertEqual(param_value, expected,
                         'Parameter value does not match what was set')

    def test_add_has_delete_object(self) -> None:
        object_name = ParameterName.PLMN_N % 1
        self.assertFalse(self.config.has_object(object_name))
        self.config.add_object(object_name)
        self.assertTrue(self.config.has_object(object_name))
        self.config.delete_object(object_name)
        self.assertFalse(self.config.has_object(object_name))

    def test_get_parameter_names(self) -> None:
        # Should start off as an empty list
        names_list = self.config.get_parameter_names()
        self.assertEqual(len(names_list), 0, 'Expected 0 names')

        # Should grow as we set parameters
        self.config.set_parameter(ParameterName.ADMIN_STATE, True)
        names_list = self.config.get_parameter_names()
        self.assertEqual(len(names_list), 1, 'Expected 1 name')

        # Parameter names should not include objects
        self.config.add_object(ParameterName.PLMN)
        names_list = self.config.get_parameter_names()
        self.assertEqual(len(names_list), 1, 'Expected 1 name')

    def test_get_object_names(self) -> None:
        # Should start off as an empty list
        obj_list = self.config.get_object_names()
        self.assertEqual(len(obj_list), 0, 'Expected 0 names')

        # Should grow as we set parameters
        self.config.add_object(ParameterName.PLMN)
        obj_list = self.config.get_object_names()
        self.assertEqual(len(obj_list), 1, 'Expected 1 names')

    def test_get_set_parameter_for_object(self) -> None:
        self.config.add_object(ParameterName.PLMN_N % 1)
        self.config.set_parameter_for_object(
            ParameterName.PLMN_N_CELL_RESERVED % 1, True,
            ParameterName.PLMN_N % 1)
        param_value = self.config.get_parameter_for_object(
            ParameterName.PLMN_N_CELL_RESERVED % 1, ParameterName.PLMN_N % 1)
        self.assertTrue(
            param_value,
            'Expected that the param for object was set correctly')

    def test_get_parameter_names_for_object(self) -> None:
        # Should start off empty
        self.config.add_object(ParameterName.PLMN_N % 1)
        param_list = self.config.get_parameter_names_for_object(
            ParameterName.PLMN_N % 1)
        self.assertEqual(len(param_list), 0, 'Should be an empty param list')

        # Should increment as we set parameters
        self.config.set_parameter_for_object(
            ParameterName.PLMN_N_CELL_RESERVED % 1, True,
            ParameterName.PLMN_N % 1)
        param_list = self.config.get_parameter_names_for_object(
            ParameterName.PLMN_N % 1)
        self.assertEqual(len(param_list), 1, 'Should not be an empty list')
コード例 #24
0
def process_inform_message(
    inform: Any,
    device_name: EnodebDeviceName,
    data_model: DataModel,
    device_cfg: EnodebConfiguration,
) -> None:
    """
    Modifies the device configuration based on what is received in the Inform
    message. Will raise an error if it turns out that the data model we are
    using is incorrect. This is decided based on the device OUI and
    software-version that is reported in the Inform message.

    Args:
        inform: Inform Tr069 message
        device_handler: The state machine we are using for our device
    """
    logging.info('Processing Inform message')

    def _get_param_value_from_path_suffix(
        suffix: str,
        path_list: List[str],
        param_values_by_path: Dict[str, Any],
    ) -> Any:
        for path in path_list:
            if path.endswith(suffix):
                return param_values_by_path[path]
        raise ConfigurationError('Did not receive expected info in Inform')

    if hasattr(inform, 'ParameterList') and \
            hasattr(inform.ParameterList, 'ParameterValueStruct'):
        param_values_by_path = {}
        for param_value in inform.ParameterList.ParameterValueStruct:
            path = param_value.Name
            value = param_value.Value.Data
            logging.debug('(Inform msg) Received parameter: %s = %s', path,
                          value)
            param_values_by_path[path] = value

        # Check the OUI and version number to see if the data model matches
        path_list = list(param_values_by_path.keys())
        device_oui = _get_param_value_from_path_suffix(
            'DeviceInfo.ManufacturerOUI',
            path_list,
            param_values_by_path,
        )
        sw_version = _get_param_value_from_path_suffix(
            'DeviceInfo.SoftwareVersion',
            path_list,
            param_values_by_path,
        )
        logging.info('OUI: %s, Software: %s', device_oui, sw_version)
        correct_device_name = get_device_name(device_oui, sw_version)
        if device_name is not correct_device_name:
            raise IncorrectDeviceHandlerError(
                device_name=correct_device_name)

        param_name_list = data_model.get_parameter_names()
        name_to_val = {}
        for name in param_name_list:
            path = data_model.get_parameter(name).path
            if path in param_values_by_path:
                value = param_values_by_path[path]
                name_to_val[name] = value

        for name, val in name_to_val.items():
            device_cfg.set_parameter(name, val)
コード例 #25
0
ファイル: baicells_qrtb.py プロジェクト: rsarwad/magma
def qrtb_update_desired_config_from_cbsd_state(state: CBSDStateResult, config: EnodebConfiguration) -> None:
    """
    Call grpc endpoint on the Domain Proxy to update the desired config based on sas grant

    Args:
        state (CBSDStateResult): state result as received from DP
        config (EnodebConfiguration): configuration to update
    """
    logger.debug("Updating desired config based on Domain Proxy state.")
    num_of_channels = len(state.channels)
    radio_enabled = num_of_channels > 0 and state.radio_enabled
    config.set_parameter(ParameterName.SAS_RADIO_ENABLE, radio_enabled)

    if not radio_enabled:
        return

    # FAPService.1
    channel = state.channels[0]
    earfcn = calc_earfcn(channel.low_frequency_hz, channel.high_frequency_hz)
    bandwidth_mhz = calc_bandwidth_mhz(channel.low_frequency_hz, channel.high_frequency_hz)
    bandwidth_rbs = calc_bandwidth_rbs(bandwidth_mhz)
    psd = _calc_psd(channel.max_eirp_dbm_mhz)
    logger.debug(f"Channel1: {earfcn=}, {bandwidth_rbs=}, {psd=}")

    can_enable_carrier_aggregation = _qrtb_check_state_compatibility_with_ca(state)
    logger.debug(f"Should Carrier Aggregation be enabled on eNB: {can_enable_carrier_aggregation=}")
    # Enabling Carrier Aggregation on QRTB eNB means:
    # 1. Set CA_ENABLE to 1
    # 2. Set CA_NUM_OF_CELLS to 2
    # 3. Configure appropriate TR nodes for FAPSerivce.2 like EARFCNDL/UL etc
    # Otherwise we need to disable Carrier Aggregation on eNB and switch to Single Carrier configuration
    # 1. Set CA_ENABLE to 0
    # 2. Set CA_NUM_OF_CELLS to 1
    # Those two nodes should handle everything else accordingly.
    # (NOTE: carrier aggregation may still be enabled on Domain Proxy, but Domain Proxy may not have 2 channels granted by SAS.
    #        In such case, we still have to switch eNB to Single Carrier)
    num_of_cells = 2 if can_enable_carrier_aggregation else 1
    ca_enable = 1 if can_enable_carrier_aggregation else 0

    params_to_set = {
        ParameterName.SAS_RADIO_ENABLE: True,
        ParameterName.BAND: BAND,
        ParameterName.DL_BANDWIDTH: bandwidth_rbs,
        ParameterName.UL_BANDWIDTH: bandwidth_rbs,
        ParameterName.EARFCNDL: earfcn,
        ParameterName.EARFCNUL: earfcn,
        ParameterName.POWER_SPECTRAL_DENSITY: psd,
        CarrierAggregationParameters.CA_ENABLE: ca_enable,
        CarrierAggregationParameters.CA_NUM_OF_CELLS: num_of_cells,
    }
    if can_enable_carrier_aggregation:
        # Configure FAPService.2
        # NOTE: We set PCI and CELL_ID to the values of FAP1 "+1"
        #       This was suggested by BaiCells
        channel = state.channels[1]
        earfcn = calc_earfcn(channel.low_frequency_hz, channel.high_frequency_hz)
        bandwidth_mhz = calc_bandwidth_mhz(channel.low_frequency_hz, channel.high_frequency_hz)
        bandwidth_rbs = calc_bandwidth_rbs(bandwidth_mhz)
        psd = _calc_psd(channel.max_eirp_dbm_mhz)
        logger.debug(f"Channel2: {earfcn=}, {bandwidth_rbs=}, {psd=}")
        params_to_set.update({
            CarrierAggregationParameters.CA_DL_BANDWIDTH: bandwidth_rbs,
            CarrierAggregationParameters.CA_UL_BANDWIDTH: bandwidth_rbs,
            CarrierAggregationParameters.CA_BAND: BAND,
            CarrierAggregationParameters.CA_EARFCNDL: earfcn,
            CarrierAggregationParameters.CA_EARFCNUL: earfcn,
            CarrierAggregationParameters.CA_PCI: config.get_parameter(ParameterName.PCI) + 1,
            CarrierAggregationParameters.CA_CELL_ID: config.get_parameter(ParameterName.CELL_ID) + 1,
            CarrierAggregationParameters.CA_RADIO_ENABLE: True,
        })

    for param, value in params_to_set.items():
        config.set_parameter(param, value)
コード例 #26
0
ファイル: freedomfi_one.py プロジェクト: markjen/magma
    def set_magma_device_cfg(
        cls,
        name_to_val: Dict,
        device_cfg: EnodebConfiguration,
    ):
        """
        Convert FreedomFiOne name_to_val representation to magma device_cfg
        """
        success_str = "SUCCESS"  # String constant returned by radio
        insync_str = "INSYNC"

        if (name_to_val.get(cls.DEFAULT_GW)
                and name_to_val[cls.DEFAULT_GW].upper() != success_str):
            # Nothing will proceed if the eNB doesn't have an IP on the WAN
            serial_num = "unknown"
            if device_cfg.has_parameter(ParameterName.SERIAL_NUMBER):
                serial_num = device_cfg.get_parameter(
                    ParameterName.SERIAL_NUMBER, )
            EnodebdLogger.error(
                "Radio with serial number %s doesn't have IP address "
                "on WAN",
                serial_num,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.RF_TX_STATUS,
                value=False,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.GPS_STATUS,
                value=False,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.PTP_STATUS,
                value=False,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.MME_STATUS,
                value=False,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.OP_STATE,
                value=False,
            )
            return

        if (name_to_val.get(cls.SAS_STATUS)
                and name_to_val[cls.SAS_STATUS].upper() == success_str):
            device_cfg.set_parameter(
                param_name=ParameterName.RF_TX_STATUS,
                value=True,
            )
        else:
            # No sas grant so not transmitting. There is no explicit node for Tx
            # in FreedomFiOne
            device_cfg.set_parameter(
                param_name=ParameterName.RF_TX_STATUS,
                value=False,
            )

        if (name_to_val.get(cls.GPS_SCAN_STATUS)
                and name_to_val[cls.GPS_SCAN_STATUS].upper() == success_str):
            device_cfg.set_parameter(
                param_name=ParameterName.GPS_STATUS,
                value=True,
            )
            # Time comes through GPS so can only be insync with GPS is
            # in sync, we use PTP_STATUS field to overload timer is in Sync.
            if (name_to_val.get(cls.SYNC_STATUS)
                    and name_to_val[cls.SYNC_STATUS].upper() == insync_str):
                device_cfg.set_parameter(
                    param_name=ParameterName.PTP_STATUS,
                    value=True,
                )
            else:
                device_cfg.set_parameter(
                    param_name=ParameterName.PTP_STATUS,
                    value=False,
                )
        else:
            device_cfg.set_parameter(
                param_name=ParameterName.GPS_STATUS,
                value=False,
            )
            device_cfg.set_parameter(
                param_name=ParameterName.PTP_STATUS,
                value=False,
            )

        if (name_to_val.get(cls.DEFAULT_GW)
                and name_to_val[cls.DEFAULT_GW].upper() == success_str):
            device_cfg.set_parameter(
                param_name=ParameterName.MME_STATUS,
                value=True,
            )
        else:
            device_cfg.set_parameter(
                param_name=ParameterName.MME_STATUS,
                value=False,
            )

        if (name_to_val.get(cls.ENB_STATUS)
                and name_to_val[cls.ENB_STATUS].upper() == success_str):
            device_cfg.set_parameter(
                param_name=ParameterName.OP_STATE,
                value=True,
            )
        else:
            device_cfg.set_parameter(
                param_name=ParameterName.OP_STATE,
                value=False,
            )

        pass_through_params = [ParameterName.GPS_LAT, ParameterName.GPS_LONG]
        for name in pass_through_params:
            device_cfg.set_parameter(name, name_to_val[name])
コード例 #27
0
class EnodebConfigurationFactoryTest(TestCase):

    def setUp(self):
        self.cfg = EnodebConfiguration(BaicellsTrDataModel)
        self.device_cfg = EnodebConfiguration(BaicellsTrDataModel)

    def tearDown(self):
        self.cfg = None
        self.device_cfg = None

    def _get_mconfig(self):
        return {
            "@type": "type.googleapis.com/magma.mconfig.EnodebD",
            "bandwidthMhz": 20,
            "specialSubframePattern": 7,
            "earfcndl": 44490,
            "logLevel": "INFO",
            "plmnidList": "00101",
            "pci": 260,
            "allowEnodebTransmit": False,
            "subframeAssignment": 2,
            "tac": 1
        },

    def _get_service_config(self):
        return {
            "tr069": {
                "interface": "eth1",
                "port": 48080,
                "perf_mgmt_port": 8081,
                "public_ip": "192.88.99.142",
            },
            "reboot_enodeb_on_mme_disconnected": True,
            "s1_interface": "eth1",
        }

    def test_set_pci(self):
        pci = 3
        _set_pci(self.cfg, pci)
        self.assertEqual(self.cfg.get_parameter(ParameterName.PCI), pci,
                         'PCI value should be same as what was set')
        with self.assertRaises(ConfigurationError):
            _set_pci(self.cfg, 505)

    def test_set_bandwidth(self):
        mhz = 15
        _set_bandwidth(self.cfg, mhz)
        self.assertEqual(self.cfg.get_parameter(ParameterName.DL_BANDWIDTH),
                         mhz,
                         'Should have set %s' % ParameterName.DL_BANDWIDTH)
        self.assertEqual(self.cfg.get_parameter(ParameterName.UL_BANDWIDTH),
                         mhz,
                         'Should have set %s' % ParameterName.UL_BANDWIDTH)

    def test_set_tdd_subframe_config(self):
        # Not TDD mode, should not try to set anything
        self.device_cfg.set_parameter(
            ParameterName.DUPLEX_MODE_CAPABILITY, 'Not TDDMode')
        subframe = 0
        special_subframe = 0
        _set_tdd_subframe_config(self.device_cfg, self.cfg, subframe,
                                              special_subframe)
        self.assertTrue(ParameterName.SUBFRAME_ASSIGNMENT not in
                        self.cfg.get_parameter_names())

        # Invalid subframe assignment
        self.device_cfg.set_parameter(
            ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode')
        _set_tdd_subframe_config(self.device_cfg, self.cfg, subframe,
                                 special_subframe)
        self.assertIn(ParameterName.SUBFRAME_ASSIGNMENT,
                      self.cfg.get_parameter_names(),
                      'Expected a subframe assignment')

    def test_set_management_server(self):
        _set_management_server(self.cfg)
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_ENABLE),
            True, 'Expected periodic inform enable to be true')
        self.assertTrue(
            isinstance(
                self.cfg.get_parameter(ParameterName.PERIODIC_INFORM_INTERVAL),
                int),
            'Expected periodic inform interval to ani integer'
        )

    def test_set_s1_connection(self):
        invalid_mme_ip = 1234
        invalid_mme_port = '8080'
        mme_ip = '192.168.0.1'
        mme_port = 8080

        # MME IP should be a string
        with self.assertRaises(ConfigurationError):
            _set_s1_connection(self.cfg, invalid_mme_ip, mme_port)

        # MME Port should be an integer
        with self.assertRaises(ConfigurationError):
            _set_s1_connection(self.cfg, mme_ip, invalid_mme_port)

        # Check the ip and port are sort properly
        _set_s1_connection(self.cfg, mme_ip, mme_port)
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.MME_IP), mme_ip,
            'Expected mme ip to be set')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.MME_PORT), mme_port,
            'Expected mme port to be set')

    def test_set_perf_mgmt(self):
        mgmt_ip = '192.168.0.1'
        mgmt_upload_interval = 300
        mgmt_port = 8080
        _set_perf_mgmt(self.cfg, mgmt_ip, mgmt_port)
        self.assertTrue(
            self.cfg.get_parameter(ParameterName.PERF_MGMT_ENABLE),
            'Expected perf mgmt to be enabled')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_INTERVAL),
            mgmt_upload_interval, 'Expected upload interval to be set')
        expected_url = 'http://192.168.0.1:8080/'
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.PERF_MGMT_UPLOAD_URL),
            expected_url, 'Incorrect Url')

    def test_set_misc_static_params(self):
        # IPSec enable as integer
        data_model = BaicellsTrDataModel
        self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 0)
        _set_misc_static_params(self.device_cfg, self.cfg, data_model)
        self.assertTrue(
            isinstance(
                self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), int),
            'Should support an integer IP_SEC_ENABLE parameter')

        # IPSec enable as boolean
        self.device_cfg.set_parameter(ParameterName.IP_SEC_ENABLE, 'False')
        _set_misc_static_params(self.device_cfg, self.cfg, data_model)
        self.assertTrue(
            isinstance(
                self.cfg.get_parameter(ParameterName.IP_SEC_ENABLE), bool),
            'Should support a boolean IP_SEC_ENABLE parameter')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.LOCAL_GATEWAY_ENABLE), 0,
            'Should be disabled')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.CELL_RESERVED), False,
            'Should be disabled')
        self.assertEqual(
            self.cfg.get_parameter(ParameterName.MME_POOL_ENABLE), False,
            'Should be disabled')

    def test_set_plmnids_tac(self):
        # We only handle a single PLMNID for now
        data_model = BaicellsTrDataModel
        plmnids = '1, 2, 3, 4'
        tac = 1
        with self.assertRaises(ConfigurationError):
            _set_plmnids_tac(self.cfg, data_model, plmnids, tac)

        # Max PLMNID length is 6 characters
        plmnids = '1234567'
        with self.assertRaises(ConfigurationError):
            _set_plmnids_tac(self.cfg, data_model, plmnids, tac)

        # Check that only one PLMN element is enabled
        plmnids = '1'
        _set_plmnids_tac(self.cfg, data_model, plmnids, tac)
        self.assertTrue(
            self.cfg.get_parameter_for_object(
                ParameterName.PLMN_N_ENABLE % 1, ParameterName.PLMN_N % 1),
            'First PLMN should be enabled')
        self.assertFalse(self.cfg.has_object(ParameterName.PLMN_N % 2),
                         'Second PLMN should be disabled')

    def test_set_earafcn_freq_band_mode(self):
        # Invalid earfcndl
        with self.assertRaises(ConfigurationError):
            invalid_earfcndl = -1
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg,
                                       invalid_earfcndl)

        # Duplex_mode is TDD but capability is FDD
        with self.assertRaises(ConfigurationError):
            self.device_cfg.set_parameter(
                ParameterName.DUPLEX_MODE_CAPABILITY, 'FDDMode')
            earfcndl = 38650  # Corresponds to TDD
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg, earfcndl)

        # Duplex_mode is FDD but capability is TDD
        with self.assertRaises(ConfigurationError):
            self.device_cfg.set_parameter(
                ParameterName.DUPLEX_MODE_CAPABILITY, 'TDDMode')
            earfcndl = 0  # Corresponds to FDD
            _set_earfcn_freq_band_mode(self.device_cfg, self.cfg, earfcndl)
コード例 #28
0
def _set_earfcn_freq_band_mode(
    device_cfg: EnodebConfiguration,
    cfg: EnodebConfiguration,
    data_model: DataModel,
    earfcndl: int,
) -> None:
    """
    Set the following parameters:
     - EARFCNDL
     - EARFCNUL
     - Band
    """
    # Note: validation of EARFCNDL done by mapping function. If invalid
    # EARFCN, raise ConfigurationError
    try:
        band, duplex_mode, earfcnul = map_earfcndl_to_band_earfcnul_mode(
            earfcndl)
    except ValueError as err:
        raise ConfigurationError(err)

    # Verify capabilities
    duplex_capability =\
        device_cfg.get_parameter(ParameterName.DUPLEX_MODE_CAPABILITY)
    if duplex_mode == DuplexMode.TDD and duplex_capability != 'TDDMode':
        raise ConfigurationError(
            ('eNodeB duplex mode capability is <{0}>, '
             'but earfcndl is <{1}>, giving duplex '
             'mode <{2}> instead').format(duplex_capability, str(earfcndl),
                                          str(duplex_mode)))
    elif duplex_mode == DuplexMode.FDD and duplex_capability != 'FDDMode':
        raise ConfigurationError(
            ('eNodeB duplex mode capability is <{0}>, '
             'but earfcndl is <{1}>, giving duplex '
             'mode <{2}> instead').format(duplex_capability, str(earfcndl),
                                          str(duplex_mode)))
    elif duplex_mode not in [DuplexMode.TDD, DuplexMode.FDD]:
        raise ConfigurationError('Invalid duplex mode (%s)' % str(duplex_mode))

    # Baicells indicated that they no longer use the band capability list,
    # so it may not be populated correctly
    band_capability_list = device_cfg.get_parameter(
        ParameterName.BAND_CAPABILITY)
    band_capabilities = band_capability_list.split(',')
    if str(band) not in band_capabilities:
        logging.warning(
            'Band %d not in capabilities list (%s). Continuing'
            ' with config because capabilities list may not be'
            ' correct', band, band_capabilities)

    cfg.set_parameter(ParameterName.EARFCNDL, earfcndl)
    if duplex_mode == DuplexMode.FDD:
        cfg.set_parameter(ParameterName.EARFCNUL, earfcnul)
    else:
        logging.debug('Not setting EARFCNUL - duplex mode is not FDD')

    _set_param_if_present(cfg, data_model, ParameterName.BAND, band)

    if duplex_mode == DuplexMode.TDD:
        logging.debug('Set EARFCNDL=%d, Band=%d', earfcndl, band)
    else:
        logging.debug('Set EARFCNDL=%d, EARFCNUL=%d, Band=%d', earfcndl,
                      earfcnul, band)