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 |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 28 | from pyvoltha.protos import third_party |
| 29 | from pyvoltha.protos.adapter_pb2 import Adapter |
| 30 | from pyvoltha.protos.adapter_pb2 import AdapterConfig |
| 31 | from pyvoltha.protos.common_pb2 import LogLevel |
| 32 | from pyvoltha.protos.device_pb2 import DeviceType, DeviceTypes, Port, Image |
| 33 | from pyvoltha.protos.health_pb2 import HealthStatus |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 34 | |
Matt Jeanneret | 72f96fc | 2019-02-11 10:53:05 -0500 | [diff] [blame] | 35 | from pyvoltha.adapters.common.frameio.frameio import hexify |
| 36 | from pyvoltha.adapters.extensions.omci.openomci_agent import OpenOMCIAgent, OpenOmciAgentDefaults |
| 37 | from pyvoltha.adapters.extensions.omci.omci_me import * |
| 38 | |
| 39 | from brcm_openomci_onu_handler import BrcmOpenomciOnuHandler |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 40 | from omci.brcm_capabilities_task import BrcmCapabilitiesTask |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 41 | from omci.brcm_mib_sync import BrcmMibSynchronizer |
| 42 | from copy import deepcopy |
| 43 | |
| 44 | |
| 45 | _ = third_party |
| 46 | log = structlog.get_logger() |
| 47 | |
| 48 | |
| 49 | @implementer(IAdapterInterface) |
| 50 | class 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 Jeanneret | 2136320 | 2019-02-13 16:21:48 -0500 | [diff] [blame] | 63 | def __init__(self, core_proxy, adapter_proxy, config): |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 64 | log.debug('function-entry', config=config) |
Matt Jeanneret | 0bd63c8 | 2019-02-15 05:40:44 -0500 | [diff] [blame] | 65 | self.adapter_proxy = adapter_proxy |
| 66 | self.adapter_agent = core_proxy |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 67 | self.config = config |
| 68 | self.descriptor = Adapter( |
| 69 | id=self.name, |
| 70 | vendor='Voltha project', |
Matt Jeanneret | 2136320 | 2019-02-13 16:21:48 -0500 | [diff] [blame] | 71 | version='2.0', |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 72 | config=AdapterConfig(log_level=LogLevel.INFO) |
| 73 | ) |
| 74 | self.devices_handlers = dict() |
Matt Jeanneret | 2136320 | 2019-02-13 16:21:48 -0500 | [diff] [blame] | 75 | self.device_handler_class = BrcmOpenomciOnuHandler |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | # Customize OpenOMCI for Broadcom ONUs |
| 78 | self.broadcom_omci = deepcopy(OpenOmciAgentDefaults) |
| 79 | |
| 80 | self.broadcom_omci['mib-synchronizer']['state-machine'] = BrcmMibSynchronizer |
| 81 | self.broadcom_omci['omci-capabilities']['tasks']['get-capabilities'] = BrcmCapabilitiesTask |
| 82 | |
| 83 | # Defer creation of omci agent to a lazy init that allows subclasses to override support classes |
| 84 | |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 85 | def custom_me_entities(self): |
| 86 | return None |
| 87 | |
| 88 | @property |
| 89 | def omci_agent(self): |
| 90 | if not hasattr(self, '_omci_agent') or self._omci_agent is None: |
| 91 | log.debug('creating-omci-agent') |
Matt Jeanneret | 84e56f6 | 2019-02-26 10:48:09 -0500 | [diff] [blame] | 92 | self._omci_agent = OpenOMCIAgent(self.adapter_agent, |
Matt Jeanneret | f1e9c5d | 2019-02-08 07:41:29 -0500 | [diff] [blame] | 93 | support_classes=self.broadcom_omci) |
| 94 | return self._omci_agent |
| 95 | |
| 96 | def start(self): |
| 97 | log.debug('starting') |
| 98 | self.omci_agent.start() |
| 99 | 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 | """ |
| 178 | log.info('self-test-device - Not implemented yet', device=device.id) |
| 179 | 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 | |
| 193 | # 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) |
| 199 | |
| 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): |
| 213 | log.debug('send-proxied-message', proxy_address=proxy_address, msg=msg) |
| 214 | |
| 215 | def receive_proxied_message(self, proxy_address, msg): |
| 216 | log.debug('receive-proxied-message', proxy_address=proxy_address, |
| 217 | 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): |
| 231 | log.debug('receive_inter_adapter_message', msg=msg) |
| 232 | 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): |
| 245 | log.debug('create-interface', device_id=device.id) |
| 246 | 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): |
| 252 | log.debug('update-interface', device_id=device.id) |
| 253 | 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): |
| 259 | log.debug('remove-interface', device_id=device.id) |
| 260 | 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): |
| 269 | log.debug('create-tcont', 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.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): |
| 279 | log.debug('remove-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.remove_tcont(tcont_data, traffic_descriptor_data) |
| 284 | |
| 285 | def create_gemport(self, device, data): |
| 286 | log.debug('create-gemport', 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_gemport(data) |
| 291 | |
| 292 | def update_gemport(self, device, data): |
| 293 | raise NotImplementedError() |
| 294 | |
| 295 | def remove_gemport(self, device, data): |
| 296 | log.debug('remove-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.remove_gemport(data) |
| 301 | |
| 302 | def create_multicast_gemport(self, device, data): |
| 303 | log.debug('create-multicast-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_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 | |