blob: ed510d90a810b9d098dca18e375a5a8e7e50aa75 [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 BaicellsHandler(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
93
94 @property
95 def data_model_class(self) -> Type[DataModel]:
96 return BaicellsTrDataModel
97
98 @property
99 def config_postprocessor(self) -> EnodebConfigurationPostProcessor:
100 return BaicellsTrConfigurationInitializer()
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 BaicellsTrDataModel(DataModel):
116 """
117 Class to represent relevant data model parameters from TR-196/TR-098/TR-181.
118 This class is effectively read-only
119
120 This is for any version BaiStation_V100R001C00B110SPC003 or after
121 """
122 # Parameters to query when reading eNodeB config
123 LOAD_PARAMETERS = [ParameterName.DEVICE]
124 # Mapping of TR parameter paths to aliases
125 DEVICE_PATH = 'Device.'
126 FAPSERVICE_PATH = DEVICE_PATH + 'Services.FAPService.1.'
127 PARAMETERS = {
128 # Top-level objects
129 ParameterName.DEVICE: TrParam(DEVICE_PATH, True, TrParameterType.OBJECT, False),
130 ParameterName.FAP_SERVICE: TrParam(FAPSERVICE_PATH, True, TrParameterType.OBJECT, False),
131
132 # Device info parameters
133 ParameterName.GPS_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_GPS_Status', True, TrParameterType.BOOLEAN, False),
134 ParameterName.PTP_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_1588_Status', True, TrParameterType.BOOLEAN, False),
135 ParameterName.MME_STATUS: TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_MME_Status', True, TrParameterType.BOOLEAN, False),
136 ParameterName.REM_STATUS: TrParam(FAPSERVICE_PATH + 'REM.X_BAICELLS_COM_REM_Status', True, TrParameterType.BOOLEAN, False),
137 ParameterName.LOCAL_GATEWAY_ENABLE:
138 TrParam(DEVICE_PATH + 'DeviceInfo.X_BAICELLS_COM_LTE_LGW_Switch', False, TrParameterType.BOOLEAN, False),
139 # Tested Baicells devices were missing this parameter
140 ParameterName.GPS_ENABLE: TrParam(DEVICE_PATH + 'X_BAICELLS_COM_GpsSyncEnable', False, TrParameterType.BOOLEAN, True),
141 ParameterName.GPS_LAT: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLatitude', True, TrParameterType.INT, True),
142 ParameterName.GPS_LONG: TrParam(DEVICE_PATH + 'FAP.GPS.LockedLongitude', True, TrParameterType.INT, True),
143 ParameterName.SW_VERSION: TrParam(DEVICE_PATH + 'DeviceInfo.SoftwareVersion', True, TrParameterType.STRING, False),
144 ParameterName.SERIAL_NUMBER: TrParam(DEVICE_PATH + 'DeviceInfo.SerialNumber', True, TrParameterType.STRING, False),
145
146 # Capabilities
147 ParameterName.DUPLEX_MODE_CAPABILITY: TrParam(
148 FAPSERVICE_PATH + 'Capabilities.LTE.DuplexMode', True, TrParameterType.STRING, False,
149 ),
150 ParameterName.BAND_CAPABILITY: TrParam(FAPSERVICE_PATH + 'Capabilities.LTE.BandsSupported', True, TrParameterType.STRING, False),
151
152 # RF-related parameters
153 ParameterName.EARFCNDL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNDLInUse', True, TrParameterType.INT, False),
154 ParameterName.EARFCNUL: TrParam(FAPSERVICE_PATH + 'X_BAICELLS_COM_LTE.EARFCNULInUse', True, TrParameterType.INT, False),
155 ParameterName.BAND: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.FreqBandIndicator', True, TrParameterType.INT, False),
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800156 ParameterName.PCI1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.PhyCellID', False, TrParameterType.INT, False),
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800157 ParameterName.DL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.DLBandwidth', True, TrParameterType.STRING, False),
158 ParameterName.UL_BANDWIDTH: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.RF.ULBandwidth', True, TrParameterType.STRING, False),
159 ParameterName.SUBFRAME_ASSIGNMENT: TrParam(
160 FAPSERVICE_PATH
161 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SubFrameAssignment', True, TrParameterType.INT, False,
162 ),
163 ParameterName.SPECIAL_SUBFRAME_PATTERN: TrParam(
164 FAPSERVICE_PATH
165 + 'CellConfig.LTE.RAN.PHY.TDDFrame.SpecialSubframePatterns', True, TrParameterType.INT, False,
166 ),
167 ParameterName.CELL_ID: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.RAN.Common.CellIdentity', True, TrParameterType.UNSIGNED_INT, False),
168
169 # Other LTE parameters
170 ParameterName.ADMIN_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.AdminState', False, TrParameterType.BOOLEAN, False),
171 ParameterName.OP_STATE: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.OpState', True, TrParameterType.BOOLEAN, False),
172 ParameterName.RF_TX_STATUS: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.RFTxStatus', True, TrParameterType.BOOLEAN, False),
173
174 # RAN parameters
175 ParameterName.CELL_RESERVED: TrParam(
176 FAPSERVICE_PATH
177 + 'CellConfig.LTE.RAN.CellRestriction.CellReservedForOperatorUse', True, TrParameterType.BOOLEAN, False,
178 ),
179 ParameterName.CELL_BARRED: TrParam(
180 FAPSERVICE_PATH
181 + 'CellConfig.LTE.RAN.CellRestriction.CellBarred', True, TrParameterType.BOOLEAN, False,
182 ),
183
184 # Core network parameters
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800185 ParameterName.MME_ADDRESS: TrParam(
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800186 FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkServerList', True, TrParameterType.STRING, False,
187 ),
188 ParameterName.MME_PORT: TrParam(FAPSERVICE_PATH + 'FAPControl.LTE.Gateway.S1SigLinkPort', True, TrParameterType.INT, False),
189 ParameterName.NUM_PLMNS: TrParam(
190 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNListNumberOfEntries', True, TrParameterType.INT, False,
191 ),
192 ParameterName.PLMN: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.', True, TrParameterType.STRING, False),
193 # PLMN arrays are added below
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800194 ParameterName.TAC1: TrParam(FAPSERVICE_PATH + 'CellConfig.LTE.EPC.TAC', True, TrParameterType.INT, False),
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800195 ParameterName.IP_SEC_ENABLE: TrParam(
196 DEVICE_PATH + 'Services.FAPService.Ipsec.IPSEC_ENABLE', False, TrParameterType.BOOLEAN, False,
197 ),
198 ParameterName.MME_POOL_ENABLE: TrParam(
199 FAPSERVICE_PATH
200 + 'FAPControl.LTE.Gateway.X_BAICELLS_COM_MmePool.Enable', True, TrParameterType.BOOLEAN, False,
201 ),
202
203 # Management server parameters
204 ParameterName.PERIODIC_INFORM_ENABLE:
205 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformEnable', False, TrParameterType.BOOLEAN, False),
206 ParameterName.PERIODIC_INFORM_INTERVAL:
207 TrParam(DEVICE_PATH + 'ManagementServer.PeriodicInformInterval', False, TrParameterType.INT, False),
208
209 # Performance management parameters
210 ParameterName.PERF_MGMT_ENABLE: TrParam(
211 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.Enable', False, TrParameterType.BOOLEAN, False,
212 ),
213 ParameterName.PERF_MGMT_UPLOAD_INTERVAL: TrParam(
214 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.PeriodicUploadInterval', False, TrParameterType.INT, False,
215 ),
216 ParameterName.PERF_MGMT_UPLOAD_URL: TrParam(
217 DEVICE_PATH + 'FAP.PerfMgmt.Config.1.URL', False, TrParameterType.STRING, False,
218 ),
219
220 }
221
222 NUM_PLMNS_IN_CONFIG = 6
223 for i in range(1, NUM_PLMNS_IN_CONFIG + 1):
224 PARAMETERS[(ParameterName.PLMN_N) % i] = TrParam(
225 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.' % i, True, TrParameterType.STRING, False,
226 )
227 PARAMETERS[ParameterName.PLMN_N_CELL_RESERVED % i] = TrParam(
228 FAPSERVICE_PATH
229 + 'CellConfig.LTE.EPC.PLMNList.%d.CellReservedForOperatorUse' % i, True, TrParameterType.BOOLEAN, False,
230 )
231 PARAMETERS[ParameterName.PLMN_N_ENABLE % i] = TrParam(
232 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.Enable' % i, True, TrParameterType.BOOLEAN, False,
233 )
234 PARAMETERS[ParameterName.PLMN_N_PRIMARY % i] = TrParam(
235 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.IsPrimary' % i, True, TrParameterType.BOOLEAN, False,
236 )
237 PARAMETERS[ParameterName.PLMN_N_PLMNID % i] = TrParam(
238 FAPSERVICE_PATH + 'CellConfig.LTE.EPC.PLMNList.%d.PLMNID' % i, True, TrParameterType.STRING, False,
239 )
240
241 TRANSFORMS_FOR_ENB = {
242 ParameterName.DL_BANDWIDTH: transform_for_enb.bandwidth,
243 ParameterName.UL_BANDWIDTH: transform_for_enb.bandwidth,
244 }
245 TRANSFORMS_FOR_MAGMA = {
246 ParameterName.DL_BANDWIDTH: transform_for_magma.bandwidth,
247 ParameterName.UL_BANDWIDTH: transform_for_magma.bandwidth,
248 # We don't set GPS, so we don't need transform for enb
249 ParameterName.GPS_LAT: transform_for_magma.gps_tr181,
250 ParameterName.GPS_LONG: transform_for_magma.gps_tr181,
251 }
252
253 @classmethod
254 def get_parameter(cls, param_name: ParameterName) -> Optional[TrParam]:
255 return cls.PARAMETERS.get(param_name)
256
257 @classmethod
258 def _get_magma_transforms(
259 cls,
260 ) -> Dict[ParameterName, Callable[[Any], Any]]:
261 return cls.TRANSFORMS_FOR_MAGMA
262
263 @classmethod
264 def _get_enb_transforms(cls) -> Dict[ParameterName, Callable[[Any], Any]]:
265 return cls.TRANSFORMS_FOR_ENB
266
267 @classmethod
268 def get_load_parameters(cls) -> List[ParameterName]:
269 return cls.LOAD_PARAMETERS
270
271 @classmethod
272 def get_num_plmns(cls) -> int:
273 return cls.NUM_PLMNS_IN_CONFIG
274
275 @classmethod
276 def get_parameter_names(cls) -> List[ParameterName]:
277 excluded_params = [
278 str(ParameterName.DEVICE),
279 str(ParameterName.FAP_SERVICE),
280 ]
281 names = list(
282 filter(
283 lambda x: (not str(x).startswith('PLMN'))
284 and (str(x) not in excluded_params),
285 cls.PARAMETERS.keys(),
286 ),
287 )
288 return names
289
290 @classmethod
291 def get_numbered_param_names(cls) -> Dict[ParameterName, List[ParameterName]]:
292 names = {}
293 for i in range(1, cls.NUM_PLMNS_IN_CONFIG + 1):
294 params = []
295 params.append(ParameterName.PLMN_N_CELL_RESERVED % i)
296 params.append(ParameterName.PLMN_N_ENABLE % i)
297 params.append(ParameterName.PLMN_N_PRIMARY % i)
298 params.append(ParameterName.PLMN_N_PLMNID % i)
299 names[ParameterName.PLMN_N % i] = params
300 return names
301
302
303class BaicellsTrConfigurationInitializer(EnodebConfigurationPostProcessor):
Wei-Yu Chen8d064162022-05-27 21:06:55 +0800304 def postprocess(self, desired_cfg: EnodebConfiguration) -> None:
Wei-Yu Chen49950b92021-11-08 19:19:18 +0800305 desired_cfg.set_parameter(ParameterName.CELL_BARRED, False)