blob: 7756791dc51d94d00079c1efb42729c1ba0dd772 [file] [log] [blame]
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -08001#
2# Copyright 2018 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
17"""
18Openolt adapter.
19"""
20import arrow
21import grpc
22import structlog
23from google.protobuf.empty_pb2 import Empty
24from google.protobuf.json_format import MessageToDict
25from scapy.layers.inet import Raw
26import json
27from google.protobuf.message import Message
28from grpc._channel import _Rendezvous
29from scapy.layers.l2 import Ether, Dot1Q
30from simplejson import dumps
31from twisted.internet import reactor
32from twisted.internet.defer import inlineCallbacks, returnValue
33from twisted.internet.task import LoopingCall
34
35from python.adapters.common.frameio.frameio import BpfProgramFilter, hexify
36from python.common.utils.asleep import asleep
37from python.common.utils.registry import registry
38from python.adapters.iadapter import OltAdapter
39from python.adapters.kafka.kafka_proxy import get_kafka_proxy
40from python.protos import openolt_pb2
41from python.protos import third_party
42from python.protos.common_pb2 import OperStatus, ConnectStatus
43from python.protos.common_pb2 import LogLevel
44from python.protos.common_pb2 import OperationResp
45from python.protos.inter_container_pb2 import SwitchCapability, PortCapability, \
46 InterAdapterMessageType, InterAdapterResponseBody
Arun Arora5f89fb62018-12-19 08:25:54 +000047from python.protos.device_pb2 import Port, PmConfig, PmConfigs, \
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -080048 DeviceType, DeviceTypes
49from python.protos.adapter_pb2 import Adapter
50from python.protos.adapter_pb2 import AdapterConfig
51
52
53from python.protos.events_pb2 import KpiEvent, KpiEventType, MetricValuePairs
54from python.protos.logical_device_pb2 import LogicalPort
55from python.protos.openflow_13_pb2 import OFPPS_LIVE, OFPPF_FIBER, \
56 OFPPF_1GB_FD, \
57 OFPC_GROUP_STATS, OFPC_PORT_STATS, OFPC_TABLE_STATS, OFPC_FLOW_STATS, \
58 ofp_switch_features, ofp_desc
59from python.protos.openflow_13_pb2 import ofp_port
60from python.protos.ponsim_pb2 import FlowTable, PonSimFrame, PonSimMetricsRequest
61
62_ = third_party
63log = structlog.get_logger()
64#OpenOltDefaults = {
65# 'support_classes': {
66# 'platform': OpenOltPlatform,
67# 'resource_mgr': OpenOltResourceMgr,
68# 'flow_mgr': OpenOltFlowMgr,
69# 'alarm_mgr': OpenOltAlarmMgr,
70# 'stats_mgr': OpenOltStatisticsMgr,
71# 'bw_mgr': OpenOltBW
72# }
73#}
74
75
76class OpenoltAdapter(object):
77 name = 'openolt'
78
79 supported_device_types = [
80 DeviceType(
81 id=name,
82 adapter=name,
83 accepts_bulk_flow_update=True,
84 accepts_direct_logical_flows_update=True
85 )
86 ]
87
Arun Arora5f89fb62018-12-19 08:25:54 +000088 # System Init Methods #
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -080089 def __init__(self, core_proxy, adapter_proxy, config):
Arun Arora5f89fb62018-12-19 08:25:54 +000090 self.adapter_proxy = adapter_proxy
91 self.core_proxy = core_proxy
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -080092 self.config = config
93 self.descriptor = Adapter(
94 id=self.name,
95 vendor='OLT white box vendor',
96 version='0.1',
97 config=config
98 )
Arun Arora5f89fb62018-12-19 08:25:54 +000099 log.debug('openolt.__init__', adapter_proxy=adapter_proxy)
Dinesh Belwalkard1cbf4c2018-12-13 13:34:05 -0800100 self.devices = dict() # device_id -> OpenoltDevice()
101 self.interface = registry('main').get_args().interface
102 self.logical_device_id_to_root_device_id = dict()
103 self.num_devices = 0
104
Arun Arora5f89fb62018-12-19 08:25:54 +0000105 def start(self):
106 log.info('started', interface=self.interface)
107
108 def stop(self):
109 log.info('stopped', interface=self.interface)
110
111
112 # Info Methods #
113 def adapter_descriptor(self):
114 log.debug('get descriptor', interface=self.interface)
115 return self.descriptor
116
117 def device_types(self):
118 log.debug('get device_types', interface=self.interface,
119 items=self.supported_device_types)
120 return DeviceTypes(items=self.supported_device_types)
121
122 def health(self):
123 log.debug('get health', interface=self.interface)
124 raise NotImplementedError()
125
126 def get_device_details(self, device):
127 log.debug('get_device_details', device=device)
128 raise NotImplementedError()
129
130
131 # Device Operation Methods #
132 def change_master_state(self, master):
133 log.debug('change_master_state', interface=self.interface,
134 master=master)
135 raise NotImplementedError()
136
137 def abandon_device(self, device):
138 log.info('abandon-device', device=device)
139 raise NotImplementedError()
140
141
142 # Configuration Methods #
143 def update_flows_incrementally(self, device, flow_changes, group_changes):
144 log.debug('update_flows_incrementally', device=device,
145 flow_changes=flow_changes, group_changes=group_changes)
146 log.info('This device does not allow this, therefore it is Not '
147 'implemented')
148 raise NotImplementedError()
149
150 def update_pm_config(self, device, pm_configs):
151 log.info('update_pm_config - Not implemented yet', device=device,
152 pm_configs=pm_configs)
153 raise NotImplementedError()
154
155 def receive_proxied_message(self, proxy_address, msg):
156 log.debug('receive_proxied_message - Not implemented',
157 proxy_address=proxy_address,
158 proxied_msg=msg)
159 raise NotImplementedError()
160
161 def receive_inter_adapter_message(self, msg):
162 log.info('rx_inter_adapter_msg - Not implemented')
163 raise NotImplementedError()
164
165
166 # Image Operations Methods #
167 def download_image(self, device, request):
168 log.info('image_download - Not implemented yet', device=device,
169 request=request)
170 raise NotImplementedError()
171
172 def get_image_download_status(self, device, request):
173 log.info('get_image_download - Not implemented yet', device=device,
174 request=request)
175 raise NotImplementedError()
176
177 def cancel_image_download(self, device, request):
178 log.info('cancel_image_download - Not implemented yet', device=device)
179 raise NotImplementedError()
180
181 def activate_image_update(self, device, request):
182 log.info('activate_image_update - Not implemented yet',
183 device=device, request=request)
184 raise NotImplementedError()
185
186 def revert_image_update(self, device, request):
187 log.info('revert_image_update - Not implemented yet',
188 device=device, request=request)
189 raise NotImplementedError()
190
191 def self_test_device(self, device):
192 # from voltha.protos.voltha_pb2 import SelfTestResponse
193 log.info('Not implemented yet')
194 raise NotImplementedError()
195
196
197 # PON Operations Methods #
198 def create_interface(self, device, data):
199 log.debug('create-interface - Not implemented - We do not use this',
200 data=data)
201 raise NotImplementedError()
202
203 def update_interface(self, device, data):
204 log.debug('update-interface - Not implemented - We do not use this',
205 data=data)
206 raise NotImplementedError()
207
208 def remove_interface(self, device, data):
209 log.debug('remove-interface - Not implemented - We do not use this',
210 data=data)
211 raise NotImplementedError()
212
213 def receive_onu_detect_state(self, proxy_address, state):
214 log.debug('receive-onu-detect-state - Not implemented - We do not '
215 'use this', proxy_address=proxy_address,
216 state=state)
217 raise NotImplementedError()
218
219 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
220 log.info('create-tcont - Not implemented - We do not use this',
221 tcont_data=tcont_data,
222 traffic_descriptor_data=traffic_descriptor_data)
223 raise NotImplementedError()
224
225 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
226 log.info('update-tcont - Not implemented - We do not use this',
227 tcont_data=tcont_data,
228 traffic_descriptor_data=traffic_descriptor_data)
229 raise NotImplementedError()
230
231 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
232 log.info('remove-tcont - Not implemented - We do not use this',
233 tcont_data=tcont_data,
234 traffic_descriptor_data=traffic_descriptor_data)
235 raise NotImplementedError()
236
237 def create_gemport(self, device, data):
238 log.info('create-gemport - Not implemented - We do not use this',
239 data=data)
240 raise NotImplementedError()
241
242 def update_gemport(self, device, data):
243 log.info('update-gemport - Not implemented - We do not use this',
244 data=data)
245 raise NotImplementedError()
246
247 def remove_gemport(self, device, data):
248 log.info('remove-gemport - Not implemented - We do not use this',
249 data=data)
250 raise NotImplementedError()
251
252 def create_multicast_gemport(self, device, data):
253 log.info('create-mcast-gemport - Not implemented - We do not use '
254 'this', data=data)
255 raise NotImplementedError()
256
257 def update_multicast_gemport(self, device, data):
258 log.info('update-mcast-gemport - Not implemented - We do not use '
259 'this', data=data)
260 raise NotImplementedError()
261
262 def remove_multicast_gemport(self, device, data):
263 log.info('remove-mcast-gemport - Not implemented - We do not use '
264 'this', data=data)
265 raise NotImplementedError()
266
267 def create_multicast_distribution_set(self, device, data):
268 log.info('create-mcast-distribution-set - Not implemented - We do '
269 'not use this', data=data)
270 raise NotImplementedError()
271
272 def update_multicast_distribution_set(self, device, data):
273 log.info('update-mcast-distribution-set - Not implemented - We do '
274 'not use this', data=data)
275 raise NotImplementedError()
276
277 def remove_multicast_distribution_set(self, device, data):
278 log.info('remove-mcast-distribution-set - Not implemented - We do '
279 'not use this', data=data)
280 raise NotImplementedError()
281
282
283 # Alarm Methods #
284 def suppress_alarm(self, filter):
285 log.info('suppress_alarm - Not implemented yet', filter=filter)
286 raise NotImplementedError()
287
288 def unsuppress_alarm(self, filter):
289 log.info('unsuppress_alarm - Not implemented yet', filter=filter)
290 raise NotImplementedError()