blob: b7a524f8145b2bb534750fe966a5ed21e9e6bf05 [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 PonSimServicer, PonSimDeviceInfo
20from google.protobuf.empty_pb2 import Empty
21from voltha.protos.ponsim_pb2 import XPonSimServicer
22
23_ = third_party
24
25log = structlog.get_logger()
26
27class FlowUpdateHandler(PonSimServicer):
28
29 def __init__(self, thread_pool, ponsim):
30 self.thread_pool = thread_pool
31 self.ponsim = ponsim
32
33 @twisted_async
34 def GetDeviceInfo(self, request, context):
35 log.info('get-device-info')
36 ports = self.ponsim.get_ports()
37 return PonSimDeviceInfo(
38 nni_port=ports[0],
39 uni_ports=ports[1:]
40 )
41
42 @twisted_async
43 def UpdateFlowTable(self, request, context):
44 log.info('flow-table-update', request=request, port=request.port)
45 if request.port == 0:
46 # by convention this is the olt port
47 self.ponsim.olt_install_flows(request.flows)
48 else:
49 self.ponsim.onu_install_flows(request.port, request.flows)
50 return Empty()
51
52 def GetStats(self, request, context):
53 return self.ponsim.get_stats()
54
55class XPonHandler(XPonSimServicer):
56
57 def __init__(self, thread_pool, x_pon_sim):
58 self.thread_pool = thread_pool
59 self.x_pon_sim = x_pon_sim
60
61 def CreateInterface(self, request, context):
62 self.x_pon_sim.CreateInterface(request)
63 return Empty()
64
65 def UpdateInterface(self, request, context):
66 self.x_pon_sim.UpdateInterface(request)
67 return Empty()
68
69 def RemoveInterface(self, request, context):
70 self.x_pon_sim.RemoveInterface(request)
71 return Empty()