alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 1 | # |
Zsolt Haraszti | 3eb27a5 | 2017-01-03 21:56:48 -0800 | [diff] [blame] | 2 | # Copyright 2017 the original author or authors. |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 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 | Microsemi/Celestica Ruby vOLTHA adapter. |
| 19 | """ |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 20 | import structlog |
| 21 | from twisted.internet import reactor |
| 22 | |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 23 | from voltha.adapters.interface import IAdapterInterface |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 24 | from voltha.adapters.microsemi_olt.APIProxy import APIProxy |
alshabib | 8b7e0ec | 2017-03-02 15:12:29 -0800 | [diff] [blame] | 25 | from voltha.adapters.microsemi_olt.ActivationWatcher import ActivationWatcher |
| 26 | from voltha.adapters.microsemi_olt.DeviceManager import DeviceManager |
alshabib | 38ba203 | 2017-03-14 11:19:58 +0100 | [diff] [blame] | 27 | from voltha.adapters.microsemi_olt.OMCIProxy import OMCIProxy |
alshabib | 8b7e0ec | 2017-03-02 15:12:29 -0800 | [diff] [blame] | 28 | from voltha.adapters.microsemi_olt.OltStateMachine import OltStateMachine |
| 29 | from voltha.adapters.microsemi_olt.PAS5211_comm import PAS5211Communication |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 30 | from voltha.extensions.omci.omci_frame import OmciFrame |
| 31 | from voltha.extensions.omci.omci_messages import OmciMessage |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 32 | from voltha.protos import third_party |
| 33 | from voltha.protos.adapter_pb2 import Adapter, AdapterConfig |
| 34 | from voltha.protos.common_pb2 import LogLevel |
| 35 | from voltha.protos.device_pb2 import DeviceTypes, DeviceType |
| 36 | from voltha.protos.health_pb2 import HealthStatus |
| 37 | from voltha.registry import registry |
| 38 | |
| 39 | from zope.interface import implementer |
| 40 | |
| 41 | log = structlog.get_logger() |
| 42 | _ = third_party |
| 43 | |
| 44 | |
| 45 | @implementer(IAdapterInterface) |
| 46 | class RubyAdapter(object): |
| 47 | |
alshabib | 8b7e0ec | 2017-03-02 15:12:29 -0800 | [diff] [blame] | 48 | name = "microsemi_olt" |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 49 | |
| 50 | supported_device_types = [ |
| 51 | DeviceType( |
alshabib | 8b7e0ec | 2017-03-02 15:12:29 -0800 | [diff] [blame] | 52 | id=name, |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 53 | adapter=name, |
| 54 | accepts_bulk_flow_update=True |
| 55 | ) |
| 56 | ] |
| 57 | |
| 58 | def __init__(self, adaptor_agent, config): |
| 59 | self.adaptor_agent = adaptor_agent |
| 60 | self.config = config |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 61 | self.olts = {} |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 62 | self.descriptor = Adapter( |
| 63 | id=self.name, |
| 64 | vendor='Microsemi / Celestica', |
| 65 | version='0.1', |
| 66 | config=AdapterConfig(log_level=LogLevel.INFO) |
| 67 | ) |
| 68 | |
| 69 | self.interface = registry('main').get_args().interface |
| 70 | |
| 71 | def start(self): |
| 72 | log.info('starting') |
| 73 | log.info('started') |
| 74 | return self |
| 75 | |
| 76 | def stop(self): |
| 77 | log.debug('stopping') |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 78 | for target in self.olts.keys(): |
| 79 | self._abandon(target) |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 80 | log.info('stopped') |
| 81 | return self |
| 82 | |
| 83 | def adapter_descriptor(self): |
| 84 | return self.descriptor |
| 85 | |
| 86 | def device_types(self): |
| 87 | return DeviceTypes(items=self.supported_device_types) |
| 88 | |
| 89 | def health(self): |
| 90 | return HealthStatus(state=HealthStatus.HealthState.HEALTHY) |
| 91 | |
| 92 | def change_master_state(self, master): |
| 93 | raise NotImplementedError() |
| 94 | |
| 95 | def adopt_device(self, device): |
| 96 | device_manager = DeviceManager(device, self.adaptor_agent) |
| 97 | target = device.mac_address |
| 98 | comm = PAS5211Communication(dst_mac=target, iface=self.interface) |
| 99 | olt = OltStateMachine(iface=self.interface, comm=comm, |
| 100 | target=target, device=device_manager) |
| 101 | activation = ActivationWatcher(iface=self.interface, comm=comm, |
| 102 | target=target, device=device_manager) |
alshabib | 1dde11c | 2017-01-24 11:03:04 -0800 | [diff] [blame] | 103 | reactor.callLater(0, self._init_olt, olt, activation) |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 104 | |
| 105 | log.info('adopted-device', device=device) |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 106 | self.olts[target] = (olt, activation, comm) |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 107 | |
| 108 | def abandon_device(self, device): |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 109 | self._abandon(device.mac_address) |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 110 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 111 | def disable_device(self, device): |
| 112 | raise NotImplementedError() |
| 113 | |
| 114 | def reenable_device(self, device): |
| 115 | raise NotImplementedError() |
| 116 | |
Sergio Slobodrian | ec864c6 | 2017-03-09 11:41:43 -0500 | [diff] [blame] | 117 | def update_pm_config(self, device, pm_configs): |
| 118 | raise NotImplementedError() |
| 119 | |
Khen Nursimulu | d068d81 | 2017-03-06 11:44:18 -0500 | [diff] [blame] | 120 | def reboot_device(self, device): |
| 121 | raise NotImplementedError() |
| 122 | |
| 123 | def delete_device(self, device): |
| 124 | raise NotImplementedError() |
| 125 | |
| 126 | def get_device_details(self, device): |
| 127 | raise NotImplementedError() |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 128 | |
| 129 | def update_flows_bulk(self, device, flows, groups): |
| 130 | log.debug('bulk-flow-update', device_id=device.id, |
| 131 | flows=flows, groups=groups) |
| 132 | |
| 133 | def send_proxied_message(self, proxy_address, msg): |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 134 | device = self.adaptor_agent.get_device(proxy_address.device_id) |
| 135 | _, _, comm = self.olts[device.mac_address] |
| 136 | if isinstance(msg, OmciFrame): |
| 137 | log.info('send-omci-proxied-message', proxy_address=proxy_address, device=device) |
Daniel Velasco | f37726b | 2017-03-14 17:36:55 +0100 | [diff] [blame] | 138 | # TODO make this more efficient |
| 139 | omci_proxy = OMCIProxy(proxy_address=proxy_address, |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 140 | msg=msg, |
| 141 | adapter_agent=self.adaptor_agent, |
| 142 | target=device.mac_address, |
| 143 | comm=comm, |
| 144 | iface=self.interface) |
| 145 | omci_proxy.runbg() |
| 146 | |
Daniel Velasco | f37726b | 2017-03-14 17:36:55 +0100 | [diff] [blame] | 147 | |
| 148 | else: |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 149 | log.info('send-proxied-message', proxy_address=proxy_address) |
| 150 | api_proxy = APIProxy(proxy_address=proxy_address, |
| 151 | msg=msg, |
| 152 | adapter_agent=self.adaptor_agent, |
| 153 | target=device.mac_address, |
| 154 | comm=comm, |
| 155 | iface=self.interface) |
| 156 | api_proxy.runbg() |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 157 | |
| 158 | def receive_proxied_message(self, proxy_address, msg): |
| 159 | raise NotImplementedError() |
| 160 | |
| 161 | def update_flows_incrementally(self, device, flow_changes, group_changes): |
| 162 | raise NotImplementedError() |
| 163 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 164 | def receive_packet_out(self, logical_device_id, egress_port_no, msg): |
| 165 | log.info('packet-out', logical_device_id=logical_device_id, |
| 166 | egress_port_no=egress_port_no, msg_len=len(msg)) |
| 167 | |
Peter Shafik | b2ff5a6 | 2017-05-02 15:54:39 -0400 | [diff] [blame] | 168 | def receive_inter_adapter_message(self, msg): |
| 169 | raise NotImplementedError() |
| 170 | |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 171 | ## |
| 172 | # Private methods |
| 173 | ## |
alshabib | 1dde11c | 2017-01-24 11:03:04 -0800 | [diff] [blame] | 174 | def _init_olt(self, olt, activation_watch): |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 175 | olt.runbg() |
| 176 | activation_watch.runbg() |
| 177 | |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 178 | def _abandon(self, target): |
alshabib | 1ef322b | 2017-03-16 10:39:59 +0100 | [diff] [blame] | 179 | olt, activation, _ = self.olts[target] |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 180 | olt.stop() |
| 181 | activation.stop() |
alshabib | 8b7e0ec | 2017-03-02 15:12:29 -0800 | [diff] [blame] | 182 | del self.olts[target] |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame] | 183 | |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |