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