blob: bd87ea77a52fb777608f86566d385b5ddad1f456 [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
61 self.descriptor = Adapter(
62 id=self.name,
63 vendor='Microsemi / Celestica',
64 version='0.1',
65 config=AdapterConfig(log_level=LogLevel.INFO)
66 )
67
68 self.interface = registry('main').get_args().interface
69
70 def start(self):
71 log.info('starting')
72 log.info('started')
73 return self
74
75 def stop(self):
76 log.debug('stopping')
77 # TODO Stop all OLTs
78 log.info('stopped')
79 return self
80
81 def adapter_descriptor(self):
82 return self.descriptor
83
84 def device_types(self):
85 return DeviceTypes(items=self.supported_device_types)
86
87 def health(self):
88 return HealthStatus(state=HealthStatus.HealthState.HEALTHY)
89
90 def change_master_state(self, master):
91 raise NotImplementedError()
92
93 def adopt_device(self, device):
94 device_manager = DeviceManager(device, self.adaptor_agent)
95 target = device.mac_address
96 comm = PAS5211Communication(dst_mac=target, iface=self.interface)
97 olt = OltStateMachine(iface=self.interface, comm=comm,
98 target=target, device=device_manager)
99 activation = ActivationWatcher(iface=self.interface, comm=comm,
100 target=target, device=device_manager)
alshabib1dde11c2017-01-24 11:03:04 -0800101 reactor.callLater(0, self._init_olt, olt, activation)
alshabib22302372016-12-20 13:46:14 -0800102
103 log.info('adopted-device', device=device)
104 # TODO store olt elements
105
106 def abandon_device(self, device):
107 raise NotImplementedError(0)
108
109 def deactivate_device(self, device):
110 raise NotImplementedError()
111
112 def update_flows_bulk(self, device, flows, groups):
113 log.debug('bulk-flow-update', device_id=device.id,
114 flows=flows, groups=groups)
115
116 def send_proxied_message(self, proxy_address, msg):
117 log.info('send-proxied-message', proxy_address=proxy_address, msg=msg)
118
119 def receive_proxied_message(self, proxy_address, msg):
120 raise NotImplementedError()
121
122 def update_flows_incrementally(self, device, flow_changes, group_changes):
123 raise NotImplementedError()
124
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800125 def receive_packet_out(self, logical_device_id, egress_port_no, msg):
126 log.info('packet-out', logical_device_id=logical_device_id,
127 egress_port_no=egress_port_no, msg_len=len(msg))
128
alshabib22302372016-12-20 13:46:14 -0800129 ##
130 # Private methods
131 ##
alshabib1dde11c2017-01-24 11:03:04 -0800132 def _init_olt(self, olt, activation_watch):
alshabib22302372016-12-20 13:46:14 -0800133 olt.runbg()
134 activation_watch.runbg()
135
136
137
138
139
140