blob: 418ec1e0ac84625b3d64998f4fa1db5d8a3e73ef [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
28from voltha.adapters.microsemi.ActivationWatcher import ActivationWatcher
29from voltha.adapters.microsemi.DeviceManager import DeviceManager
30from voltha.adapters.microsemi.OltStateMachine import OltStateMachine
31from voltha.adapters.microsemi.PAS5211_comm import PAS5211Communication
32from 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
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
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
111 def deactivate_device(self, device):
alshabib661922c2017-02-28 11:18:06 -0800112 self._abandon(device.mac_address)
alshabib22302372016-12-20 13:46:14 -0800113
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 Haraszti656ecc62016-12-28 15:08:23 -0800127 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
alshabib22302372016-12-20 13:46:14 -0800131 ##
132 # Private methods
133 ##
alshabib1dde11c2017-01-24 11:03:04 -0800134 def _init_olt(self, olt, activation_watch):
alshabib22302372016-12-20 13:46:14 -0800135 olt.runbg()
136 activation_watch.runbg()
137
alshabib661922c2017-02-28 11:18:06 -0800138 def _abandon(self, target):
139 olt, activation = self.olts[target]
140 olt.stop()
141 activation.stop()
142
alshabib22302372016-12-20 13:46:14 -0800143
144
145
146
147