blob: ccfec38f83ae609bd6935a2deea7259687451297 [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()
Nikolay Titov176f1db2017-08-10 12:38:43 -040072
73 def CreateTcont(self, request, context):
74 self.x_pon_sim.CreateTcont(
75 request.tconts_config_data,
76 request.traffic_descriptor_profile_config_data)
77 return Empty()
78
79 def UpdateTcont(self, request, context):
80 self.x_pon_sim.UpdateTcont(
81 request.tconts_config_data,
82 request.traffic_descriptor_profile_config_data)
83 return Empty()
84
85 def RemoveTcont(self, request, context):
86 self.x_pon_sim.RemoveTcont(
87 request.tconts_config_data,
88 request.traffic_descriptor_profile_config_data)
89 return Empty()
90
91 def CreateGemport(self, request, context):
92 self.x_pon_sim.CreateGemport(request)
93 return Empty()
94
95 def UpdateGemport(self, request, context):
96 self.x_pon_sim.UpdateGemport(request)
97 return Empty()
98
99 def RemoveGemport(self, request, context):
100 self.x_pon_sim.RemoveGemport(request)
101 return Empty()
102
103 def CreateMulticastGemport(self, request, context):
104 self.x_pon_sim.CreateMulticastGemport(request)
105 return Empty()
106
107 def UpdateMulticastGemport(self, request, context):
108 self.x_pon_sim.UpdateMulticastGemport(request)
109 return Empty()
110
111 def RemoveMulticastGemport(self, request, context):
112 self.x_pon_sim.RemoveMulticastGemport(request)
113 return Empty()
114
115 def CreateMulticastDistributionSet(self, request, context):
116 self.x_pon_sim.CreateMulticastDistributionSet(request)
117 return Empty()
118
119 def UpdateMulticastDistributionSet(self, request, context):
120 self.x_pon_sim.UpdateMulticastDistributionSet(request)
121 return Empty()
122
123 def RemoveMulticastDistributionSet(self, request, context):
124 self.x_pon_sim.RemoveMulticastDistributionSet(request)
125 return Empty()