blob: 05430a13ea4e71a7c01784e5824ef289c378bd57 [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 Dict, Optional
7
8import grpc
9from lte.protos.s1ap_service_pb2_grpc import S1apServiceStub
10from common.service_registry import ServiceRegistry
11from logger import EnodebdLogger as logger
12from orc8r.protos.common_pb2 import Void
13
14S1AP_SERVICE_NAME = "s1ap_service"
15DEFAULT_GRPC_TIMEOUT = 20
16
17
18def 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 {}