blob: b4d29db03c19c707dc0f9e1fb3c09b6009d3fe81 [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
Wei-Yu Chen49950b92021-11-08 19:19:18 +08006from typing import NamedTuple, Optional
7
8from lte.protos.mconfig.mconfigs_pb2 import EnodebD
9
10EnodebConfig = NamedTuple(
11 'EnodebConfig', [
12 ('serial_num', str),
13 ('config', EnodebD.EnodebConfig),
14 ],
15)
16
17
18def get_enb_rf_tx_desired(mconfig: EnodebD, enb_serial: str) -> bool:
19 """ True if the mconfig specifies to enable transmit on the eNB """
20 if mconfig.enb_configs_by_serial is not None and \
21 len(mconfig.enb_configs_by_serial) > 0:
22 if enb_serial in mconfig.enb_configs_by_serial:
23 enb_config = mconfig.enb_configs_by_serial[enb_serial]
24 return enb_config.transmit_enabled
25 else:
26 raise KeyError('Missing eNB from mconfig: %s' % enb_serial)
27 return mconfig.allow_enodeb_transmit
28
29
30def is_enb_registered(mconfig: EnodebD, enb_serial: str) -> bool:
31 """
32 True if either:
33 - the eNodeB is registered by serial to the Access Gateway
34 or
35 - the Access Gateway accepts all eNodeB devices
36 """
37 if mconfig.enb_configs_by_serial is not None and \
38 len(mconfig.enb_configs_by_serial) > 0:
39 if enb_serial in mconfig.enb_configs_by_serial:
40 return True
41 else:
42 return False
43 return True
44
45
46def find_enb_by_cell_id(mconfig: EnodebD, cell_id: int) \
47 -> Optional[EnodebConfig]:
48 """
49 Returns eNB config if:
50 - the eNodeB is registered by serial to the Access Gateway
51 - cell ID is found in eNB status by serial
52 else: returns None
53 """
54 if mconfig.enb_configs_by_serial is not None and \
55 len(mconfig.enb_configs_by_serial) > 0:
56 for sn, enb in mconfig.enb_configs_by_serial.items():
57 if cell_id == enb.cell_id:
58 config = EnodebConfig(serial_num=sn, config=enb)
59 return config
60 return None