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