blob: addfd3431e93f88b7b2636d46fb0e9a8cba3e0a8 [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
30from voltha.adapters.microsemi_olt.OltStateMachine import OltStateMachine
31from voltha.adapters.microsemi_olt.PAS5211_comm import PAS5211Communication
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)
alshabib661922c2017-02-28 11:18:06 -0800106 self.olts[target] = (olt, activation)
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):
134 log.info('send-proxied-message', proxy_address=proxy_address, msg=msg)
135
136 def receive_proxied_message(self, proxy_address, msg):
137 raise NotImplementedError()
138
139 def update_flows_incrementally(self, device, flow_changes, group_changes):
140 raise NotImplementedError()
141
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800142 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
143 log.info('packet-out', logical_device_id=logical_device_id,
144 egress_port_no=egress_port_no, msg_len=len(msg))
145
alshabib22302372016-12-20 13:46:14 -0800146 ##
147 # Private methods
148 ##
alshabib1dde11c2017-01-24 11:03:04 -0800149 def _init_olt(self, olt, activation_watch):
alshabib22302372016-12-20 13:46:14 -0800150 olt.runbg()
151 activation_watch.runbg()
152
alshabib661922c2017-02-28 11:18:06 -0800153 def _abandon(self, target):
154 olt, activation = self.olts[target]
155 olt.stop()
156 activation.stop()
alshabib8b7e0ec2017-03-02 15:12:29 -0800157 del self.olts[target]
alshabib661922c2017-02-28 11:18:06 -0800158
alshabib22302372016-12-20 13:46:14 -0800159
160
161
162
163