blob: f036d67cf424f4652ee447aeb9cfaf52393b2f35 [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
21from voltha.adapters.asfvolt16_olt.protos.bal_pb2 import BalServicer, BalErr
22from voltha.adapters.asfvolt16_olt.protos.bal_errno_pb2 import BAL_ERR_OK
23
24_ = third_party
25
26log = structlog.get_logger()
27
28class BalHandler(BalServicer):
29
30 def __init__(self, thread_pool, ponsim):
31 self.thread_pool = thread_pool
32 self.ponsim = ponsim
33
34 @twisted_async
35 def GetDeviceInfo(self, request, context):
36 log.info('get-device-info')
37 ports = self.ponsim.get_ports()
38 return PonSimDeviceInfo(
39 nni_port=ports[0],
40 uni_ports=ports[1:]
41 )
42
43 @twisted_async
44 def UpdateFlowTable(self, request, context):
45 log.info('flow-table-update', request=request, port=request.port)
46 if request.port == 0:
47 # by convention this is the olt port
48 self.ponsim.olt_install_flows(request.flows)
49 else:
50 self.ponsim.onu_install_flows(request.port, request.flows)
51 return Empty()
52
53 def GetStats(self, request, context):
54 return self.ponsim.get_stats()
55
56 def BalApiInit(self, request, context):
57 log.info('olt-connection-successful', request=request)
58 return BalErr(err=BAL_ERR_OK)
59
60 def BalApiFinish(self, request, context):
61 log.info('BalApi', request=request)
62 return BalErr(err=BAL_ERR_OK)
63
64 def BalCfgSet(self, request, context):
65 log.info('olt-activation-successful', request=request)
66 return BalErr(err=BAL_ERR_OK)
67
68 def BalAccessTerminalCfgSet(self, request, context):
69 log.info('olt-activation-successful', request=request)
70 return BalErr(err=BAL_ERR_OK)
71
72 def BalCfgClear(self, request, context):
73 log.info('BalCfClear', request=request)
74 return BalErr(err=BAL_ERR_OK)