blob: 532915d5b3b7c48bb0fe875433c5d36e53801943 [file] [log] [blame]
alshabib22302372016-12-20 13:46:14 -08001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
alshabib22302372016-12-20 13:46:14 -08003#
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"""
18Microsemi/Celestica Ruby vOLTHA adapter.
19"""
20from common.frameio.frameio import BpfProgramFilter, FrameIOManager
21from scapy.layers.l2 import Dot3
22import structlog
23from twisted.internet import reactor
24
25
26
27from voltha.adapters.interface import IAdapterInterface
alshabib8b7e0ec2017-03-02 15:12:29 -080028from voltha.adapters.microsemi_olt.ActivationWatcher import ActivationWatcher
29from voltha.adapters.microsemi_olt.DeviceManager import DeviceManager
alshabib38ba2032017-03-14 11:19:58 +010030from voltha.adapters.microsemi_olt.OMCIProxy import OMCIProxy
alshabib8b7e0ec2017-03-02 15:12:29 -080031from voltha.adapters.microsemi_olt.OltStateMachine import OltStateMachine
32from voltha.adapters.microsemi_olt.PAS5211_comm import PAS5211Communication
alshabib22302372016-12-20 13:46:14 -080033from voltha.protos import third_party
34from voltha.protos.adapter_pb2 import Adapter, AdapterConfig
35from voltha.protos.common_pb2 import LogLevel
36from voltha.protos.device_pb2 import DeviceTypes, DeviceType
37from voltha.protos.health_pb2 import HealthStatus
38from voltha.registry import registry
39
40from zope.interface import implementer
41
42log = structlog.get_logger()
43_ = third_party
44
45
46@implementer(IAdapterInterface)
47class RubyAdapter(object):
48
alshabib8b7e0ec2017-03-02 15:12:29 -080049 name = "microsemi_olt"
alshabib22302372016-12-20 13:46:14 -080050
51 supported_device_types = [
52 DeviceType(
alshabib8b7e0ec2017-03-02 15:12:29 -080053 id=name,
alshabib22302372016-12-20 13:46:14 -080054 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
alshabib661922c2017-02-28 11:18:06 -080062 self.olts = {}
alshabib22302372016-12-20 13:46:14 -080063 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')
alshabib661922c2017-02-28 11:18:06 -080079 for target in self.olts.keys():
80 self._abandon(target)
alshabib22302372016-12-20 13:46:14 -080081 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)
alshabib1dde11c2017-01-24 11:03:04 -0800104 reactor.callLater(0, self._init_olt, olt, activation)
alshabib22302372016-12-20 13:46:14 -0800105
106 log.info('adopted-device', device=device)
alshabib661922c2017-02-28 11:18:06 -0800107 self.olts[target] = (olt, activation)
alshabib22302372016-12-20 13:46:14 -0800108
109 def abandon_device(self, device):
alshabib661922c2017-02-28 11:18:06 -0800110 self._abandon(device.mac_address)
alshabib22302372016-12-20 13:46:14 -0800111
Khen Nursimulud068d812017-03-06 11:44:18 -0500112 def disable_device(self, device):
113 raise NotImplementedError()
114
115 def reenable_device(self, device):
116 raise NotImplementedError()
117
Sergio Slobodrianec864c62017-03-09 11:41:43 -0500118 def update_pm_config(self, device, pm_configs):
119 raise NotImplementedError()
120
Khen Nursimulud068d812017-03-06 11:44:18 -0500121 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()
alshabib22302372016-12-20 13:46:14 -0800129
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):
135 log.info('send-proxied-message', proxy_address=proxy_address, msg=msg)
alshabib38ba2032017-03-14 11:19:58 +0100136 # TODO make this more efficient
137 omci_proxy = OMCIProxy(proxy_address=proxy_address,
138 msg=msg)
139 omci_proxy.run()
140 del omci_proxy
alshabib22302372016-12-20 13:46:14 -0800141
142 def receive_proxied_message(self, proxy_address, msg):
143 raise NotImplementedError()
144
145 def update_flows_incrementally(self, device, flow_changes, group_changes):
146 raise NotImplementedError()
147
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800148 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
149 log.info('packet-out', logical_device_id=logical_device_id,
150 egress_port_no=egress_port_no, msg_len=len(msg))
151
alshabib22302372016-12-20 13:46:14 -0800152 ##
153 # Private methods
154 ##
alshabib1dde11c2017-01-24 11:03:04 -0800155 def _init_olt(self, olt, activation_watch):
alshabib22302372016-12-20 13:46:14 -0800156 olt.runbg()
157 activation_watch.runbg()
158
alshabib661922c2017-02-28 11:18:06 -0800159 def _abandon(self, target):
160 olt, activation = self.olts[target]
161 olt.stop()
162 activation.stop()
alshabib8b7e0ec2017-03-02 15:12:29 -0800163 del self.olts[target]
alshabib661922c2017-02-28 11:18:06 -0800164
alshabib22302372016-12-20 13:46:14 -0800165
166
167
168
169