blob: 288155c39898bc7f50e10ef1955ea1d550b88544 [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
29from voltha.protos.device_pb2 import DeviceType, DeviceTypes
Shad Ansari2825d012018-02-22 23:57:46 +000030from voltha.registry import registry
31
32_ = third_party
33log = structlog.get_logger()
34
Shad Ansarif9d2d102018-06-13 02:15:26 +000035
Shad Ansari2825d012018-02-22 23:57:46 +000036@implementer(IAdapterInterface)
37class OpenoltAdapter(object):
38 name = 'openolt'
39
40 supported_device_types = [
41 DeviceType(
42 id=name,
43 adapter=name,
44 accepts_bulk_flow_update=True
45 )
46 ]
47
48 def __init__(self, adapter_agent, config):
49 self.adapter_agent = adapter_agent
50 self.config = config
51 self.descriptor = Adapter(
52 id=self.name,
53 vendor='OLT white box vendor',
54 version='0.1',
55 config=AdapterConfig(log_level=LogLevel.INFO)
56 )
57 log.debug('openolt.__init__', adapter_agent=adapter_agent)
58 self.devices = dict() # device_id -> OpenoltDevice()
59 self.interface = registry('main').get_args().interface
60 self.logical_device_id_to_root_device_id = dict()
Shad Ansari5dbc9c82018-05-10 03:29:31 +000061 self.num_devices = 0
Shad Ansari2825d012018-02-22 23:57:46 +000062
63 def start(self):
64 log.info('started', interface=self.interface)
65
66 def stop(self):
67 log.info('stopped', interface=self.interface)
68
69 def adapter_descriptor(self):
70 log.debug('get descriptor', interface=self.interface)
71 return self.descriptor
72
73 def device_types(self):
Shad Ansarif9d2d102018-06-13 02:15:26 +000074 log.debug('get device_types', interface=self.interface,
75 items=self.supported_device_types)
Shad Ansari2825d012018-02-22 23:57:46 +000076 return DeviceTypes(items=self.supported_device_types)
77
78 def health(self):
79 log.debug('get health', interface=self.interface)
80 raise NotImplementedError()
81
82 def change_master_state(self, master):
Shad Ansarif9d2d102018-06-13 02:15:26 +000083 log.debug('change_master_state', interface=self.interface,
84 master=master)
Shad Ansari2825d012018-02-22 23:57:46 +000085 raise NotImplementedError()
86
87 def adopt_device(self, device):
88 log.info('adopt-device', device=device)
89 kwargs = {
90 'adapter_agent': self.adapter_agent,
Shad Ansari5dbc9c82018-05-10 03:29:31 +000091 'device': device,
92 'device_num': self.num_devices + 1
Shad Ansari2825d012018-02-22 23:57:46 +000093 }
94 try:
95 self.devices[device.id] = OpenoltDevice(**kwargs)
96 except Exception as e:
97 log.error('Failed to adopt OpenOLT device', error=e)
98 del self.devices[device.id]
99 raise
Shad Ansari5dbc9c82018-05-10 03:29:31 +0000100 else:
101 self.num_devices += 1
Shad Ansari2825d012018-02-22 23:57:46 +0000102
103 def reconcile_device(self, device):
104 log.info('reconcile-device', device=device)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400105 kwargs = {
106 'adapter_agent': self.adapter_agent,
107 'device': device,
108 'device_num': self.num_devices + 1,
109 'reconciliation': True
110 }
111 try:
112 reconciled_device = OpenoltDevice(**kwargs)
Shad Ansarif9d2d102018-06-13 02:15:26 +0000113 log.debug('reconciled-device-recreated',
114 device_id=reconciled_device.device_id)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400115 self.devices[device.id] = reconciled_device
116 except Exception as e:
Shad Ansarif9d2d102018-06-13 02:15:26 +0000117 log.error('Failed to reconcile OpenOLT device', error=e,
118 exception_type=type(e).__name__)
Nicolas Palpacuer253461f2018-06-01 12:01:45 -0400119 del self.devices[device.id]
120 raise
121 else:
122 self.num_devices += 1
123 # Invoke the children reconciliation which would setup the
124 # basic children data structures
125 self.adapter_agent.reconcile_child_devices(device.id)
126 return device
Shad Ansari2825d012018-02-22 23:57:46 +0000127
128 def abandon_device(self, device):
129 log.info('abandon-device', device=device)
130 raise NotImplementedError()
131
132 def disable_device(self, device):
133 log.info('disable-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400134 handler = self.devices[device.id]
135 handler.disable()
Shad Ansari2825d012018-02-22 23:57:46 +0000136
137 def reenable_device(self, device):
138 log.info('reenable-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400139 handler = self.devices[device.id]
140 handler.reenable()
Shad Ansari2825d012018-02-22 23:57:46 +0000141
142 def reboot_device(self, device):
143 log.info('reboot_device', device=device)
Nicolas Palpacuerfd365ac2018-08-02 11:37:37 -0400144 handler = self.devices[device.id]
145 handler.reboot()
Shad Ansari2825d012018-02-22 23:57:46 +0000146
147 def download_image(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400148 log.info('image_download - Not implemented yet', device=device,
149 request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000150 raise NotImplementedError()
151
152 def get_image_download_status(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400153 log.info('get_image_download - Not implemented yet', device=device,
154 request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000155 raise NotImplementedError()
156
157 def cancel_image_download(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400158 log.info('cancel_image_download - Not implemented yet', device=device)
Shad Ansari2825d012018-02-22 23:57:46 +0000159 raise NotImplementedError()
160
161 def activate_image_update(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400162 log.info('activate_image_update - Not implemented yet',
163 device=device, request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000164 raise NotImplementedError()
165
166 def revert_image_update(self, device, request):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400167 log.info('revert_image_update - Not implemented yet',
168 device=device, request=request)
Shad Ansari2825d012018-02-22 23:57:46 +0000169 raise NotImplementedError()
170
171 def self_test_device(self, device):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000172 # from voltha.protos.voltha_pb2 import SelfTestResponse
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400173 log.info('Not implemented yet')
Shad Ansari2825d012018-02-22 23:57:46 +0000174 raise NotImplementedError()
175
176 def delete_device(self, device):
177 log.info('delete-device', device=device)
Jonathan Davis0f917a22018-05-30 14:39:45 -0400178 handler = self.devices[device.id]
179 handler.delete()
180 del self.devices[device.id]
Nicolas Palpacuer0d44e682018-08-06 10:30:26 -0400181 return device
Shad Ansari2825d012018-02-22 23:57:46 +0000182
183 def get_device_details(self, device):
184 log.debug('get_device_details', device=device)
185 raise NotImplementedError()
186
187 def update_flows_bulk(self, device, flows, groups):
188 log.info('bulk-flow-update', device_id=device.id,
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400189 number_of_flows=len(flows.items), number_of_groups=len(
190 groups.items))
191 log.debug('flows and grousp details', flows=flows, groups=groups)
Shad Ansari2825d012018-02-22 23:57:46 +0000192 assert len(groups.items) == 0, "Cannot yet deal with groups"
193 handler = self.devices[device.id]
194 return handler.update_flow_table(flows.items)
195
196 def update_flows_incrementally(self, device, flow_changes, group_changes):
Shad Ansarif9d2d102018-06-13 02:15:26 +0000197 log.debug('update_flows_incrementally', device=device,
198 flow_changes=flow_changes, group_changes=group_changes)
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400199 log.info('This device does not allow this, therefore it is Not '
200 'implemented')
Shad Ansari2825d012018-02-22 23:57:46 +0000201 raise NotImplementedError()
202
203 def update_pm_config(self, device, pm_configs):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400204 log.info('update_pm_config - Not implemented yet', device=device,
205 pm_configs=pm_configs)
Shad Ansari2825d012018-02-22 23:57:46 +0000206 raise NotImplementedError()
207
208 def send_proxied_message(self, proxy_address, msg):
209 log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg)
210 handler = self.devices[proxy_address.device_id]
211 handler.send_proxied_message(proxy_address, msg)
212
213 def receive_proxied_message(self, proxy_address, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400214 log.debug('receive_proxied_message - Not implemented',
215 proxy_address=proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000216 msg=msg)
Shad Ansari2825d012018-02-22 23:57:46 +0000217 raise NotImplementedError()
218
219 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
220 log.debug('packet-out', logical_device_id=logical_device_id,
221 egress_port_no=egress_port_no, msg_len=len(msg))
Shad Ansarif9d2d102018-06-13 02:15:26 +0000222
Shad Ansari42db7342018-04-25 21:39:46 +0000223 def ldi_to_di(ldi):
224 di = self.logical_device_id_to_root_device_id.get(ldi)
225 if di is None:
226 logical_device = self.adapter_agent.get_logical_device(ldi)
227 di = logical_device.root_device_id
228 self.logical_device_id_to_root_device_id[ldi] = di
229 return di
230
231 device_id = ldi_to_di(logical_device_id)
232 handler = self.devices[device_id]
233 handler.packet_out(egress_port_no, msg)
Shad Ansari2825d012018-02-22 23:57:46 +0000234
235 def receive_inter_adapter_message(self, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400236 log.info('rx_inter_adapter_msg - Not implemented')
Shad Ansari2825d012018-02-22 23:57:46 +0000237 raise NotImplementedError()
238
239 def suppress_alarm(self, filter):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400240 log.info('suppress_alarm - Not implemented yet', filter=filter)
Shad Ansari2825d012018-02-22 23:57:46 +0000241 raise NotImplementedError()
242
243 def unsuppress_alarm(self, filter):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400244 log.info('unsuppress_alarm - Not implemented yet', filter=filter)
Shad Ansari2825d012018-02-22 23:57:46 +0000245 raise NotImplementedError()
246
247 # PON Mgnt APIs #
248 def create_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400249 log.debug('create-interface - Not implemented - We do not use this',
250 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000251 raise NotImplementedError()
252
253 def update_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400254 log.debug('update-interface - Not implemented - We do not use this',
255 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000256 raise NotImplementedError()
257
258 def remove_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400259 log.debug('remove-interface - Not implemented - We do not use this',
260 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000261 raise NotImplementedError()
262
263 def receive_onu_detect_state(self, proxy_address, state):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400264 log.debug('receive-onu-detect-state - Not implemented - We do not '
265 'use this', proxy_address=proxy_address,
Shad Ansarif9d2d102018-06-13 02:15:26 +0000266 state=state)
Shad Ansari2825d012018-02-22 23:57:46 +0000267 raise NotImplementedError()
268
269 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400270 log.info('create-tcont - Not implemented - We do not use this',
271 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000272 traffic_descriptor_data=traffic_descriptor_data)
273 raise NotImplementedError()
274
275 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400276 log.info('update-tcont - Not implemented - We do not use this',
277 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000278 traffic_descriptor_data=traffic_descriptor_data)
279 raise NotImplementedError()
280
281 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400282 log.info('remove-tcont - Not implemented - We do not use this',
283 tcont_data=tcont_data,
Shad Ansari2825d012018-02-22 23:57:46 +0000284 traffic_descriptor_data=traffic_descriptor_data)
285 raise NotImplementedError()
286
287 def create_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400288 log.info('create-gemport - Not implemented - We do not use this',
289 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000290 raise NotImplementedError()
291
292 def update_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400293 log.info('update-gemport - Not implemented - We do not use this',
294 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000295 raise NotImplementedError()
296
297 def remove_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400298 log.info('remove-gemport - Not implemented - We do not use this',
299 data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000300 raise NotImplementedError()
301
302 def create_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400303 log.info('create-mcast-gemport - Not implemented - We do not use '
304 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000305 raise NotImplementedError()
306
307 def update_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400308 log.info('update-mcast-gemport - Not implemented - We do not use '
309 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000310 raise NotImplementedError()
311
312 def remove_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400313 log.info('remove-mcast-gemport - Not implemented - We do not use '
314 'this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000315 raise NotImplementedError()
316
317 def create_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400318 log.info('create-mcast-distribution-set - Not implemented - We do '
319 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000320 raise NotImplementedError()
321
322 def update_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400323 log.info('update-mcast-distribution-set - Not implemented - We do '
324 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000325 raise NotImplementedError()
326
327 def remove_multicast_distribution_set(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400328 log.info('remove-mcast-distribution-set - Not implemented - We do '
329 'not use this', data=data)
Shad Ansari2825d012018-02-22 23:57:46 +0000330 raise NotImplementedError()
Jonathan Davisb45bb372018-07-19 15:05:15 -0400331
332 def disable_child_device(self, parent_device_id, child_device):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400333 log.info('disable-child_device', parent_device_id=parent_device_id,
334 child_device=child_device)
Jonathan Davisb45bb372018-07-19 15:05:15 -0400335 handler = self.devices[parent_device_id]
336 handler.disable_child_device(child_device)
337
338 def delete_child_device(self, parent_device_id, child_device):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400339 log.info('delete-child_device', parent_device_id=parent_device_id,
340 child_device=child_device)
Jonathan Davisb45bb372018-07-19 15:05:15 -0400341 handler = self.devices[parent_device_id]
342 handler.delete_child_device(child_device)