blob: 565fa637890e46a077fab0ea104a9078a2fe2831 [file] [log] [blame]
Matt Jeannerete6a70332018-07-20 16:11:25 -04001#
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.
Nicolas Palpacuer68a60ca2018-08-23 12:12:27 -040019
20This adapter does NOT support XPON
Matt Jeannerete6a70332018-07-20 16:11:25 -040021"""
22
23from twisted.internet import reactor, task
24from zope.interface import implementer
25
26from voltha.adapters.brcm_openomci_onu.brcm_openomci_onu_handler import BrcmOpenomciOnuHandler
27from voltha.adapters.interface import IAdapterInterface
28from voltha.protos import third_party
29from voltha.protos.adapter_pb2 import Adapter
30from voltha.protos.adapter_pb2 import AdapterConfig
31from voltha.protos.common_pb2 import LogLevel
32from voltha.protos.device_pb2 import DeviceType, DeviceTypes, Port, Image
33from voltha.protos.health_pb2 import HealthStatus
34
35from common.frameio.frameio import hexify
36from voltha.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults
37from voltha.extensions.omci.omci_me import *
Matt Jeanneret6da55792018-08-08 16:44:18 -040038from voltha.extensions.omci.database.mib_db_dict import MibDbVolatileDict
Matt Jeannerete6a70332018-07-20 16:11:25 -040039from omci.brcm_capabilities_task import BrcmCapabilitiesTask
40from omci.brcm_get_mds_task import BrcmGetMdsTask
41from omci.brcm_mib_sync import BrcmMibSynchronizer
42from copy import deepcopy
43
44
45_ = third_party
46log = 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,
Shad Ansari9fa53402018-10-03 19:15:28 +000057 vendor_ids=['OPEN', 'ALCL', 'BRCM', 'TWSH', 'ALPH', 'ISKT', 'SFAA'],
Matt Jeannerete6a70332018-07-20 16:11:25 -040058 adapter=name,
59 accepts_bulk_flow_update=True
60 )
61 ]
62
63 def __init__(self, adapter_agent, config):
64 log.debug('function-entry', config=config)
65 self.adapter_agent = adapter_agent
66 self.config = config
67 self.descriptor = Adapter(
68 id=self.name,
69 vendor='Voltha project',
70 version='0.50',
71 config=AdapterConfig(log_level=LogLevel.INFO)
72 )
73 self.devices_handlers = dict()
74
75 # Customize OpenOMCI for Broadcom ONUs
76 self.broadcom_omci = deepcopy(OpenOmciAgentDefaults)
77
Matt Jeannerete6a70332018-07-20 16:11:25 -040078 self.broadcom_omci['omci-capabilities']['tasks']['get-capabilities'] = BrcmCapabilitiesTask
79
Matt Jeanneret1c90e502018-11-12 17:38:42 -050080 # Defer creation of omci agent to a lazy init that allows subclasses to override support classes
Matt Jeannerete6a70332018-07-20 16:11:25 -040081
82 # register for adapter messages
83 self.adapter_agent.register_for_inter_adapter_messages()
84
Craig Lutgen2eabc862018-10-18 22:14:14 +000085 def custom_me_entities(self):
86 return None
87
Matt Jeannerete6a70332018-07-20 16:11:25 -040088 @property
89 def omci_agent(self):
Craig Lutgen2eabc862018-10-18 22:14:14 +000090 if not hasattr(self, '_omci_agent') or self._omci_agent is None:
91 log.debug('creating-omci-agent')
92 self._omci_agent = OpenOMCIAgent(self.adapter_agent.core,
93 support_classes=self.broadcom_omci)
Matt Jeannerete6a70332018-07-20 16:11:25 -040094 return self._omci_agent
95
96 def start(self):
97 log.debug('starting')
Craig Lutgen2eabc862018-10-18 22:14:14 +000098 self.omci_agent.start()
Matt Jeannerete6a70332018-07-20 16:11:25 -040099 log.info('started')
100
101 def stop(self):
102 log.debug('stopping')
103
104 omci, self._omci_agent = self._omci_agent, None
105 if omci is not None:
106 self._omci_agent.stop()
107
108 log.info('stopped')
109
110 def adapter_descriptor(self):
111 return self.descriptor
112
113 def device_types(self):
114 return DeviceTypes(items=self.supported_device_types)
115
116 def health(self):
117 return HealthStatus(state=HealthStatus.HealthState.HEALTHY)
118
119 def change_master_state(self, master):
120 raise NotImplementedError()
121
122 def adopt_device(self, device):
123 log.info('adopt_device', device_id=device.id)
124 self.devices_handlers[device.id] = BrcmOpenomciOnuHandler(self, device.id)
125 reactor.callLater(0, self.devices_handlers[device.id].activate, device)
126 return device
127
128 def reconcile_device(self, device):
129 log.info('reconcile-device', device_id=device.id)
130 self.devices_handlers[device.id] = BrcmOpenomciOnuHandler(self, device.id)
131 reactor.callLater(0, self.devices_handlers[device.id].reconcile, device)
132
133 def abandon_device(self, device):
134 raise NotImplementedError()
135
136 def disable_device(self, device):
137 log.info('disable-onu-device', device_id=device.id)
138 if device.id in self.devices_handlers:
139 handler = self.devices_handlers[device.id]
140 if handler is not None:
141 handler.disable(device)
142
143 def reenable_device(self, device):
144 log.info('reenable-onu-device', device_id=device.id)
145 if device.id in self.devices_handlers:
146 handler = self.devices_handlers[device.id]
147 if handler is not None:
148 handler.reenable(device)
149
150 def reboot_device(self, device):
151 log.info('reboot-device', device_id=device.id)
152 if device.id in self.devices_handlers:
153 handler = self.devices_handlers[device.id]
154 if handler is not None:
155 handler.reboot()
156
157 def download_image(self, device, request):
158 raise NotImplementedError()
159
160 def get_image_download_status(self, device, request):
161 raise NotImplementedError()
162
163 def cancel_image_download(self, device, request):
164 raise NotImplementedError()
165
166 def activate_image_update(self, device, request):
167 raise NotImplementedError()
168
169 def revert_image_update(self, device, request):
170 raise NotImplementedError()
171
172 def self_test_device(self, device):
173 """
174 This is called to Self a device based on a NBI call.
175 :param device: A Voltha.Device object.
176 :return: Will return result of self test
177 """
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400178 log.info('self-test-device - Not implemented yet', device=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400179 raise NotImplementedError()
180
181 def delete_device(self, device):
182 log.info('delete-device', device_id=device.id)
183 if device.id in self.devices_handlers:
184 handler = self.devices_handlers[device.id]
185 if handler is not None:
186 handler.delete(device)
187 del self.devices_handlers[device.id]
188 return
189
190 def get_device_details(self, device):
191 raise NotImplementedError()
192
Scott Bakerc474bb92018-10-12 16:19:18 -0700193 # TODO(smbaker): When BrcmOpenomciOnuAdapter is updated to inherit from OnuAdapter, this function can be deleted
194 def update_pm_config(self, device, pm_config):
195 log.info("adapter-update-pm-config", device=device,
196 pm_config=pm_config)
197 handler = self.devices_handlers[device.id]
198 handler.update_pm_config(device, pm_config)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400199
200 def update_flows_bulk(self, device, flows, groups):
201 '''
202 log.info('bulk-flow-update', device_id=device.id,
203 flows=flows, groups=groups)
204 '''
205 assert len(groups.items) == 0
206 handler = self.devices_handlers[device.id]
207 return handler.update_flow_table(device, flows.items)
208
209 def update_flows_incrementally(self, device, flow_changes, group_changes):
210 raise NotImplementedError()
211
212 def send_proxied_message(self, proxy_address, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400213 log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400214
215 def receive_proxied_message(self, proxy_address, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400216 log.debug('receive-proxied-message', proxy_address=proxy_address,
Matt Jeannerete6a70332018-07-20 16:11:25 -0400217 device_id=proxy_address.device_id, msg=hexify(msg))
218 # Device_id from the proxy_address is the olt device id. We need to
219 # get the onu device id using the port number in the proxy_address
220 device = self.adapter_agent. \
221 get_child_device_with_proxy_address(proxy_address)
222 if device:
223 handler = self.devices_handlers[device.id]
224 handler.receive_message(msg)
225
226 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
227 log.info('packet-out', logical_device_id=logical_device_id,
228 egress_port_no=egress_port_no, msg_len=len(msg))
229
230 def receive_inter_adapter_message(self, msg):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400231 log.debug('receive_inter_adapter_message', msg=msg)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400232 proxy_address = msg['proxy_address']
233 assert proxy_address is not None
234 # Device_id from the proxy_address is the olt device id. We need to
235 # get the onu device id using the port number in the proxy_address
236 device = self.adapter_agent. \
237 get_child_device_with_proxy_address(proxy_address)
238 if device:
239 handler = self.devices_handlers[device.id]
240 handler.event_messages.put(msg)
241 else:
242 log.error("device-not-found")
243
244 def create_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400245 log.debug('create-interface', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400246 if device.id in self.devices_handlers:
247 handler = self.devices_handlers[device.id]
248 if handler is not None:
249 handler.create_interface(data)
250
251 def update_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400252 log.debug('update-interface', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400253 if device.id in self.devices_handlers:
254 handler = self.devices_handlers[device.id]
255 if handler is not None:
256 handler.update_interface(data)
257
258 def remove_interface(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400259 log.debug('remove-interface', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400260 if device.id in self.devices_handlers:
261 handler = self.devices_handlers[device.id]
262 if handler is not None:
263 handler.remove_interface(data)
264
265 def receive_onu_detect_state(self, device_id, state):
266 raise NotImplementedError()
267
268 def create_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400269 log.debug('create-tcont', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400270 if device.id in self.devices_handlers:
271 handler = self.devices_handlers[device.id]
272 if handler is not None:
273 handler.create_tcont(tcont_data, traffic_descriptor_data)
274
275 def update_tcont(self, device, tcont_data, traffic_descriptor_data):
276 raise NotImplementedError()
277
278 def remove_tcont(self, device, tcont_data, traffic_descriptor_data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400279 log.debug('remove-tcont', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400280 if device.id in self.devices_handlers:
281 handler = self.devices_handlers[device.id]
282 if handler is not None:
283 handler.remove_tcont(tcont_data, traffic_descriptor_data)
284
285 def create_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400286 log.debug('create-gemport', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400287 if device.id in self.devices_handlers:
288 handler = self.devices_handlers[device.id]
289 if handler is not None:
290 handler.create_gemport(data)
291
292 def update_gemport(self, device, data):
293 raise NotImplementedError()
294
295 def remove_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400296 log.debug('remove-gemport', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400297 if device.id in self.devices_handlers:
298 handler = self.devices_handlers[device.id]
299 if handler is not None:
300 handler.remove_gemport(data)
301
302 def create_multicast_gemport(self, device, data):
Nicolas Palpacuer324dcae2018-08-02 11:12:22 -0400303 log.debug('create-multicast-gemport', device_id=device.id)
Matt Jeannerete6a70332018-07-20 16:11:25 -0400304 if device.id in self.devices_handlers:
305 handler = self.devices_handlers[device.id]
306 if handler is not None:
307 handler.create_multicast_gemport(data)
308
309 def update_multicast_gemport(self, device, data):
310 raise NotImplementedError()
311
312 def remove_multicast_gemport(self, device, data):
313 raise NotImplementedError()
314
315 def create_multicast_distribution_set(self, device, data):
316 raise NotImplementedError()
317
318 def update_multicast_distribution_set(self, device, data):
319 raise NotImplementedError()
320
321 def remove_multicast_distribution_set(self, device, data):
322 raise NotImplementedError()
323
324 def suppress_alarm(self, filter):
325 raise NotImplementedError()
326
327 def unsuppress_alarm(self, filter):
328 raise NotImplementedError()
329
330