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 Dict, Optional |
| 7 | |
| 8 | import grpc |
| 9 | from lte.protos.s1ap_service_pb2_grpc import S1apServiceStub |
| 10 | from common.service_registry import ServiceRegistry |
| 11 | from logger import EnodebdLogger as logger |
| 12 | from orc8r.protos.common_pb2 import Void |
| 13 | |
| 14 | S1AP_SERVICE_NAME = "s1ap_service" |
| 15 | DEFAULT_GRPC_TIMEOUT = 20 |
| 16 | |
| 17 | |
| 18 | def get_all_enb_state() -> Optional[Dict[int, int]]: |
| 19 | """ |
| 20 | Make RPC call to 'GetENBState' method of s1ap service |
| 21 | """ |
| 22 | try: |
| 23 | chan = ServiceRegistry.get_rpc_channel( |
| 24 | S1AP_SERVICE_NAME, |
| 25 | ServiceRegistry.LOCAL, |
| 26 | ) |
| 27 | except ValueError: |
| 28 | logger.error('Cant get RPC channel to %s', S1AP_SERVICE_NAME) |
| 29 | return {} |
| 30 | client = S1apServiceStub(chan) |
| 31 | try: |
| 32 | res = client.GetENBState(Void(), DEFAULT_GRPC_TIMEOUT) |
| 33 | return res.enb_state_map |
| 34 | except grpc.RpcError as err: |
| 35 | logger.warning( |
| 36 | "GetEnbState error: [%s] %s", |
| 37 | err.code(), |
| 38 | err.details(), |
| 39 | ) |
| 40 | return {} |