blob: d95cb6d01cebf26388edffd336a99373b40692a0 [file] [log] [blame]
Wei-Yu Chenad55cb82022-02-15 20:07:01 +08001# 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 Chen49950b92021-11-08 19:19:18 +08005
6from typing import Any, Callable, Dict, List, Optional, Type
7
8from common.service import MagmaService
9from data_models import transform_for_enb, transform_for_magma
10from data_models.data_model import DataModel, TrParam
11from data_models.data_model_parameters import (
12 ParameterName,
13 TrParameterType,
14)
15from device_config.enodeb_config_postprocessor import (
16 EnodebConfigurationPostProcessor,
17)
18from device_config.enodeb_configuration import EnodebConfiguration
19from devices.device_utils import EnodebDeviceName
20from state_machines.enb_acs_impl import BasicEnodebAcsStateMachine
21from state_machines.enb_acs_states import (
22 AddObjectsState,
23 BaicellsRemWaitState,
24 CheckOptionalParamsState,
25 DeleteObjectsState,
26 EnbSendRebootState,
27 EndSessionState,
28 EnodebAcsState,
29 ErrorState,
30 GetObjectParametersState,
31 GetParametersState,
32 SendGetTransientParametersState,
33 SetParameterValuesState,
34 WaitEmptyMessageState,
35 WaitGetObjectParametersState,
36 WaitGetParametersState,
37 WaitGetTransientParametersState,
38 WaitInformMRebootState,
39 WaitInformState,
40 WaitRebootResponseState,
41 WaitSetParameterValuesState,
42)
43
44
45class BaicellsOldHandler(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='wait_empty', when_boot='wait_rem'),
62 'wait_rem': BaicellsRemWaitState(self, when_done='wait_inform'),
63 'wait_empty': WaitEmptyMessageState(self, when_done='get_transient_params', when_missing='check_optional_params'),
64 'check_optional_params': CheckOptionalParamsState(self, when_done='get_transient_params'),
65 'get_transient_params': SendGetTransientParametersState(self, when_done='wait_get_transient_params'),
66 'wait_get_transient_params': WaitGetTransientParametersState(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'),
67 'get_params': GetParametersState(self, when_done='wait_get_params'),
68 'wait_get_params': WaitGetParametersState(self, when_done='get_obj_params'),
69 'get_obj_params': GetObjectParametersState(self, when_done='wait_get_obj_params'),
70 'wait_get_obj_params': WaitGetObjectParametersState(self, when_delete='delete_objs', when_add='add_objs', when_set='set_params', when_skip='end_session'),
71 'delete_objs': DeleteObjectsState(self, when_add='add_objs', when_skip='set_params'),
72 'add_objs': AddObjectsState(self, when_done='set_params'),
73 'set_params': SetParameterValuesState(self, when_done='wait_set_params'),
74 'wait_set_params': WaitSetParameterValuesState(self, when_done='check_get_params', when_apply_invasive='reboot'),
75 'check_get_params': GetParametersState(self, when_done='check_wait_get_params', request_all_params=True),
76 'check_wait_get_params': WaitGetParametersState(self, when_done='end_session'),
77 'end_session': EndSessionState(self),
78 'reboot': EnbSendRebootState(self, when_done='wait_reboot'),
79 'wait_reboot': WaitRebootResponseState(self, when_done='wait_post_reboot_inform'),
80 'wait_post_reboot_inform': WaitInformMRebootState(self, when_done='wait_rem_post_reboot', when_timeout='wait_inform_post_reboot'),
81 # After rebooting, we don't need to query optional params again.
82 'wait_inform_post_reboot': WaitInformState(self, when_done='wait_empty_post_reboot', when_boot='wait_rem_post_reboot'),
83 'wait_rem_post_reboot': BaicellsRemWaitState(self, when_done='wait_inform_post_reboot'),
84 'wait_empty_post_reboot': WaitEmptyMessageState(self, when_done='get_transient_params', when_missing='check_optional_params'),
85 # The states below are entered when an unexpected message type is
86 # received
87 'unexpected_fault': ErrorState(self, inform_transition_target='wait_inform'),
88 }
89
90 @property
91 def device_name(self) -> str:
92 return EnodebDeviceName.BAICELLS_OLD
93
94 @property
95 def data_model_class(self) -> Type[DataModel]:
96 return BaicellsTrOldDataModel
97
98 @property
99 def config_postprocessor(self) -> EnodebConfigurationPostProcessor:
100 return BaicellsTrOldConfigurationInitializer()
101
102 @property
103 def state_map(self) -> Dict[str, EnodebAcsState]:
104 return self._state_map
105
106 @property
107 def disconnected_state_name(self) -> str:
108 return 'wait_inform'
109
110 @property
111 def unexpected_fault_state_name(self) -> str:
112 return 'unexpected_fault'
113
114
115class BaicellsTrOldDataModel(DataModel):
116 """
117 Class to represent relevant data model parameters from
118 TR-196/TR-098/TR-181.
119
120 This class is effectively read-only
121
122 This is for any version before BaiStation_V100R001C00B110SPC003
123
124 Some eNodeBs have a bug where the meaning of the following parameter is
125 inverted:
126 Device.Services.FAPService.1.CellConfig.LTE.EPC.PLMNList.1.CellReservedForOperatorUse
127 I.e. CellReservedForOperatorUse = True in TR-196 results in the relevant
128 SIB parameter being advertised as 'CellReservedForOperatorUse notReserved',
129 and vice versa.
130
131 This issue was fixed in the above SW version, so the flag should be
132 inverted for the all versions PRECEEDING
133
134 The same problem exists for 'cell barred'. See above description
135 """
136 # Parameters to query when reading eNodeB config
137 LOAD_PARAMETERS = [ParameterName.DEVICE]
138 # Mapping of TR parameter paths to aliases
139 DEVICE_PATH = 'Device.'
140 FAPSERVICE_PATH = DEVICE_PATH + 'Services.FAPService.1.'
141 PARAMETERS = {
142 # Top-level objects
143 ParameterName.DEVICE: TrParam(DEVICE_PATH, True, TrParameterType.OBJECT, False),
144 ParameterName.FAP_SERVICE: TrParam(FAPSERVICE_PATH, True, TrParameterType.OBJECT, False),
145
146 # Device info parameters
147 ParameterName.GPS_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_GPS_Status', True, TrParameterType.BOOLEAN, False),
148 ParameterName.PTP_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_1588_Status', True, TrParameterType.BOOLEAN, False),
149 ParameterName.MME_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_MME_Status', True, TrParameterType.BOOLEAN, False),
150 ParameterName.REM_STATUS: TrParam(FAPSERVICE_PATH + 'REM.X_BAICELLS_COM_REM_Status', True, TrParameterType.BOOLEAN, True),
151 ParameterName.LOCAL_GATEWAY_ENABLE:
152 TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_LTE_LGW_Switch', False, TrParameterType.BOOLEAN, False),
153 ParameterName.GPS_ENABLE: TrParam(DEVICE_PATH + 'X_BAICELLS_COM_GpsSyncEnable', False, TrParameterType.BOOLEAN, True),
154 ParameterName.GPS_LAT: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLatitude', True, TrParameterType.INT, True),
155 ParameterName.GPS_LONG: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLongitude', True, TrParameterType.INT, True),
156 ParameterName.SW_VERSION: TrParam(DEVICE_PATH + 'DeviceInfo.SoftwareVersion', True, TrParameterType.STRING, False),
157 ParameterName.SERIAL_NUMBER: TrParam(DEVICE_PATH + 'DeviceInfo.SerialNumber', True, TrParameterType.STRING, False),
158
159 # Capabilities
160 ParameterName.DUPLEX_MODE_CAPABILITY: TrParam(
161 FAPSERVICE_PATH + 'Capabilities.LTE.DuplexMode', True, TrParameterType.STRING, False,
162 ),
163 ParameterName.BAND_CAPABILITY: TrParam(FAPSERVICE_PATH + 'Capabilities.LTE.BandsSupported', True, TrParameterType.STRING, False),
164
165 # RF-related parameters
166 ParameterName.EARFCNDL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNDLInUse', True, TrParameterType.INT, False),
167 ParameterName.EARFCNUL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNULInUse', True, TrParameterType.INT, False),
168 ParameterName.BAND: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.FreqBandIndicator', True, TrParameterType.INT, False),
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800169 ParameterName.PCI1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.PhyCellID', True, TrParameterType.INT, False),
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800170 ParameterName.DL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.DLBandwidth', True, TrParameterType.STRING, False),
171 ParameterName.UL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.ULBandwidth', True, TrParameterType.STRING, False),
172 ParameterName.SUBFRAME_ASSIGNMENT: TrParam(
173 FAPSERVICE_PATH
174 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SubFrameAssignment', True, TrParameterType.INT, False,
175 ),
176 ParameterName.SPECIAL_SUBFRAME_PATTERN: TrParam(
177 FAPSERVICE_PATH
178 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SpecialSubframePatterns', True, TrParameterType.INT, False,
179 ),
180 ParameterName.CELL_ID: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.Common.CellIdentity', True, TrParameterType.UNSIGNED_INT, False),
181
182 # Other LTE parameters
183 ParameterName.ADMIN_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.AdminState', False, TrParameterType.BOOLEAN, False),
184 ParameterName.OP_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False),
185 ParameterName.RF_TX_STATUS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.RFTxStatus', True, TrParameterType.BOOLEAN, False),
186
187 # RAN parameters
188 ParameterName.CELL_RESERVED: TrParam(
189 FAPSERVICE_PATH
190 + 'CellConfig.LTE.RAN.CellRestriction.CellReservedForOperatorUse', True, TrParameterType.BOOLEAN, False,
191 ),
192 ParameterName.CELL_BARRED: TrParam(
193 FAPSERVICE_PATH
194 + 'CellConfig.LTE.RAN.CellRestriction.CellBarred', True, TrParameterType.BOOLEAN, False,
195 ),
196
197 # Core network parameters
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800198 ParameterName.MME_ADDRESS: TrParam(
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800199 FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkServerList', True, TrParameterType.STRING, False,
200 ),
201 ParameterName.MME_PORT: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkPort', True, TrParameterType.INT, False),
202 ParameterName.NUM_PLMNS: TrParam(
203 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNListNumberOfEntries', True, TrParameterType.INT, False,
204 ),
205 ParameterName.PLMN: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.', True, TrParameterType.STRING, False),
206 # PLMN arrays are added below
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800207 ParameterName.TAC1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.TAC', True, TrParameterType.INT, False),
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800208 ParameterName.IP_SEC_ENABLE: TrParam(
209 DEVICE_PATH + 'Services.FAPService.Ipsec.IPSEC_ENABLE', False, TrParameterType.BOOLEAN, False,
210 ),
211 ParameterName.MME_POOL_ENABLE: TrParam(
212 FAPSERVICE_PATH +
213 'FAPControl.LTE.Gateway.X_BAICELLS_COM_MmePool.Enable', True, TrParameterType.BOOLEAN, True,
214 ),
215
216 # Management server parameters
217 ParameterName.PERIODIC_INFORM_ENABLE:
218 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformEnable', False, TrParameterType.BOOLEAN, False),
219 ParameterName.PERIODIC_INFORM_INTERVAL:
220 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformInterval', False, TrParameterType.INT, False),
221
222 # Performance management parameters
223 ParameterName.PERF_MGMT_ENABLE: TrParam(
224 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.Enable', False, TrParameterType.BOOLEAN, False,
225 ),
226 ParameterName.PERF_MGMT_UPLOAD_INTERVAL: TrParam(
227 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.PeriodicUploadInterval', False, TrParameterType.INT, False,
228 ),
229 ParameterName.PERF_MGMT_UPLOAD_URL: TrParam(
230 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.URL', False, TrParameterType.STRING, False,
231 ),
232
233 }
234
235 NUM_PLMNS_IN_CONFIG = 6
236 for i in range(1, NUM_PLMNS_IN_CONFIG + 1):
237 PARAMETERS[(ParameterName.PLMN_N) % i] = TrParam(
238 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.' % i, True, TrParameterType.STRING, False,
239 )
240 PARAMETERS[ParameterName.PLMN_N_CELL_RESERVED % i] = TrParam(
241 FAPSERVICE_PATH +
242 'CellConfig.LTE.EPC.PLMNList.%d.CellReservedForOperatorUse' % i, True, TrParameterType.BOOLEAN, False,
243 )
244 PARAMETERS[ParameterName.PLMN_N_ENABLE % i] = TrParam(
245 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.Enable' % i, True, TrParameterType.BOOLEAN, False,
246 )
247 PARAMETERS[ParameterName.PLMN_N_PRIMARY % i] = TrParam(
248 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.IsPrimary' % i, True, TrParameterType.BOOLEAN, False,
249 )
250 PARAMETERS[ParameterName.PLMN_N_PLMNID % i] = TrParam(
251 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.PLMNID' % i, True, TrParameterType.STRING, False,
252 )
253
254 TRANSFORMS_FOR_ENB = {
255 ParameterName.DL_BANDWIDTH: transform_for_enb.bandwidth,
256 ParameterName.UL_BANDWIDTH: transform_for_enb.bandwidth,
257 ParameterName.CELL_BARRED: transform_for_enb.invert_cell_barred,
258 ParameterName.CELL_RESERVED: transform_for_enb.invert_cell_reserved,
259 }
260 TRANSFORMS_FOR_MAGMA = {
261 ParameterName.DL_BANDWIDTH: transform_for_magma.bandwidth,
262 ParameterName.UL_BANDWIDTH: transform_for_magma.bandwidth,
263 # We don't set GPS, so we don't need transform for enb
264 ParameterName.GPS_LAT: transform_for_magma.gps_tr181,
265 ParameterName.GPS_LONG: transform_for_magma.gps_tr181,
266 }
267
268 @classmethod
269 def get_parameter(cls, param_name: ParameterName) -> Optional[TrParam]:
270 return cls.PARAMETERS.get(param_name)
271
272 @classmethod
273 def _get_magma_transforms(
274 cls,
275 ) -> Dict[ParameterName, Callable[[Any], Any]]:
276 return cls.TRANSFORMS_FOR_MAGMA
277
278 @classmethod
279 def _get_enb_transforms(cls) -> Dict[ParameterName, Callable[[Any], Any]]:
280 return cls.TRANSFORMS_FOR_ENB
281
282 @classmethod
283 def get_load_parameters(cls) -> List[ParameterName]:
284 return cls.LOAD_PARAMETERS
285
286 @classmethod
287 def get_num_plmns(cls) -> int:
288 return cls.NUM_PLMNS_IN_CONFIG
289
290 @classmethod
291 def get_parameter_names(cls) -> List[ParameterName]:
292 excluded_params = [
293 str(ParameterName.DEVICE),
294 str(ParameterName.FAP_SERVICE),
295 ]
296 names = list(
297 filter(
298 lambda x: (not str(x).startswith('PLMN'))
299 and (str(x) not in excluded_params),
300 cls.PARAMETERS.keys(),
301 ),
302 )
303 return names
304
305 @classmethod
306 def get_numbered_param_names(cls) -> Dict[ParameterName, List[ParameterName]]:
307 names = {}
308 for i in range(1, cls.NUM_PLMNS_IN_CONFIG + 1):
309 params = []
310 params.append(ParameterName.PLMN_N_CELL_RESERVED % i)
311 params.append(ParameterName.PLMN_N_ENABLE % i)
312 params.append(ParameterName.PLMN_N_PRIMARY % i)
313 params.append(ParameterName.PLMN_N_PLMNID % i)
314 names[ParameterName.PLMN_N % i] = params
315
316 return names
317
318
319class BaicellsTrOldConfigurationInitializer(EnodebConfigurationPostProcessor):
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800320 def postprocess(self, desired_cfg: EnodebConfiguration) -> None:
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800321 desired_cfg.set_parameter(ParameterName.CELL_BARRED, False)