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 |
| 21 | from voltha.adapters.asfvolt16_olt.protos.bal_pb2 import BalServicer, BalErr |
| 22 | from voltha.adapters.asfvolt16_olt.protos.bal_errno_pb2 import BAL_ERR_OK |
| 23 | |
| 24 | _ = third_party |
| 25 | |
| 26 | log = structlog.get_logger() |
| 27 | |
| 28 | class 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) |