Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame] | 1 | # SPDX-FileCopyrightText: 2020 The Magma Authors. |
| 2 | # SPDX-FileCopyrightText: 2022 Open Networking Foundation <support@opennetworking.org> |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
| 6 | from typing import Any, Callable, Dict, List, Optional, Type |
| 7 | |
| 8 | from common.service import MagmaService |
| 9 | from data_models import transform_for_enb, transform_for_magma |
| 10 | from data_models.data_model import DataModel, TrParam |
| 11 | from data_models.data_model_parameters import ( |
| 12 | ParameterName, |
| 13 | TrParameterType, |
| 14 | ) |
| 15 | from device_config.enodeb_config_postprocessor import ( |
| 16 | EnodebConfigurationPostProcessor, |
| 17 | ) |
| 18 | from device_config.enodeb_configuration import EnodebConfiguration |
| 19 | from devices.baicells_qafb import ( |
| 20 | BaicellsQafbGetObjectParametersState, |
| 21 | BaicellsQafbWaitGetTransientParametersState, |
| 22 | ) |
| 23 | from devices.device_utils import EnodebDeviceName |
| 24 | from state_machines.enb_acs_impl import BasicEnodebAcsStateMachine |
| 25 | from state_machines.enb_acs_states import ( |
| 26 | AddObjectsState, |
| 27 | DeleteObjectsState, |
| 28 | EnbSendRebootState, |
| 29 | EndSessionState, |
| 30 | EnodebAcsState, |
| 31 | ErrorState, |
| 32 | GetParametersState, |
| 33 | GetRPCMethodsState, |
| 34 | SendGetTransientParametersState, |
| 35 | SetParameterValuesState, |
| 36 | WaitEmptyMessageState, |
| 37 | WaitGetParametersState, |
| 38 | WaitInformMRebootState, |
| 39 | WaitInformState, |
| 40 | WaitRebootResponseState, |
| 41 | WaitSetParameterValuesState, |
| 42 | ) |
| 43 | |
| 44 | |
| 45 | class BaicellsQAFAHandler(BasicEnodebAcsStateMachine): |
| 46 | def __init__( |
| 47 | self, |
| 48 | service: MagmaService, |
| 49 | ) -> None: |
| 50 | self._state_map = {} |
| 51 | super().__init__(service=service, use_param_key=False) |
| 52 | |
| 53 | def reboot_asap(self) -> None: |
| 54 | self.transition('reboot') |
| 55 | |
| 56 | def is_enodeb_connected(self) -> bool: |
| 57 | return not isinstance(self.state, WaitInformState) |
| 58 | |
| 59 | def _init_state_map(self) -> None: |
| 60 | self._state_map = { |
| 61 | 'wait_inform': WaitInformState(self, when_done='get_rpc_methods'), |
| 62 | 'get_rpc_methods': GetRPCMethodsState(self, when_done='wait_empty', when_skip='get_transient_params'), |
| 63 | 'wait_empty': WaitEmptyMessageState(self, when_done='get_transient_params'), |
| 64 | 'get_transient_params': SendGetTransientParametersState(self, when_done='wait_get_transient_params'), |
| 65 | 'wait_get_transient_params': BaicellsQafbWaitGetTransientParametersState(self, when_get='get_params', when_get_obj_params='get_obj_params', when_delete='delete_objs', when_add='add_objs', when_set='set_params', when_skip='end_session'), |
| 66 | 'get_params': GetParametersState(self, when_done='wait_get_params'), |
| 67 | 'wait_get_params': WaitGetParametersState(self, when_done='get_obj_params'), |
| 68 | 'get_obj_params': BaicellsQafbGetObjectParametersState(self, when_delete='delete_objs', when_add='add_objs', when_set='set_params', when_skip='end_session'), |
| 69 | 'delete_objs': DeleteObjectsState(self, when_add='add_objs', when_skip='set_params'), |
| 70 | 'add_objs': AddObjectsState(self, when_done='set_params'), |
| 71 | 'set_params': SetParameterValuesState(self, when_done='wait_set_params'), |
| 72 | 'wait_set_params': WaitSetParameterValuesState(self, when_done='check_get_params', when_apply_invasive='check_get_params'), |
| 73 | 'check_get_params': GetParametersState(self, when_done='check_wait_get_params', request_all_params=True), |
| 74 | 'check_wait_get_params': WaitGetParametersState(self, when_done='end_session'), |
| 75 | 'end_session': EndSessionState(self), |
| 76 | # These states are only entered through manual user intervention |
| 77 | 'reboot': EnbSendRebootState(self, when_done='wait_reboot'), |
| 78 | 'wait_reboot': WaitRebootResponseState(self, when_done='wait_post_reboot_inform'), |
| 79 | 'wait_post_reboot_inform': WaitInformMRebootState(self, when_done='wait_empty', when_timeout='wait_inform'), |
| 80 | # The states below are entered when an unexpected message type is |
| 81 | # received |
| 82 | 'unexpected_fault': ErrorState(self, inform_transition_target='wait_inform'), |
| 83 | } |
| 84 | |
| 85 | @property |
| 86 | def device_name(self) -> str: |
| 87 | return EnodebDeviceName.BAICELLS_QAFA |
| 88 | |
| 89 | @property |
| 90 | def data_model_class(self) -> Type[DataModel]: |
| 91 | return BaicellsQAFATrDataModel |
| 92 | |
| 93 | @property |
| 94 | def config_postprocessor(self) -> EnodebConfigurationPostProcessor: |
| 95 | return BaicellsQAFATrConfigurationInitializer() |
| 96 | |
| 97 | @property |
| 98 | def state_map(self) -> Dict[str, EnodebAcsState]: |
| 99 | return self._state_map |
| 100 | |
| 101 | @property |
| 102 | def disconnected_state_name(self) -> str: |
| 103 | return 'wait_inform' |
| 104 | |
| 105 | @property |
| 106 | def unexpected_fault_state_name(self) -> str: |
| 107 | return 'unexpected_fault' |
| 108 | |
| 109 | |
| 110 | class BaicellsQAFATrDataModel(DataModel): |
| 111 | """ |
| 112 | Class to represent relevant data model parameters from TR-196/TR-098. |
| 113 | This class is effectively read-only. |
| 114 | |
| 115 | This model specifically targets Qualcomm-based BaiCells units running |
| 116 | QAFA firmware. |
| 117 | |
| 118 | These models have these idiosyncrasies (on account of running TR098): |
| 119 | |
| 120 | - Parameter content root is different (InternetGatewayDevice) |
| 121 | - GetParameter queries with a wildcard e.g. InternetGatewayDevice. do |
| 122 | not respond with the full tree (we have to query all parameters) |
| 123 | - MME status is not exposed - we assume the MME is connected if |
| 124 | the eNodeB is transmitting (OpState=true) |
| 125 | - Parameters such as band capability/duplex config |
| 126 | are rooted under `boardconf.` and not the device config root |
| 127 | - Parameters like Admin state, CellReservedForOperatorUse, |
| 128 | Duplex mode, DL bandwidth and Band capability have different |
| 129 | formats from Intel-based Baicells units, necessitating, |
| 130 | formatting before configuration and transforming values |
| 131 | read from eNodeB state. |
| 132 | - Num PLMNs is not reported by these units |
| 133 | """ |
| 134 | # Mapping of TR parameter paths to aliases |
| 135 | DEVICE_PATH = 'InternetGatewayDevice.' |
| 136 | FAPSERVICE_PATH = DEVICE_PATH + 'Services.FAPService.1.' |
| 137 | EEPROM_PATH = 'boardconf.status.eepromInfo.' |
| 138 | PARAMETERS = { |
| 139 | # Top-level objects |
| 140 | ParameterName.DEVICE: TrParam(DEVICE_PATH, True, TrParameterType.OBJECT, False), |
| 141 | ParameterName.FAP_SERVICE: TrParam(FAPSERVICE_PATH, True, TrParameterType.OBJECT, False), |
| 142 | |
| 143 | # Qualcomm units do not expose MME_Status (We assume that the eNB is broadcasting state is connected to the MME) |
| 144 | ParameterName.MME_STATUS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False), |
| 145 | ParameterName.GPS_LAT: TrParam(DEVICE_PATH + 'FAP.GPS.latitude', True, TrParameterType.STRING, False), |
| 146 | ParameterName.GPS_LONG: TrParam(DEVICE_PATH + 'FAP.GPS.longitude', True, TrParameterType.STRING, False), |
| 147 | ParameterName.SW_VERSION: TrParam(DEVICE_PATH + 'DeviceInfo.SoftwareVersion', True, TrParameterType.STRING, False), |
| 148 | ParameterName.SERIAL_NUMBER: TrParam(DEVICE_PATH + 'DeviceInfo.SerialNumber', True, TrParameterType.STRING, False), |
| 149 | |
| 150 | # Capabilities |
| 151 | ParameterName.DUPLEX_MODE_CAPABILITY: TrParam(EEPROM_PATH + 'div_multiple', True, TrParameterType.STRING, False), |
| 152 | ParameterName.BAND_CAPABILITY: TrParam(EEPROM_PATH + 'work_mode', True, TrParameterType.STRING, False), |
| 153 | |
| 154 | # RF-related parameters |
| 155 | ParameterName.EARFCNDL: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.EARFCNDL', True, TrParameterType.INT, False), |
Wei-Yu Chen | 8d06416 | 2022-05-27 21:06:55 +0800 | [diff] [blame] | 156 | ParameterName.PCI1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.PhyCellID', True, TrParameterType.INT, False), |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 157 | ParameterName.DL_BANDWIDTH: TrParam(DEVICE_PATH + 'Services.RfConfig.1.RfCarrierCommon.carrierBwMhz', True, TrParameterType.INT, False), |
| 158 | ParameterName.SUBFRAME_ASSIGNMENT: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.PHY.TDDFrame.SubFrameAssignment', True, 'bool', False), |
| 159 | ParameterName.SPECIAL_SUBFRAME_PATTERN: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.PHY.TDDFrame.SpecialSubframePatterns', True, TrParameterType.INT, False), |
| 160 | ParameterName.CELL_ID: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.Common.CellIdentity', True, TrParameterType.UNSIGNED_INT, False), |
| 161 | |
| 162 | # Other LTE parameters |
| 163 | ParameterName.ADMIN_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.AdminState', False, TrParameterType.STRING, False), |
| 164 | ParameterName.OP_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False), |
| 165 | ParameterName.RF_TX_STATUS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False), |
| 166 | |
| 167 | # Core network parameters |
Wei-Yu Chen | 8d06416 | 2022-05-27 21:06:55 +0800 | [diff] [blame] | 168 | ParameterName.MME_ADDRESS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkServerList', True, TrParameterType.STRING, False), |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 169 | ParameterName.MME_PORT: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkPort', True, TrParameterType.INT, False), |
| 170 | # This parameter is standard but doesn't exist |
| 171 | # ParameterName.NUM_PLMNS: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNListNumberOfEntries', True, TrParameterType.INT, False), |
Wei-Yu Chen | 8d06416 | 2022-05-27 21:06:55 +0800 | [diff] [blame] | 172 | ParameterName.TAC1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.TAC', True, TrParameterType.INT, False), |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 173 | ParameterName.IP_SEC_ENABLE: TrParam('boardconf.ipsec.ipsecConfig.onBoot', False, TrParameterType.BOOLEAN, False), |
| 174 | |
| 175 | # Management server parameters |
| 176 | ParameterName.PERIODIC_INFORM_ENABLE: TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformEnable', False, TrParameterType.BOOLEAN, False), |
| 177 | ParameterName.PERIODIC_INFORM_INTERVAL: TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformInterval', False, TrParameterType.INT, False), |
| 178 | |
| 179 | # Performance management parameters |
| 180 | ParameterName.PERF_MGMT_ENABLE: TrParam(DEVICE_PATH + 'FAP.PerfMgmt.Config.Enable', False, TrParameterType.BOOLEAN, False), |
| 181 | ParameterName.PERF_MGMT_UPLOAD_INTERVAL: TrParam(DEVICE_PATH + 'FAP.PerfMgmt.Config.PeriodicUploadInterval', False, TrParameterType.INT, False), |
| 182 | ParameterName.PERF_MGMT_UPLOAD_URL: TrParam(DEVICE_PATH + 'FAP.PerfMgmt.Config.URL', False, TrParameterType.STRING, False), |
| 183 | } |
| 184 | |
| 185 | NUM_PLMNS_IN_CONFIG = 6 |
| 186 | TRANSFORMS_FOR_ENB = { |
| 187 | ParameterName.CELL_BARRED: transform_for_enb.invert_cell_barred, |
| 188 | } |
| 189 | for i in range(1, NUM_PLMNS_IN_CONFIG + 1): |
| 190 | TRANSFORMS_FOR_ENB[ParameterName.PLMN_N_CELL_RESERVED % i] = transform_for_enb.cell_reserved |
| 191 | PARAMETERS[ParameterName.PLMN_N % i] = TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.' % i, True, TrParameterType.STRING, False) |
| 192 | PARAMETERS[ParameterName.PLMN_N_CELL_RESERVED % i] = TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.CellReservedForOperatorUse' % i, True, TrParameterType.STRING, False) |
| 193 | PARAMETERS[ParameterName.PLMN_N_ENABLE % i] = TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.Enable' % i, True, TrParameterType.BOOLEAN, False) |
| 194 | PARAMETERS[ParameterName.PLMN_N_PRIMARY % i] = TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.IsPrimary' % i, True, TrParameterType.BOOLEAN, False) |
| 195 | PARAMETERS[ParameterName.PLMN_N_PLMNID % i] = TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.PLMNID' % i, True, TrParameterType.STRING, False) |
| 196 | |
| 197 | TRANSFORMS_FOR_ENB[ParameterName.ADMIN_STATE] = transform_for_enb.admin_state |
| 198 | TRANSFORMS_FOR_MAGMA = { |
| 199 | # We don't set these parameters |
| 200 | ParameterName.BAND_CAPABILITY: transform_for_magma.band_capability, |
| 201 | ParameterName.DUPLEX_MODE_CAPABILITY: transform_for_magma.duplex_mode, |
| 202 | } |
| 203 | |
| 204 | @classmethod |
| 205 | def get_parameter(cls, param_name: ParameterName) -> Optional[TrParam]: |
| 206 | return cls.PARAMETERS.get(param_name) |
| 207 | |
| 208 | @classmethod |
| 209 | def _get_magma_transforms( |
| 210 | cls, |
| 211 | ) -> Dict[ParameterName, Callable[[Any], Any]]: |
| 212 | return cls.TRANSFORMS_FOR_MAGMA |
| 213 | |
| 214 | @classmethod |
| 215 | def _get_enb_transforms(cls) -> Dict[ParameterName, Callable[[Any], Any]]: |
| 216 | return cls.TRANSFORMS_FOR_ENB |
| 217 | |
| 218 | @classmethod |
| 219 | def get_load_parameters(cls) -> List[ParameterName]: |
| 220 | """ |
| 221 | Load all the parameters instead of a subset. |
| 222 | """ |
| 223 | return list(cls.PARAMETERS.keys()) |
| 224 | |
| 225 | @classmethod |
| 226 | def get_num_plmns(cls) -> int: |
| 227 | return cls.NUM_PLMNS_IN_CONFIG |
| 228 | |
| 229 | @classmethod |
| 230 | def get_parameter_names(cls) -> List[ParameterName]: |
| 231 | excluded_params = [ |
| 232 | str(ParameterName.DEVICE), |
| 233 | str(ParameterName.FAP_SERVICE), |
| 234 | ] |
| 235 | names = list( |
| 236 | filter( |
| 237 | lambda x: (not str(x).startswith('PLMN')) |
| 238 | and (str(x) not in excluded_params), |
| 239 | cls.PARAMETERS.keys(), |
| 240 | ), |
| 241 | ) |
| 242 | return names |
| 243 | |
| 244 | @classmethod |
| 245 | def get_numbered_param_names( |
| 246 | cls, |
| 247 | ) -> Dict[ParameterName, List[ParameterName]]: |
| 248 | names = {} |
| 249 | for i in range(1, cls.NUM_PLMNS_IN_CONFIG + 1): |
| 250 | params = [] |
| 251 | params.append(ParameterName.PLMN_N_CELL_RESERVED % i) |
| 252 | params.append(ParameterName.PLMN_N_ENABLE % i) |
| 253 | params.append(ParameterName.PLMN_N_PRIMARY % i) |
| 254 | params.append(ParameterName.PLMN_N_PLMNID % i) |
| 255 | names[ParameterName.PLMN_N % i] = params |
| 256 | |
| 257 | return names |
| 258 | |
| 259 | |
| 260 | class BaicellsQAFATrConfigurationInitializer(EnodebConfigurationPostProcessor): |
Wei-Yu Chen | 8d06416 | 2022-05-27 21:06:55 +0800 | [diff] [blame] | 261 | def postprocess(self, desired_cfg: EnodebConfiguration) -> None: |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 262 | |
| 263 | desired_cfg.delete_parameter(ParameterName.ADMIN_STATE) |