blob: e7e4dde2b16c9089a85f13d174504dbc71ed4468 [file] [log] [blame]
Wei-Yu Chen49950b92021-11-08 19:19:18 +08001"""
2Copyright 2020 The Magma Authors.
3
4This source code is licensed under the BSD-style license found in the
5LICENSE file in the root directory of this source tree.
6
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12"""
13from typing import Dict, Optional
14
15import grpc
16from lte.protos.s1ap_service_pb2_grpc import S1apServiceStub
17from common.service_registry import ServiceRegistry
18from logger import EnodebdLogger as logger
19from orc8r.protos.common_pb2 import Void
20
21S1AP_SERVICE_NAME = "s1ap_service"
22DEFAULT_GRPC_TIMEOUT = 20
23
24
25def get_all_enb_state() -> Optional[Dict[int, int]]:
26 """
27 Make RPC call to 'GetENBState' method of s1ap service
28 """
29 try:
30 chan = ServiceRegistry.get_rpc_channel(
31 S1AP_SERVICE_NAME,
32 ServiceRegistry.LOCAL,
33 )
34 except ValueError:
35 logger.error('Cant get RPC channel to %s', S1AP_SERVICE_NAME)
36 return {}
37 client = S1apServiceStub(chan)
38 try:
39 res = client.GetENBState(Void(), DEFAULT_GRPC_TIMEOUT)
40 return res.enb_state_map
41 except grpc.RpcError as err:
42 logger.warning(
43 "GetEnbState error: [%s] %s",
44 err.code(),
45 err.details(),
46 )
47 return {}