Wei-Yu Chen | 49950b9 | 2021-11-08 19:19:18 +0800 | [diff] [blame^] | 1 | """ |
| 2 | Copyright 2020 The Magma Authors. |
| 3 | |
| 4 | This source code is licensed under the BSD-style license found in the |
| 5 | LICENSE file in the root directory of this source tree. |
| 6 | |
| 7 | Unless required by applicable law or agreed to in writing, software |
| 8 | distributed under the License is distributed on an "AS IS" BASIS, |
| 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 10 | See the License for the specific language governing permissions and |
| 11 | limitations under the License. |
| 12 | """ |
| 13 | from typing import NamedTuple, Optional |
| 14 | |
| 15 | from lte.protos.mconfig.mconfigs_pb2 import EnodebD |
| 16 | |
| 17 | EnodebConfig = NamedTuple( |
| 18 | 'EnodebConfig', [ |
| 19 | ('serial_num', str), |
| 20 | ('config', EnodebD.EnodebConfig), |
| 21 | ], |
| 22 | ) |
| 23 | |
| 24 | |
| 25 | def get_enb_rf_tx_desired(mconfig: EnodebD, enb_serial: str) -> bool: |
| 26 | """ True if the mconfig specifies to enable transmit on the eNB """ |
| 27 | if mconfig.enb_configs_by_serial is not None and \ |
| 28 | len(mconfig.enb_configs_by_serial) > 0: |
| 29 | if enb_serial in mconfig.enb_configs_by_serial: |
| 30 | enb_config = mconfig.enb_configs_by_serial[enb_serial] |
| 31 | return enb_config.transmit_enabled |
| 32 | else: |
| 33 | raise KeyError('Missing eNB from mconfig: %s' % enb_serial) |
| 34 | return mconfig.allow_enodeb_transmit |
| 35 | |
| 36 | |
| 37 | def is_enb_registered(mconfig: EnodebD, enb_serial: str) -> bool: |
| 38 | """ |
| 39 | True if either: |
| 40 | - the eNodeB is registered by serial to the Access Gateway |
| 41 | or |
| 42 | - the Access Gateway accepts all eNodeB devices |
| 43 | """ |
| 44 | if mconfig.enb_configs_by_serial is not None and \ |
| 45 | len(mconfig.enb_configs_by_serial) > 0: |
| 46 | if enb_serial in mconfig.enb_configs_by_serial: |
| 47 | return True |
| 48 | else: |
| 49 | return False |
| 50 | return True |
| 51 | |
| 52 | |
| 53 | def find_enb_by_cell_id(mconfig: EnodebD, cell_id: int) \ |
| 54 | -> Optional[EnodebConfig]: |
| 55 | """ |
| 56 | Returns eNB config if: |
| 57 | - the eNodeB is registered by serial to the Access Gateway |
| 58 | - cell ID is found in eNB status by serial |
| 59 | else: returns None |
| 60 | """ |
| 61 | if mconfig.enb_configs_by_serial is not None and \ |
| 62 | len(mconfig.enb_configs_by_serial) > 0: |
| 63 | for sn, enb in mconfig.enb_configs_by_serial.items(): |
| 64 | if cell_id == enb.cell_id: |
| 65 | config = EnodebConfig(serial_num=sn, config=enb) |
| 66 | return config |
| 67 | return None |