blob: ed4899d1cd720bd3dcbf4cb58c4f108ed96c0859 [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 CheckOptionalParamsState,
24 DeleteObjectsState,
25 EnbSendRebootState,
26 EndSessionState,
27 EnodebAcsState,
28 ErrorState,
29 GetObjectParametersState,
30 GetParametersState,
31 SendGetTransientParametersState,
32 SetParameterValuesState,
33 WaitEmptyMessageState,
34 WaitGetObjectParametersState,
35 WaitGetParametersState,
36 WaitGetTransientParametersState,
37 WaitInformMRebootState,
38 WaitInformState,
39 WaitRebootResponseState,
40 WaitSetParameterValuesState,
41)
42
43
44class BaicellsRTSHandler(BasicEnodebAcsStateMachine):
45 def __init__(
46 self,
47 service: MagmaService,
48 ) -> None:
49 self._state_map = {}
50 super().__init__(service=service, use_param_key=False)
51
52 def reboot_asap(self) -> None:
53 self.transition('reboot')
54
55 def is_enodeb_connected(self) -> bool:
56 return not isinstance(self.state, WaitInformState)
57
58 def _init_state_map(self) -> None:
59 self._state_map = {
60 'wait_inform': WaitInformState(self, when_done='wait_empty', when_boot=None),
61 'wait_empty': WaitEmptyMessageState(self, when_done='get_transient_params', when_missing='check_optional_params'),
62 'check_optional_params': CheckOptionalParamsState(self, when_done='get_transient_params'),
63 'get_transient_params': SendGetTransientParametersState(self, when_done='wait_get_transient_params'),
64 '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'),
65 'get_params': GetParametersState(self, when_done='wait_get_params'),
66 'wait_get_params': WaitGetParametersState(self, when_done='get_obj_params'),
67 'get_obj_params': GetObjectParametersState(self, when_done='wait_get_obj_params'),
68 'wait_get_obj_params': WaitGetObjectParametersState(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='reboot'),
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 'reboot': EnbSendRebootState(self, when_done='wait_reboot'),
77 'wait_reboot': WaitRebootResponseState(self, when_done='wait_post_reboot_inform'),
78 'wait_post_reboot_inform': WaitInformMRebootState(self, when_done='wait_empty_post_reboot', when_timeout='wait_inform_post_reboot'),
79 'wait_inform_post_reboot': WaitInformState(self, when_done='wait_empty_post_reboot', when_boot=None),
80 'wait_empty_post_reboot': WaitEmptyMessageState(self, when_done='get_transient_params', when_missing='check_optional_params'),
81 # The states below are entered when an unexpected message type is
82 # received
83 'unexpected_fault': ErrorState(self),
84 }
85
86 @property
87 def device_name(self) -> str:
88 return EnodebDeviceName.BAICELLS_RTS
89
90 @property
91 def data_model_class(self) -> Type[DataModel]:
92 return BaicellsRTSTrDataModel
93
94 @property
95 def config_postprocessor(self) -> EnodebConfigurationPostProcessor:
96 return BaicellsRTSTrConfigurationInitializer()
97
98 @property
99 def state_map(self) -> Dict[str, EnodebAcsState]:
100 return self._state_map
101
102 @property
103 def disconnected_state_name(self) -> str:
104 return 'wait_inform'
105
106 @property
107 def unexpected_fault_state_name(self) -> str:
108 return 'unexpected_fault'
109
110
111class BaicellsRTSTrDataModel(DataModel):
112 """
113 Class to represent relevant data model parameters from TR-196/TR-098/TR-181.
114 This class is effectively read-only
115
116 This is for any version beginning with BaiBS_ or after
117 """
118 # Parameters to query when reading eNodeB config
119 LOAD_PARAMETERS = [ParameterName.DEVICE]
120 # Mapping of TR parameter paths to aliases
121 DEVICE_PATH = 'Device.'
122 FAPSERVICE_PATH = DEVICE_PATH + 'Services.FAPService.1.'
123 PARAMETERS = {
124 # Top-level objects
125 ParameterName.DEVICE: TrParam(DEVICE_PATH, True, TrParameterType.OBJECT, False),
126 ParameterName.FAP_SERVICE: TrParam(FAPSERVICE_PATH, True, TrParameterType.OBJECT, False),
127
128 # Device info parameters
129 ParameterName.GPS_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_GPS_Status', True, TrParameterType.BOOLEAN, False),
130 ParameterName.PTP_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_1588_Status', True, TrParameterType.BOOLEAN, False),
131 ParameterName.MME_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_MME_Status', True, TrParameterType.BOOLEAN, False),
132 ParameterName.REM_STATUS: TrParam(FAPSERVICE_PATH + 'REM.X_BAICELLS_COM_REM_Status', True, TrParameterType.BOOLEAN, False),
133 ParameterName.LOCAL_GATEWAY_ENABLE:
134 TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_LTE_LGW_Switch', False, TrParameterType.BOOLEAN, False),
135 # Tested Baicells devices were missing this parameter
136 ParameterName.GPS_ENABLE: TrParam(DEVICE_PATH + 'X_BAICELLS_COM_GpsSyncEnable', False, TrParameterType.BOOLEAN, True),
137 ParameterName.GPS_LAT: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLatitude', True, TrParameterType.INT, True),
138 ParameterName.GPS_LONG: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLongitude', True, TrParameterType.INT, True),
139 ParameterName.SW_VERSION: TrParam(DEVICE_PATH + 'DeviceInfo.SoftwareVersion', True, TrParameterType.STRING, False),
140 ParameterName.SERIAL_NUMBER: TrParam(DEVICE_PATH + 'DeviceInfo.SerialNumber', True, TrParameterType.STRING, False),
141
142 # Capabilities
143 ParameterName.DUPLEX_MODE_CAPABILITY: TrParam(
144 FAPSERVICE_PATH + 'Capabilities.LTE.DuplexMode', True, TrParameterType.STRING, False,
145 ),
146 ParameterName.BAND_CAPABILITY: TrParam(FAPSERVICE_PATH + 'Capabilities.LTE.BandsSupported', True, TrParameterType.STRING, False),
147
148 # RF-related parameters
149 ParameterName.EARFCNDL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNDLInUse', True, TrParameterType.INT, False),
150 ParameterName.EARFCNUL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNULInUse', True, TrParameterType.INT, False),
151 ParameterName.BAND: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.FreqBandIndicator', True, TrParameterType.INT, False),
152 ParameterName.PCI: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.PhyCellID', False, TrParameterType.INT, False),
153 ParameterName.DL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.DLBandwidth', True, TrParameterType.STRING, False),
154 ParameterName.UL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.ULBandwidth', True, TrParameterType.STRING, False),
155 ParameterName.SUBFRAME_ASSIGNMENT: TrParam(
156 FAPSERVICE_PATH
157 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SubFrameAssignment', True, TrParameterType.INT, False,
158 ),
159 ParameterName.SPECIAL_SUBFRAME_PATTERN: TrParam(
160 FAPSERVICE_PATH
161 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SpecialSubframePatterns', True, TrParameterType.INT, False,
162 ),
163 ParameterName.CELL_ID: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.Common.CellIdentity', True, TrParameterType.UNSIGNED_INT, False),
164
165 # Other LTE parameters
166 ParameterName.ADMIN_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.AdminState', False, TrParameterType.BOOLEAN, False),
167 ParameterName.OP_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False),
168 ParameterName.RF_TX_STATUS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.RFTxStatus', True, TrParameterType.BOOLEAN, False),
169
170 # RAN parameters
171 ParameterName.CELL_RESERVED: TrParam(
172 FAPSERVICE_PATH
173 + 'CellConfig.LTE.RAN.CellRestriction.CellReservedForOperatorUse', True, TrParameterType.BOOLEAN, False,
174 ),
175 ParameterName.CELL_BARRED: TrParam(
176 FAPSERVICE_PATH
177 + 'CellConfig.LTE.RAN.CellRestriction.CellBarred', True, TrParameterType.BOOLEAN, False,
178 ),
179
180 # Core network parameters
181 ParameterName.MME_IP: TrParam(
182 FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkServerList', True, TrParameterType.STRING, False,
183 ),
184 ParameterName.MME_PORT: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkPort', True, TrParameterType.INT, False),
185 ParameterName.NUM_PLMNS: TrParam(
186 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNListNumberOfEntries', True, TrParameterType.INT, False,
187 ),
188 ParameterName.PLMN: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.', True, TrParameterType.STRING, False),
189 # PLMN arrays are added below
190 ParameterName.TAC: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.TAC', True, TrParameterType.INT, False),
191 ParameterName.IP_SEC_ENABLE: TrParam(
192 DEVICE_PATH + 'Services.FAPService.Ipsec.IPSEC_ENABLE', False, TrParameterType.BOOLEAN, False,
193 ),
194 ParameterName.MME_POOL_ENABLE: TrParam(
195 FAPSERVICE_PATH
196 + 'FAPControl.LTE.Gateway.X_BAICELLS_COM_MmePool.Enable', True, TrParameterType.BOOLEAN, False,
197 ),
198
199 # Management server parameters
200 ParameterName.PERIODIC_INFORM_ENABLE:
201 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformEnable', False, TrParameterType.BOOLEAN, False),
202 ParameterName.PERIODIC_INFORM_INTERVAL:
203 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformInterval', False, TrParameterType.INT, False),
204
205 # Performance management parameters
206 ParameterName.PERF_MGMT_ENABLE: TrParam(
207 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.Enable', False, TrParameterType.BOOLEAN, False,
208 ),
209 ParameterName.PERF_MGMT_UPLOAD_INTERVAL: TrParam(
210 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.PeriodicUploadInterval', False, TrParameterType.INT, False,
211 ),
212 ParameterName.PERF_MGMT_UPLOAD_URL: TrParam(
213 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.URL', False, TrParameterType.STRING, False,
214 ),
215
216 }
217
218 NUM_PLMNS_IN_CONFIG = 6
219 for i in range(1, NUM_PLMNS_IN_CONFIG + 1):
220 PARAMETERS[(ParameterName.PLMN_N) % i] = TrParam(
221 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.' % i, True, TrParameterType.STRING, False,
222 )
223 PARAMETERS[ParameterName.PLMN_N_CELL_RESERVED % i] = TrParam(
224 FAPSERVICE_PATH
225 + 'CellConfig.LTE.EPC.PLMNList.%d.CellReservedForOperatorUse' % i, True, TrParameterType.BOOLEAN, False,
226 )
227 PARAMETERS[ParameterName.PLMN_N_ENABLE % i] = TrParam(
228 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.Enable' % i, True, TrParameterType.BOOLEAN, False,
229 )
230 PARAMETERS[ParameterName.PLMN_N_PRIMARY % i] = TrParam(
231 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.IsPrimary' % i, True, TrParameterType.BOOLEAN, False,
232 )
233 PARAMETERS[ParameterName.PLMN_N_PLMNID % i] = TrParam(
234 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.PLMNID' % i, True, TrParameterType.STRING, False,
235 )
236
237 TRANSFORMS_FOR_ENB = {
238 ParameterName.DL_BANDWIDTH: transform_for_enb.bandwidth,
239 ParameterName.UL_BANDWIDTH: transform_for_enb.bandwidth,
240 }
241 TRANSFORMS_FOR_MAGMA = {
242 ParameterName.DL_BANDWIDTH: transform_for_magma.bandwidth,
243 ParameterName.UL_BANDWIDTH: transform_for_magma.bandwidth,
244 # We don't set GPS, so we don't need transform for enb
245 ParameterName.GPS_LAT: transform_for_magma.gps_tr181,
246 ParameterName.GPS_LONG: transform_for_magma.gps_tr181,
247 }
248
249 @classmethod
250 def get_parameter(cls, param_name: ParameterName) -> Optional[TrParam]:
251 return cls.PARAMETERS.get(param_name)
252
253 @classmethod
254 def _get_magma_transforms(
255 cls,
256 ) -> Dict[ParameterName, Callable[[Any], Any]]:
257 return cls.TRANSFORMS_FOR_MAGMA
258
259 @classmethod
260 def _get_enb_transforms(cls) -> Dict[ParameterName, Callable[[Any], Any]]:
261 return cls.TRANSFORMS_FOR_ENB
262
263 @classmethod
264 def get_load_parameters(cls) -> List[ParameterName]:
265 return cls.LOAD_PARAMETERS
266
267 @classmethod
268 def get_num_plmns(cls) -> int:
269 return cls.NUM_PLMNS_IN_CONFIG
270
271 @classmethod
272 def get_parameter_names(cls) -> List[ParameterName]:
273 excluded_params = [
274 str(ParameterName.DEVICE),
275 str(ParameterName.FAP_SERVICE),
276 ]
277 names = list(
278 filter(
279 lambda x: (not str(x).startswith('PLMN'))
280 and (str(x) not in excluded_params),
281 cls.PARAMETERS.keys(),
282 ),
283 )
284 return names
285
286 @classmethod
287 def get_numbered_param_names(cls) -> Dict[ParameterName, List[ParameterName]]:
288 names = {}
289 for i in range(1, cls.NUM_PLMNS_IN_CONFIG + 1):
290 params = []
291 params.append(ParameterName.PLMN_N_CELL_RESERVED % i)
292 params.append(ParameterName.PLMN_N_ENABLE % i)
293 params.append(ParameterName.PLMN_N_PRIMARY % i)
294 params.append(ParameterName.PLMN_N_PLMNID % i)
295 names[ParameterName.PLMN_N % i] = params
296 return names
297
298
299class BaicellsRTSTrConfigurationInitializer(EnodebConfigurationPostProcessor):
300 def postprocess(self, mconfig: Any, service_cfg: Any, desired_cfg: EnodebConfiguration) -> None:
301 desired_cfg.set_parameter(ParameterName.CELL_BARRED, False)