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 |
| 28 | from voltha.adapters.microsemi.ActivationWatcher import ActivationWatcher |
| 29 | from voltha.adapters.microsemi.DeviceManager import DeviceManager |
| 30 | from voltha.adapters.microsemi.OltStateMachine import OltStateMachine |
| 31 | from voltha.adapters.microsemi.PAS5211_comm import PAS5211Communication |
| 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 | |
| 48 | name = "microsemi" |
| 49 | |
| 50 | supported_device_types = [ |
| 51 | DeviceType( |
| 52 | id='microsemi', |
| 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 | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame^] | 106 | self.olts[target] = (olt, activation) |
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 | |
| 111 | def deactivate_device(self, device): |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame^] | 112 | self._abandon(device.mac_address) |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 113 | |
| 114 | def update_flows_bulk(self, device, flows, groups): |
| 115 | log.debug('bulk-flow-update', device_id=device.id, |
| 116 | flows=flows, groups=groups) |
| 117 | |
| 118 | def send_proxied_message(self, proxy_address, msg): |
| 119 | log.info('send-proxied-message', proxy_address=proxy_address, msg=msg) |
| 120 | |
| 121 | def receive_proxied_message(self, proxy_address, msg): |
| 122 | raise NotImplementedError() |
| 123 | |
| 124 | def update_flows_incrementally(self, device, flow_changes, group_changes): |
| 125 | raise NotImplementedError() |
| 126 | |
Zsolt Haraszti | 656ecc6 | 2016-12-28 15:08:23 -0800 | [diff] [blame] | 127 | def receive_packet_out(self, logical_device_id, egress_port_no, msg): |
| 128 | log.info('packet-out', logical_device_id=logical_device_id, |
| 129 | egress_port_no=egress_port_no, msg_len=len(msg)) |
| 130 | |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 131 | ## |
| 132 | # Private methods |
| 133 | ## |
alshabib | 1dde11c | 2017-01-24 11:03:04 -0800 | [diff] [blame] | 134 | def _init_olt(self, olt, activation_watch): |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 135 | olt.runbg() |
| 136 | activation_watch.runbg() |
| 137 | |
alshabib | 661922c | 2017-02-28 11:18:06 -0800 | [diff] [blame^] | 138 | def _abandon(self, target): |
| 139 | olt, activation = self.olts[target] |
| 140 | olt.stop() |
| 141 | activation.stop() |
| 142 | |
alshabib | 2230237 | 2016-12-20 13:46:14 -0800 | [diff] [blame] | 143 | |
| 144 | |
| 145 | |
| 146 | |
| 147 | |