blob: 1b7c4d4bbd10902d0bb33543f863c43ba6b31830 [file] [log] [blame]
Shad Ansarida0f3a42017-07-19 09:51:06 -07001#
2# Copyright 2017 the original author or authors.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import structlog
17from common.utils.grpc_utils import twisted_async
18from voltha.protos import third_party
19from voltha.protos.ponsim_pb2 import PonSimDeviceInfo
20from google.protobuf.empty_pb2 import Empty
Scott Bakerd865fa22018-11-07 11:45:28 -080021from voltha.adapters.asfvolt16_olt.protos.bal_pb2_grpc import BalServicer
22from voltha.adapters.asfvolt16_olt.protos.bal_pb2 BalErr
Shad Ansarida0f3a42017-07-19 09:51:06 -070023from voltha.adapters.asfvolt16_olt.protos.bal_errno_pb2 import BAL_ERR_OK
24
25_ = third_party
26
27log = structlog.get_logger()
28
29class BalHandler(BalServicer):
30
31 def __init__(self, thread_pool, ponsim):
32 self.thread_pool = thread_pool
33 self.ponsim = ponsim
34
35 @twisted_async
36 def GetDeviceInfo(self, request, context):
37 log.info('get-device-info')
38 ports = self.ponsim.get_ports()
39 return PonSimDeviceInfo(
40 nni_port=ports[0],
41 uni_ports=ports[1:]
42 )
43
44 @twisted_async
45 def UpdateFlowTable(self, request, context):
46 log.info('flow-table-update', request=request, port=request.port)
47 if request.port == 0:
48 # by convention this is the olt port
49 self.ponsim.olt_install_flows(request.flows)
50 else:
51 self.ponsim.onu_install_flows(request.port, request.flows)
52 return Empty()
53
54 def GetStats(self, request, context):
55 return self.ponsim.get_stats()
56
57 def BalApiInit(self, request, context):
58 log.info('olt-connection-successful', request=request)
59 return BalErr(err=BAL_ERR_OK)
60
61 def BalApiFinish(self, request, context):
62 log.info('BalApi', request=request)
63 return BalErr(err=BAL_ERR_OK)
64
65 def BalCfgSet(self, request, context):
66 log.info('olt-activation-successful', request=request)
67 return BalErr(err=BAL_ERR_OK)
68
69 def BalAccessTerminalCfgSet(self, request, context):
70 log.info('olt-activation-successful', request=request)
71 return BalErr(err=BAL_ERR_OK)
72
73 def BalCfgClear(self, request, context):
74 log.info('BalCfClear', request=request)
75 return BalErr(err=BAL_ERR_OK)