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