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