blob: 8ac93c50c59fef5bfa77d67c20ce52d8ece87c24 [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"""
alshabib22302372016-12-20 13:46:14 -080020import structlog
21from twisted.internet import reactor
22
alshabib22302372016-12-20 13:46:14 -080023from voltha.adapters.interface import IAdapterInterface
alshabib1ef322b2017-03-16 10:39:59 +010024from voltha.adapters.microsemi_olt.APIProxy import APIProxy
alshabib8b7e0ec2017-03-02 15:12:29 -080025from voltha.adapters.microsemi_olt.ActivationWatcher import ActivationWatcher
26from voltha.adapters.microsemi_olt.DeviceManager import DeviceManager
alshabib38ba2032017-03-14 11:19:58 +010027from voltha.adapters.microsemi_olt.OMCIProxy import OMCIProxy
alshabib8b7e0ec2017-03-02 15:12:29 -080028from voltha.adapters.microsemi_olt.OltStateMachine import OltStateMachine
29from voltha.adapters.microsemi_olt.PAS5211_comm import PAS5211Communication
alshabib1ef322b2017-03-16 10:39:59 +010030from voltha.extensions.omci.omci_frame import OmciFrame
31from voltha.extensions.omci.omci_messages import OmciMessage
alshabib22302372016-12-20 13:46:14 -080032from voltha.protos import third_party
33from voltha.protos.adapter_pb2 import Adapter, AdapterConfig
34from voltha.protos.common_pb2 import LogLevel
35from voltha.protos.device_pb2 import DeviceTypes, DeviceType
36from voltha.protos.health_pb2 import HealthStatus
37from voltha.registry import registry
38
39from zope.interface import implementer
40
41log = structlog.get_logger()
42_ = third_party
43
44
45@implementer(IAdapterInterface)
46class RubyAdapter(object):
47
alshabib8b7e0ec2017-03-02 15:12:29 -080048 name = "microsemi_olt"
alshabib22302372016-12-20 13:46:14 -080049
50 supported_device_types = [
51 DeviceType(
alshabib8b7e0ec2017-03-02 15:12:29 -080052 id=name,
alshabib22302372016-12-20 13:46:14 -080053 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
alshabib661922c2017-02-28 11:18:06 -080061 self.olts = {}
alshabib22302372016-12-20 13:46:14 -080062 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')
alshabib661922c2017-02-28 11:18:06 -080078 for target in self.olts.keys():
79 self._abandon(target)
alshabib22302372016-12-20 13:46:14 -080080 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)
alshabib1dde11c2017-01-24 11:03:04 -0800103 reactor.callLater(0, self._init_olt, olt, activation)
alshabib22302372016-12-20 13:46:14 -0800104
105 log.info('adopted-device', device=device)
alshabib1ef322b2017-03-16 10:39:59 +0100106 self.olts[target] = (olt, activation, comm)
alshabib22302372016-12-20 13:46:14 -0800107
108 def abandon_device(self, device):
alshabib661922c2017-02-28 11:18:06 -0800109 self._abandon(device.mac_address)
alshabib22302372016-12-20 13:46:14 -0800110
Khen Nursimulud068d812017-03-06 11:44:18 -0500111 def disable_device(self, device):
112 raise NotImplementedError()
113
114 def reenable_device(self, device):
115 raise NotImplementedError()
116
Sergio Slobodrianec864c62017-03-09 11:41:43 -0500117 def update_pm_config(self, device, pm_configs):
118 raise NotImplementedError()
119
Khen Nursimulud068d812017-03-06 11:44:18 -0500120 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()
alshabib22302372016-12-20 13:46:14 -0800128
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):
alshabib1ef322b2017-03-16 10:39:59 +0100134 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 Velascof37726b2017-03-14 17:36:55 +0100138 # TODO make this more efficient
139 omci_proxy = OMCIProxy(proxy_address=proxy_address,
alshabib1ef322b2017-03-16 10:39:59 +0100140 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 Velascof37726b2017-03-14 17:36:55 +0100147
148 else:
alshabib1ef322b2017-03-16 10:39:59 +0100149 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()
alshabib22302372016-12-20 13:46:14 -0800157
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 Haraszti656ecc62016-12-28 15:08:23 -0800164 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 Shafikb2ff5a62017-05-02 15:54:39 -0400168 def receive_inter_adapter_message(self, msg):
169 raise NotImplementedError()
170
alshabib22302372016-12-20 13:46:14 -0800171 ##
172 # Private methods
173 ##
alshabib1dde11c2017-01-24 11:03:04 -0800174 def _init_olt(self, olt, activation_watch):
alshabib22302372016-12-20 13:46:14 -0800175 olt.runbg()
176 activation_watch.runbg()
177
alshabib661922c2017-02-28 11:18:06 -0800178 def _abandon(self, target):
alshabib1ef322b2017-03-16 10:39:59 +0100179 olt, activation, _ = self.olts[target]
alshabib661922c2017-02-28 11:18:06 -0800180 olt.stop()
181 activation.stop()
alshabib8b7e0ec2017-03-02 15:12:29 -0800182 del self.olts[target]
alshabib661922c2017-02-28 11:18:06 -0800183
alshabib22302372016-12-20 13:46:14 -0800184
185
186
187
188