Shad Ansari | da0f3a4 | 2017-07-19 09:51:06 -0700 | [diff] [blame] | 1 | # |
| 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 | # |
| 16 | import structlog |
| 17 | from common.utils.grpc_utils import twisted_async |
| 18 | from voltha.protos import third_party |
| 19 | from voltha.protos.ponsim_pb2 import PonSimDeviceInfo |
| 20 | from google.protobuf.empty_pb2 import Empty |
Scott Baker | d865fa2 | 2018-11-07 11:45:28 -0800 | [diff] [blame] | 21 | from voltha.adapters.asfvolt16_olt.protos.bal_pb2_grpc import BalServicer |
| 22 | from voltha.adapters.asfvolt16_olt.protos.bal_pb2 BalErr |
Shad Ansari | da0f3a4 | 2017-07-19 09:51:06 -0700 | [diff] [blame] | 23 | from voltha.adapters.asfvolt16_olt.protos.bal_errno_pb2 import BAL_ERR_OK |
| 24 | |
| 25 | _ = third_party |
| 26 | |
| 27 | log = structlog.get_logger() |
| 28 | |
| 29 | class 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) |