Wei-Yu Chen | ad55cb8 | 2022-02-15 20:07:01 +0800 | [diff] [blame^] | 1 | # 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 Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 5 | |
Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame] | 6 | from typing import NamedTuple, Optional |
| 7 | |
| 8 | from lte.protos.mconfig.mconfigs_pb2 import EnodebD |
| 9 | |
| 10 | EnodebConfig = NamedTuple( |
| 11 | 'EnodebConfig', [ |
| 12 | ('serial_num', str), |
| 13 | ('config', EnodebD.EnodebConfig), |
| 14 | ], |
| 15 | ) |
| 16 | |
| 17 | |
| 18 | def 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 | |
| 30 | def 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 | |
| 46 | def 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 |