blob: 995be7893e853078ad7d7116d4f7d0795e3096f1 [file] [log] [blame]
Shad Ansari2825d012018-02-22 23:57:46 +00001#
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"""
Shad Ansari2825d012018-02-22 23:57:46 +000020from zope.interface import implementer
Shad Ansarif9d2d102018-06-13 02:15:26 +000021import structlog
Shad Ansari2825d012018-02-22 23:57:46 +000022
23from openolt_device import OpenoltDevice
24from voltha.adapters.interface import IAdapterInterface
25from voltha.protos import third_party
26from voltha.protos.adapter_pb2 import Adapter
27from voltha.protos.adapter_pb2 import AdapterConfig
28from voltha.protos.common_pb2 import LogLevel
Scott Bakerd3190952018-09-04 15:47:28 -070029from voltha.protos.common_pb2 import OperationResp
Shad Ansari2825d012018-02-22 23:57:46 +000030from voltha.protos.device_pb2 import DeviceType, DeviceTypes
Shad Ansari2825d012018-02-22 23:57:46 +000031from voltha.registry import registry
Shad Ansaricd20a6d2018-10-02 14:36:33 +000032from voltha.adapters.openolt.openolt_flow_mgr import OpenOltFlowMgr
33from voltha.adapters.openolt.openolt_alarms import OpenOltAlarmMgr
34from voltha.adapters.openolt.openolt_statistics import OpenOltStatisticsMgr
35from voltha.adapters.openolt.openolt_bw import OpenOltBW
36from voltha.adapters.openolt.openolt_platform import OpenOltPlatform
Girish Gowdru1e77ea02018-09-24 09:10:35 -070037from voltha.adapters.openolt.openolt_resource_manager import OpenOltResourceMgr
Shad Ansari2825d012018-02-22 23:57:46 +000038
39_ = third_party
40log = structlog.get_logger()
41
Shad Ansarif9d2d102018-06-13 02:15:26 +000042
Shad Ansaricd20a6d2018-10-02 14:36:33 +000043OpenOltDefaults = {
44 'support_classes': {
45 'platform': OpenOltPlatform,
Girish Gowdru1e77ea02018-09-24 09:10:35 -070046 'resource_mgr': OpenOltResourceMgr,
Shad Ansaricd20a6d2018-10-02 14:36:33 +000047 'flow_mgr': OpenOltFlowMgr,
48 'alarm_mgr': OpenOltAlarmMgr,
49 'stats_mgr': OpenOltStatisticsMgr,
50 'bw_mgr': OpenOltBW
51 }
52}
53
Shad Ansari78de2be2018-10-12 22:13:54 +000054
Shad Ansari2825d012018-02-22 23:57:46 +000055@implementer(IAdapterInterface)
56class OpenoltAdapter(object):
57 name = 'openolt'
58
59 supported_device_types = [
60 DeviceType(
61 id=name,
62 adapter=name,
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -040063 accepts_bulk_flow_update=True,
64 accepts_direct_logical_flows_update=True
Shad Ansari2825d012018-02-22 23:57:46 +000065 )
66 ]
67
68 def __init__(self, adapter_agent, config):
69 self.adapter_agent = adapter_agent
70 self.config = config
71 self.descriptor = Adapter(
72 id=self.name,
73 vendor='OLT white box vendor',
74 version='0.1',
75 config=AdapterConfig(log_level=LogLevel.INFO)
76 )
77 log.debug('openolt.__init__', adapter_agent=adapter_agent)
78 self.devices = dict() # device_id -> OpenoltDevice()
79 self.interface = registry('main').get_args().interface
80 self.logical_device_id_to_root_device_id = dict()
Shad Ansari5dbc9c82018-05-10 03:29:31 +000081 self.num_devices = 0
Shad Ansari2825d012018-02-22 23:57:46 +000082
83 def start(self):
84 log.info('started', interface=self.interface)
85
86 def stop(self):
87 log.info('stopped', interface=self.interface)
88
89 def adapter_descriptor(self):
90 log.debug('get descriptor', interface=self.interface)
91 return self.descriptor
92
93 def device_types(self):
Shad Ansarif9d2d102018-06-13 02:15:26 +000094 log.debug('get device_types', interface=self.interface,
95 items=self.supported_device_types)
Shad Ansari2825d012018-02-22 23:57:46 +000096 return DeviceTypes(items=self.supported_device_types)
97
98 def health(self):
99 log.debug('get health', interface=self.interface)
100 raise NotImplementedError()
101
102 def change_master_state(self, master):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000103 log.debug('change_master_state', interface=self.interface,
104 master=master)
Shad Ansari2825d012018-02-22 23:57:46 +0000105 raise NotImplementedError()
106
107 def adopt_device(self, device):
108 log.info('adopt-device', device=device)
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000109
Shad Ansari2825d012018-02-22 23:57:46 +0000110 kwargs = {
Shad Ansaricd20a6d2018-10-02 14:36:33 +0000111 'support_classes': OpenOltDefaults['support_classes'],
Shad Ansari2825d012018-02-22 23:57:46 +0000112 'adapter_agent': self.adapter_agent,
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000113 'device': device,
114 'device_num': self.num_devices + 1
Shad Ansari2825d012018-02-22 23:57:46 +0000115 }
116 try:
117 self.devices[device.id] = OpenoltDevice(**kwargs)
118 except Exception as e:
119 log.error('Failed to adopt OpenOLT device', error=e)
Matteo Scandolo00041762018-11-15 18:12:54 -0800120 # TODO set status to ERROR so that is clear something went wrong
Shad Ansari2825d012018-02-22 23:57:46 +0000121 del self.devices[device.id]
122 raise
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000123 else:
124 self.num_devices += 1
Shad Ansari2825d012018-02-22 23:57:46 +0000125
126 def reconcile_device(self, device):
127 log.info('reconcile-device', device=device)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400128 kwargs = {
Girish Gowdru1e77ea02018-09-24 09:10:35 -0700129 'support_classes': OpenOltDefaults['support_classes'],
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400130 'adapter_agent': self.adapter_agent,
131 'device': device,
132 'device_num': self.num_devices + 1,
133 'reconciliation': True
134 }
135 try:
136 reconciled_device = OpenoltDevice(**kwargs)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000137 log.debug('reconciled-device-recreated',
138 device_id=reconciled_device.device_id)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400139 self.devices[device.id] = reconciled_device
140 except Exception as e:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000141 log.error('Failed to reconcile OpenOLT device', error=e,
142 exception_type=type(e).__name__)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400143 del self.devices[device.id]
144 raise
145 else:
146 self.num_devices += 1
147 # Invoke the children reconciliation which would setup the
148 # basic children data structures
149 self.adapter_agent.reconcile_child_devices(device.id)
150 return device
Shad Ansari2825d012018-02-22 23:57:46 +0000151
152 def abandon_device(self, device):
153 log.info('abandon-device', device=device)
154 raise NotImplementedError()
155
156 def disable_device(self, device):
157 log.info('disable-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400158 handler = self.devices[device.id]
159 handler.disable()
Shad Ansari2825d012018-02-22 23:57:46 +0000160
161 def reenable_device(self, device):
162 log.info('reenable-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400163 handler = self.devices[device.id]
164 handler.reenable()
Shad Ansari2825d012018-02-22 23:57:46 +0000165
166 def reboot_device(self, device):
167 log.info('reboot_device', device=device)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -0400168 handler = self.devices[device.id]
169 handler.reboot()
Shad Ansari2825d012018-02-22 23:57:46 +0000170
171 def download_image(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400172 log.info('image_download - Not implemented yet', device=device,
173 request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000174 raise NotImplementedError()
175
176 def get_image_download_status(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400177 log.info('get_image_download - Not implemented yet', device=device,
178 request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000179 raise NotImplementedError()
180
181 def cancel_image_download(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400182 log.info('cancel_image_download - Not implemented yet', device=device)
Shad Ansari2825d012018-02-22 23:57:46 +0000183 raise NotImplementedError()
184
185 def activate_image_update(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400186 log.info('activate_image_update - Not implemented yet',
187 device=device, request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000188 raise NotImplementedError()
189
190 def revert_image_update(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400191 log.info('revert_image_update - Not implemented yet',
192 device=device, request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000193 raise NotImplementedError()
194
195 def self_test_device(self, device):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000196 # from voltha.protos.voltha_pb2 import SelfTestResponse
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400197 log.info('Not implemented yet')
Shad Ansari2825d012018-02-22 23:57:46 +0000198 raise NotImplementedError()
199
200 def delete_device(self, device):
201 log.info('delete-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400202 handler = self.devices[device.id]
203 handler.delete()
204 del self.devices[device.id]
Matteo Scandoloa171b6e2018-09-14 16:48:24 -0700205 del self.logical_device_id_to_root_device_id[device.parent_id]
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -0400206 return device
Shad Ansari2825d012018-02-22 23:57:46 +0000207
208 def get_device_details(self, device):
209 log.debug('get_device_details', device=device)
210 raise NotImplementedError()
211
212 def update_flows_bulk(self, device, flows, groups):
213 log.info('bulk-flow-update', device_id=device.id,
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400214 number_of_flows=len(flows.items), number_of_groups=len(
Shad Ansari78de2be2018-10-12 22:13:54 +0000215 groups.items))
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400216 log.debug('flows and grousp details', flows=flows, groups=groups)
Shad Ansari2825d012018-02-22 23:57:46 +0000217 assert len(groups.items) == 0, "Cannot yet deal with groups"
218 handler = self.devices[device.id]
219 return handler.update_flow_table(flows.items)
220
221 def update_flows_incrementally(self, device, flow_changes, group_changes):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000222 log.debug('update_flows_incrementally', device=device,
223 flow_changes=flow_changes, group_changes=group_changes)
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400224 log.info('This device does not allow this, therefore it is Not '
225 'implemented')
Shad Ansari2825d012018-02-22 23:57:46 +0000226 raise NotImplementedError()
227
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400228 def update_logical_flows(self, device_id, flows_to_add, flows_to_remove,
229 groups, device_rules_map):
230
231 log.info('logical-flows-update', flows_to_add=len(flows_to_add),
Shad Ansari78de2be2018-10-12 22:13:54 +0000232 flows_to_remove=len(flows_to_remove))
Nicolas Palpacuer0c7c3162018-08-08 11:27:57 -0400233 log.debug('logical-flows-details', flows_to_add=flows_to_add,
234 flows_to_remove=flows_to_remove)
235 assert len(groups) == 0, "Cannot yet deal with groups"
236 handler = self.devices[device_id]
237 handler.update_logical_flows(flows_to_add, flows_to_remove,
238 device_rules_map)
239
Shad Ansari2825d012018-02-22 23:57:46 +0000240 def update_pm_config(self, device, pm_configs):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400241 log.info('update_pm_config - Not implemented yet', device=device,
Shad Ansari78de2be2018-10-12 22:13:54 +0000242 pm_configs=pm_configs)
Shad Ansari2825d012018-02-22 23:57:46 +0000243 raise NotImplementedError()
244
245 def send_proxied_message(self, proxy_address, msg):
Zack Williams0ad0a392018-11-14 10:41:08 -0700246 log.debug('send-proxied-message',
247 proxy_address=proxy_address,
248 proxied_msg=msg)
Shad Ansari2825d012018-02-22 23:57:46 +0000249 handler = self.devices[proxy_address.device_id]
250 handler.send_proxied_message(proxy_address, msg)
251
252 def receive_proxied_message(self, proxy_address, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400253 log.debug('receive_proxied_message - Not implemented',
254 proxy_address=proxy_address,
Zack Williams0ad0a392018-11-14 10:41:08 -0700255 proxied_msg=msg)
Shad Ansari2825d012018-02-22 23:57:46 +0000256 raise NotImplementedError()
257
258 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
259 log.debug('packet-out', logical_device_id=logical_device_id,
260 egress_port_no=egress_port_no, msg_len=len(msg))
Shad Ansarif9d2d102018-06-13 02:15:26 +0000261
Shad Ansari42db7342018-04-25 21:39:46 +0000262 def ldi_to_di(ldi):
263 di = self.logical_device_id_to_root_device_id.get(ldi)
264 if di is None:
265 logical_device = self.adapter_agent.get_logical_device(ldi)
266 di = logical_device.root_device_id
267 self.logical_device_id_to_root_device_id[ldi] = di
268 return di
269
Matteo Scandoloa171b6e2018-09-14 16:48:24 -0700270 try:
271 device_id = ldi_to_di(logical_device_id)
272 handler = self.devices[device_id]
273 handler.packet_out(egress_port_no, msg)
274 except Exception as e:
275 log.error('packet-out:exception', e=e.message)
Shad Ansari2825d012018-02-22 23:57:46 +0000276
277 def receive_inter_adapter_message(self, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400278 log.info('rx_inter_adapter_msg - Not implemented')
Shad Ansari2825d012018-02-22 23:57:46 +0000279 raise NotImplementedError()
280
281 def suppress_alarm(self, filter):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400282 log.info('suppress_alarm - Not implemented yet', filter=filter)
Shad Ansari2825d012018-02-22 23:57:46 +0000283 raise NotImplementedError()
284
285 def unsuppress_alarm(self, filter):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400286 log.info('unsuppress_alarm - Not implemented yet', filter=filter)
Shad Ansari2825d012018-02-22 23:57:46 +0000287 raise NotImplementedError()
288
289 # PON Mgnt APIs #
290 def create_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400291 log.debug('create-interface - Not implemented - We do not use this',
292 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000293 raise NotImplementedError()
294
295 def update_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400296 log.debug('update-interface - Not implemented - We do not use this',
297 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000298 raise NotImplementedError()
299
300 def remove_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400301 log.debug('remove-interface - Not implemented - We do not use this',
302 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000303 raise NotImplementedError()
304
305 def receive_onu_detect_state(self, proxy_address, state):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400306 log.debug('receive-onu-detect-state - Not implemented - We do not '
307 'use this', proxy_address=proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000308 state=state)
Shad Ansari2825d012018-02-22 23:57:46 +0000309 raise NotImplementedError()
310
311 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400312 log.info('create-tcont - Not implemented - We do not use this',
313 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000314 traffic_descriptor_data=traffic_descriptor_data)
315 raise NotImplementedError()
316
317 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400318 log.info('update-tcont - Not implemented - We do not use this',
319 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000320 traffic_descriptor_data=traffic_descriptor_data)
321 raise NotImplementedError()
322
323 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400324 log.info('remove-tcont - Not implemented - We do not use this',
325 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000326 traffic_descriptor_data=traffic_descriptor_data)
327 raise NotImplementedError()
328
329 def create_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400330 log.info('create-gemport - Not implemented - We do not use this',
331 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000332 raise NotImplementedError()
333
334 def update_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400335 log.info('update-gemport - Not implemented - We do not use this',
336 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000337 raise NotImplementedError()
338
339 def remove_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400340 log.info('remove-gemport - Not implemented - We do not use this',
341 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000342 raise NotImplementedError()
343
344 def create_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400345 log.info('create-mcast-gemport - Not implemented - We do not use '
346 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000347 raise NotImplementedError()
348
349 def update_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400350 log.info('update-mcast-gemport - Not implemented - We do not use '
351 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000352 raise NotImplementedError()
353
354 def remove_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400355 log.info('remove-mcast-gemport - Not implemented - We do not use '
356 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000357 raise NotImplementedError()
358
359 def create_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400360 log.info('create-mcast-distribution-set - Not implemented - We do '
361 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000362 raise NotImplementedError()
363
364 def update_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400365 log.info('update-mcast-distribution-set - Not implemented - We do '
366 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000367 raise NotImplementedError()
368
369 def remove_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400370 log.info('remove-mcast-distribution-set - Not implemented - We do '
371 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000372 raise NotImplementedError()
Jonathan Davisb45bb372018-07-19 15:05:15 -0400373
Jonathan Davisb45bb372018-07-19 15:05:15 -0400374 def delete_child_device(self, parent_device_id, child_device):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400375 log.info('delete-child_device', parent_device_id=parent_device_id,
376 child_device=child_device)
Jonathan Davisb45bb372018-07-19 15:05:15 -0400377 handler = self.devices[parent_device_id]
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400378 if handler is not None:
379 handler.delete_child_device(child_device)
380 else:
381 log.error('Could not find matching handler',
Shad Ansari78de2be2018-10-12 22:13:54 +0000382 looking_for_device_id=parent_device_id,
Nicolas Palpacuer131790b2018-08-20 09:59:34 -0400383 available_handlers=self.devices.keys())
Nicolas Palpacuer30027f42018-09-06 15:55:54 -0400384
385 # This is currently not part of the Iadapter interface
386 def collect_stats(self, device_id):
387 log.info('collect_stats', device_id=device_id)
Shad Ansari78de2be2018-10-12 22:13:54 +0000388 handler = self.devices[device_id]
Nicolas Palpacuer30027f42018-09-06 15:55:54 -0400389 if handler is not None:
390 handler.trigger_statistics_collection()
391 else:
392 log.error('Could not find matching handler',
393 looking_for_device_id=device_id,
394 available_handlers=self.devices.keys())
Scott Bakerd3190952018-09-04 15:47:28 -0700395
396 def simulate_alarm(self, device, request):
397 log.info('simulate_alarm', device=device, request=request)
398
399 if device.id not in self.devices:
400 log.error("Device does not exist", device_id=device.id)
401 return OperationResp(code=OperationResp.OPERATION_FAILURE,
Shad Ansari78de2be2018-10-12 22:13:54 +0000402 additional_info="Device %s does not exist"
403 % device.id)
Scott Bakerd3190952018-09-04 15:47:28 -0700404
405 handler = self.devices[device.id]
406
407 handler.simulate_alarm(request)
408
409 return OperationResp(code=OperationResp.OPERATION_SUCCESS)