blob: 335693f32b91b042a1fc0d0454163ab24d75de03 [file] [log] [blame]
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -05001#
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#
16
17"""
18Broadcom OpenOMCI OLT/ONU adapter.
19
20This adapter does NOT support XPON
21"""
22
23from twisted.internet import reactor, task
William Kurkian3a206332019-04-29 11:05:47 -040024from twisted.internet.defer import inlineCallbacks
25
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050026from zope.interface import implementer
27
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050028from pyvoltha.adapters.interface import IAdapterInterface
Matt Jeanneret21363202019-02-13 16:21:48 -050029from pyvoltha.adapters.iadapter import OnuAdapter
William Kurkian8235c1e2019-03-05 12:58:28 -050030from voltha_protos.adapter_pb2 import Adapter
31from voltha_protos.adapter_pb2 import AdapterConfig
32from voltha_protos.common_pb2 import LogLevel
33from voltha_protos.device_pb2 import DeviceType, DeviceTypes, Port, Image
34from voltha_protos.health_pb2 import HealthStatus
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050035
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050036from pyvoltha.adapters.common.frameio.frameio import hexify
37from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
38from pyvoltha.adapters.extensions.omci.omci_me import *
Matt Jeanneret98f99dc2019-09-25 11:05:25 -040039from pyvoltha.adapters.extensions.omci.database.mib_db_dict import MibDbVolatileDict
Matt Jeanneret72f96fc2019-02-11 10:53:05 -050040
41from brcm_openomci_onu_handler import BrcmOpenomciOnuHandler
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050042from omci.brcm_capabilities_task import BrcmCapabilitiesTask
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050043from omci.brcm_mib_sync import BrcmMibSynchronizer
44from copy import deepcopy
45
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050046log = structlog.get_logger()
47
48
49@implementer(IAdapterInterface)
50class BrcmOpenomciOnuAdapter(object):
51
52 name = 'brcm_openomci_onu'
53
54 supported_device_types = [
55 DeviceType(
56 id=name,
57 vendor_ids=['OPEN', 'ALCL', 'BRCM', 'TWSH', 'ALPH', 'ISKT', 'SFAA', 'BBSM'],
58 adapter=name,
59 accepts_bulk_flow_update=True
60 )
61 ]
62
Matt Jeanneret21363202019-02-13 16:21:48 -050063 def __init__(self, core_proxy, adapter_proxy, config):
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050064 log.debug('function-entry', config=config)
Matt Jeannereta32441c2019-03-07 05:16:37 -050065 self.core_proxy = core_proxy
Matt Jeanneret0bd63c82019-02-15 05:40:44 -050066 self.adapter_proxy = adapter_proxy
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050067 self.config = config
68 self.descriptor = Adapter(
69 id=self.name,
70 vendor='Voltha project',
Matt Jeanneret21363202019-02-13 16:21:48 -050071 version='2.0',
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050072 config=AdapterConfig(log_level=LogLevel.INFO)
73 )
74 self.devices_handlers = dict()
Matt Jeanneret21363202019-02-13 16:21:48 -050075 self.device_handler_class = BrcmOpenomciOnuHandler
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050076
77 # Customize OpenOMCI for Broadcom ONUs
78 self.broadcom_omci = deepcopy(OpenOmciAgentDefaults)
79
80 self.broadcom_omci['mib-synchronizer']['state-machine'] = BrcmMibSynchronizer
Matt Jeanneret98f99dc2019-09-25 11:05:25 -040081 self.broadcom_omci['mib-synchronizer']['database'] = MibDbVolatileDict
82 self.broadcom_omci['alarm-synchronizer']['database'] = MibDbVolatileDict
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050083 self.broadcom_omci['omci-capabilities']['tasks']['get-capabilities'] = BrcmCapabilitiesTask
84
85 # Defer creation of omci agent to a lazy init that allows subclasses to override support classes
86
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050087 def custom_me_entities(self):
88 return None
89
90 @property
91 def omci_agent(self):
92 if not hasattr(self, '_omci_agent') or self._omci_agent is None:
93 log.debug('creating-omci-agent')
Matt Jeannereta32441c2019-03-07 05:16:37 -050094 self._omci_agent = OpenOMCIAgent(self.core_proxy,
95 self.adapter_proxy,
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -050096 support_classes=self.broadcom_omci)
97 return self._omci_agent
98
99 def start(self):
100 log.debug('starting')
101 self.omci_agent.start()
102 log.info('started')
103
104 def stop(self):
105 log.debug('stopping')
106
107 omci, self._omci_agent = self._omci_agent, None
108 if omci is not None:
109 self._omci_agent.stop()
110
111 log.info('stopped')
112
113 def adapter_descriptor(self):
114 return self.descriptor
115
116 def device_types(self):
117 return DeviceTypes(items=self.supported_device_types)
118
119 def health(self):
120 return HealthStatus(state=HealthStatus.HealthState.HEALTHY)
121
122 def change_master_state(self, master):
123 raise NotImplementedError()
124
125 def adopt_device(self, device):
126 log.info('adopt_device', device_id=device.id)
127 self.devices_handlers[device.id] = BrcmOpenomciOnuHandler(self, device.id)
128 reactor.callLater(0, self.devices_handlers[device.id].activate, device)
129 return device
130
131 def reconcile_device(self, device):
132 log.info('reconcile-device', device_id=device.id)
133 self.devices_handlers[device.id] = BrcmOpenomciOnuHandler(self, device.id)
134 reactor.callLater(0, self.devices_handlers[device.id].reconcile, device)
135
136 def abandon_device(self, device):
137 raise NotImplementedError()
138
139 def disable_device(self, device):
140 log.info('disable-onu-device', device_id=device.id)
141 if device.id in self.devices_handlers:
142 handler = self.devices_handlers[device.id]
143 if handler is not None:
144 handler.disable(device)
145
146 def reenable_device(self, device):
147 log.info('reenable-onu-device', device_id=device.id)
148 if device.id in self.devices_handlers:
149 handler = self.devices_handlers[device.id]
150 if handler is not None:
151 handler.reenable(device)
152
153 def reboot_device(self, device):
154 log.info('reboot-device', device_id=device.id)
155 if device.id in self.devices_handlers:
156 handler = self.devices_handlers[device.id]
157 if handler is not None:
158 handler.reboot()
159
160 def download_image(self, device, request):
161 raise NotImplementedError()
162
163 def get_image_download_status(self, device, request):
164 raise NotImplementedError()
165
166 def cancel_image_download(self, device, request):
167 raise NotImplementedError()
168
169 def activate_image_update(self, device, request):
170 raise NotImplementedError()
171
172 def revert_image_update(self, device, request):
173 raise NotImplementedError()
174
175 def self_test_device(self, device):
176 """
177 This is called to Self a device based on a NBI call.
178 :param device: A Voltha.Device object.
179 :return: Will return result of self test
180 """
181 log.info('self-test-device - Not implemented yet', device=device.id)
182 raise NotImplementedError()
183
184 def delete_device(self, device):
185 log.info('delete-device', device_id=device.id)
186 if device.id in self.devices_handlers:
187 handler = self.devices_handlers[device.id]
188 if handler is not None:
189 handler.delete(device)
190 del self.devices_handlers[device.id]
191 return
192
193 def get_device_details(self, device):
194 raise NotImplementedError()
195
196 # TODO(smbaker): When BrcmOpenomciOnuAdapter is updated to inherit from OnuAdapter, this function can be deleted
197 def update_pm_config(self, device, pm_config):
198 log.info("adapter-update-pm-config", device=device,
199 pm_config=pm_config)
200 handler = self.devices_handlers[device.id]
201 handler.update_pm_config(device, pm_config)
202
203 def update_flows_bulk(self, device, flows, groups):
204 '''
205 log.info('bulk-flow-update', device_id=device.id,
206 flows=flows, groups=groups)
207 '''
208 assert len(groups.items) == 0
209 handler = self.devices_handlers[device.id]
210 return handler.update_flow_table(device, flows.items)
211
212 def update_flows_incrementally(self, device, flow_changes, group_changes):
213 raise NotImplementedError()
214
215 def send_proxied_message(self, proxy_address, msg):
216 log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg)
217
William Kurkian3a206332019-04-29 11:05:47 -0400218 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500219 def receive_proxied_message(self, proxy_address, msg):
220 log.debug('receive-proxied-message', proxy_address=proxy_address,
221 device_id=proxy_address.device_id, msg=hexify(msg))
222 # Device_id from the proxy_address is the olt device id. We need to
223 # get the onu device id using the port number in the proxy_address
William Kurkian3a206332019-04-29 11:05:47 -0400224 device = self.core_proxy. \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500225 get_child_device_with_proxy_address(proxy_address)
226 if device:
227 handler = self.devices_handlers[device.id]
228 handler.receive_message(msg)
229
230 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
231 log.info('packet-out', logical_device_id=logical_device_id,
232 egress_port_no=egress_port_no, msg_len=len(msg))
233
William Kurkian3a206332019-04-29 11:05:47 -0400234 @inlineCallbacks
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500235 def receive_inter_adapter_message(self, msg):
236 log.debug('receive_inter_adapter_message', msg=msg)
237 proxy_address = msg['proxy_address']
238 assert proxy_address is not None
239 # Device_id from the proxy_address is the olt device id. We need to
240 # get the onu device id using the port number in the proxy_address
William Kurkian3a206332019-04-29 11:05:47 -0400241 device = self.core_proxy. \
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500242 get_child_device_with_proxy_address(proxy_address)
243 if device:
244 handler = self.devices_handlers[device.id]
245 handler.event_messages.put(msg)
246 else:
247 log.error("device-not-found")
248
Matt Jeanneretc083f462019-03-11 15:02:01 -0400249 def get_ofp_port_info(self, device, port_no):
250 ofp_port_info = self.devices_handlers[device.id].get_ofp_port_info(device, port_no)
251 log.debug('get_ofp_port_info', device_id=device.id, ofp_port_info=ofp_port_info)
252 return ofp_port_info
253
Matt Jeannereta32441c2019-03-07 05:16:37 -0500254 def process_inter_adapter_message(self, msg):
255 log.debug('process-inter-adapter-message', msg=msg)
256 # Unpack the header to know which device needs to handle this message
257 if msg.header:
258 handler = self.devices_handlers[msg.header.to_device_id]
259 handler.process_inter_adapter_message(msg)
260
Matt Jeanneretf1e9c5d2019-02-08 07:41:29 -0500261 def create_interface(self, device, data):
262 log.debug('create-interface', device_id=device.id)
263 if device.id in self.devices_handlers:
264 handler = self.devices_handlers[device.id]
265 if handler is not None:
266 handler.create_interface(data)
267
268 def update_interface(self, device, data):
269 log.debug('update-interface', device_id=device.id)
270 if device.id in self.devices_handlers:
271 handler = self.devices_handlers[device.id]
272 if handler is not None:
273 handler.update_interface(data)
274
275 def remove_interface(self, device, data):
276 log.debug('remove-interface', device_id=device.id)
277 if device.id in self.devices_handlers:
278 handler = self.devices_handlers[device.id]
279 if handler is not None:
280 handler.remove_interface(data)
281
282 def receive_onu_detect_state(self, device_id, state):
283 raise NotImplementedError()
284
285 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
286 log.debug('create-tcont', device_id=device.id)
287 if device.id in self.devices_handlers:
288 handler = self.devices_handlers[device.id]
289 if handler is not None:
290 handler.create_tcont(tcont_data, traffic_descriptor_data)
291
292 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
293 raise NotImplementedError()
294
295 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
296 log.debug('remove-tcont', device_id=device.id)
297 if device.id in self.devices_handlers:
298 handler = self.devices_handlers[device.id]
299 if handler is not None:
300 handler.remove_tcont(tcont_data, traffic_descriptor_data)
301
302 def create_gemport(self, device, data):
303 log.debug('create-gemport', device_id=device.id)
304 if device.id in self.devices_handlers:
305 handler = self.devices_handlers[device.id]
306 if handler is not None:
307 handler.create_gemport(data)
308
309 def update_gemport(self, device, data):
310 raise NotImplementedError()
311
312 def remove_gemport(self, device, data):
313 log.debug('remove-gemport', device_id=device.id)
314 if device.id in self.devices_handlers:
315 handler = self.devices_handlers[device.id]
316 if handler is not None:
317 handler.remove_gemport(data)
318
319 def create_multicast_gemport(self, device, data):
320 log.debug('create-multicast-gemport', device_id=device.id)
321 if device.id in self.devices_handlers:
322 handler = self.devices_handlers[device.id]
323 if handler is not None:
324 handler.create_multicast_gemport(data)
325
326 def update_multicast_gemport(self, device, data):
327 raise NotImplementedError()
328
329 def remove_multicast_gemport(self, device, data):
330 raise NotImplementedError()
331
332 def create_multicast_distribution_set(self, device, data):
333 raise NotImplementedError()
334
335 def update_multicast_distribution_set(self, device, data):
336 raise NotImplementedError()
337
338 def remove_multicast_distribution_set(self, device, data):
339 raise NotImplementedError()
340
341 def suppress_alarm(self, filter):
342 raise NotImplementedError()
343
344 def unsuppress_alarm(self, filter):
345 raise NotImplementedError()
346
347