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