blob: 60c27f1ce87e8531cc3cf0e37887a2607d349c55 [file] [log] [blame]
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -08001#
Zsolt Haraszti3eb27a52017-01-03 21:56:48 -08002# Copyright 2017 the original author or authors.
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -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"""
18Interface definition for Voltha Adapters
19"""
20from zope.interface import Interface
21
22
23class IAdapterInterface(Interface):
24 """
25 A Voltha adapter
26 """
27
28 def start():
29 """
30 Called once after adapter instance is laoded. Can be used to async
31 initialization.
32 :return: (None or Deferred)
33 """
34
35 def stop():
36 """
37 Called once before adapter is unloaded. It can be used to perform
38 any cleanup after the adapter.
39 :return: (None or Deferred)
40 """
41
42 def adapter_descriptor():
43 """
44 Return the adapter descriptor object for this adapter.
45 :return: voltha.Adapter grpc object (see voltha/protos/adapter.proto),
46 with adapter-specific information and config extensions.
47 """
48
49 def device_types():
50 """
51 Return list of device types supported by the adapter.
52 :return: voltha.DeviceTypes protobuf object, with optional type
53 specific extensions.
54 """
55
56 def health():
57 """
58 Return a 3-state health status using the voltha.HealthStatus message.
59 :return: Deferred or direct return with voltha.HealthStatus message
60 """
61
62 def change_master_state(master):
63 """
64 Called to indicate if plugin shall assume or lose master role. The
65 master role can be used to perform functions that must be performed
66 from a single point in the cluster. In single-node deployments of
67 Voltha, the plugins are always in master role.
68 :param master: (bool) True to indicate the mastership needs to be
69 assumed; False to indicate that mastership needs to be abandoned.
70 :return: (Deferred) which is fired by the adapter when mastership is
71 assumed/dropped, respectively.
72 """
73
74 def adopt_device(device):
75 """
76 Make sure the adapter looks after given device. Called when a device
77 is provisioned top-down and needs to be activated by the adapter.
78 :param device: A voltha.Device object, with possible device-type
79 specific extensions. Such extensions shall be described as part of
80 the device type specification returned by device_types().
81 :return: (Deferred) Shall be fired to acknowledge device ownership.
82 """
83
84 def abandon_device(device):
85 """
86 Make sur ethe adapter no longer looks after device. This is called
87 if device ownership is taken over by another Voltha instance.
88 :param device: A Voltha.Device object.
89 :return: (Deferred) Shall be fired to acknowledge abandonment.
90 """
91
Khen Nursimulud068d812017-03-06 11:44:18 -050092 def disable_device(device):
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -080093 """
Khen Nursimulud068d812017-03-06 11:44:18 -050094 This is called when a previously enabled device needs to be disabled
95 based on a NBI call.
Zsolt Harasztic5c5d102016-12-07 21:12:27 -080096 :param device: A Voltha.Device object.
Khen Nursimulud068d812017-03-06 11:44:18 -050097 :return: (Deferred) Shall be fired to acknowledge disabling the device.
98 """
99
100 def reenable_device(device):
101 """
102 This is called when a previously disabled device needs to be enabled
103 based on a NBI call.
104 :param device: A Voltha.Device object.
105 :return: (Deferred) Shall be fired to acknowledge re-enabling the
106 device.
107 """
108
109 def reboot_device(device):
110 """
111 This is called to reboot a device based on a NBI call. The admin
112 state of the device will not change after the reboot
113 :param device: A Voltha.Device object.
114 :return: (Deferred) Shall be fired to acknowledge the reboot.
115 """
116
117 def delete_device(device):
118 """
119 This is called to delete a device from the PON based on a NBI call.
120 If the device is an OLT then the whole PON will be deleted.
121 :param device: A Voltha.Device object.
122 :return: (Deferred) Shall be fired to acknowledge the deletion.
123 """
124
125 def get_device_details(device):
126 """
127 This is called to get additional device details based on a NBI call.
128 :param device: A Voltha.Device object.
129 :return: (Deferred) Shall be fired to acknowledge the retrieval of
130 additional details.
Zsolt Haraszti7eeb2b32016-11-06 14:04:55 -0800131 """
132
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800133 def update_flows_bulk(device, flows, groups):
134 """
135 Called after any flow table change, but only if the device supports
136 bulk mode, which is expressed by the 'accepts_bulk_flow_update'
137 capability attribute of the device type.
138 :param device: A Voltha.Device object.
139 :param flows: An openflow_v13.Flows object
140 :param groups: An openflow_v13.Flows object
141 :return: (Deferred or None)
142 """
143
144 def update_flows_incrementally(device, flow_changes, group_changes):
145 """
146 [This mode is not supported yet.]
147 :param device: A Voltha.Device object.
148 :param flow_changes:
149 :param group_changes:
150 :return:
151 """
152
Sergio Slobodrianec864c62017-03-09 11:41:43 -0500153 def update_pm_config(device, pm_configs):
Sergio Slobodriana2eb52b2017-03-07 12:24:46 -0500154 """
155 Called every time a request is made to change pm collection behavior
156 :param device: A Voltha.Device object
157 :param pm_collection_config: A Pms
158 """
159
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800160 def send_proxied_message(proxy_address, msg):
161 """
162 Forward a msg to a child device of device, addressed by the given
163 proxy_address=Device.ProxyAddress().
164 :param proxy_address: Address info for the parent device
165 to route the message to the child device. This was given to the
166 child device by the parent device at the creation of the child
167 device.
168 :param msg: (str) The actual message to send.
169 :return: (Deferred(None) or None) The return of this method should
170 indicate that the message was successfully *sent*.
171 """
172
173 def receive_proxied_message(proxy_address, msg):
174 """
175 Pass an async message (arrived via a proxy) to this device.
176 :param proxy_address: Address info for the parent device
177 to route the message to the child device. This was given to the
178 child device by the parent device at the creation of the child
179 device. Note this is the proxy_address with which the adapter
180 had to register prior to receiving proxied messages.
181 :param msg: (str) The actual message received.
182 :return: None
183 """
184
Zsolt Haraszti656ecc62016-12-28 15:08:23 -0800185 def receive_packet_out(logical_device_id, egress_port_no, msg):
186 """
187 Pass a packet_out message content to adapter so that it can forward it
188 out to the device. This is only called on root devices.
189 :param logical_device_id:
190 :param egress_port: egress logical port number
191 :param msg: actual message
192 :return: None
193 """
194
Peter Shafikb2ff5a62017-05-02 15:54:39 -0400195 def receive_inter_adapter_message(msg):
196 """
197 Called when the adapter recieves a message that was sent to it directly
198 from another adapter. An adapter may register for these messages by calling
199 the register_for_inter_adapter_messages() method in the adapter agent.
200 Note that it is the responsibility of the sending and receiving
201 adapters to properly encode and decode the message.
202 :param msg: The message contents.
203 :return: None
204 """
205
Khen Nursimulud068d812017-03-06 11:44:18 -0500206 # TODO work in progress
207 # ...
Zsolt Haraszti00d9a842016-11-23 11:18:23 -0800208
209
Zsolt Haraszti66862032016-11-28 14:28:39 -0800210class IAdapterAgent(Interface):
Zsolt Haraszti00d9a842016-11-23 11:18:23 -0800211 """
212 This object is passed in to the __init__ function of each adapter,
213 and can be used by the adapter implementation to initiate async calls
214 toward Voltha's CORE via the APIs defined here.
215 """
216
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800217 def get_device(device_id):
Zsolt Haraszti66862032016-11-28 14:28:39 -0800218 # TODO add doc
219 """"""
220
221 def add_device(device):
222 # TODO add doc
223 """"""
224
225 def update_device(device):
Zsolt Haraszti00d9a842016-11-23 11:18:23 -0800226 # TODO add doc
227 """"""
228
229 def add_port(device_id, port):
230 # TODO add doc
231 """"""
232
233 def create_logical_device(logical_device):
234 # TODO add doc
235 """"""
236
237 def add_logical_port(logical_device_id, port):
238 # TODO add doc
239 """"""
240
Zsolt Haraszti66862032016-11-28 14:28:39 -0800241 def child_device_detected(parent_device_id,
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800242 parent_port_no,
Zsolt Haraszti66862032016-11-28 14:28:39 -0800243 child_device_type,
Zsolt Haraszti89a27302016-12-08 16:53:06 -0800244 proxy_address,
245 **kw):
Zsolt Haraszti66862032016-11-28 14:28:39 -0800246 # TODO add doc
247 """"""
248
Zsolt Harasztic5c5d102016-12-07 21:12:27 -0800249 def send_proxied_message(proxy_address, msg):
250 """
251 Forward a msg to a child device of device, addressed by the given
252 proxy_address=Device.ProxyAddress().
253 :param proxy_address: Address info for the parent device
254 to route the message to the child device. This was given to the
255 child device by the parent device at the creation of the child
256 device.
257 :param msg: (str) The actual message to send.
258 :return: (Deferred(None) or None) The return of this method should
259 indicate that the message was successfully *sent*.
260 """
261
262 def receive_proxied_message(proxy_address, msg):
263 """
264 Pass an async message (arrived via a proxy) to this device.
265 :param proxy_address: Address info for the parent device
266 to route the message to the child device. This was given to the
267 child device by the parent device at the creation of the child
268 device. Note this is the proxy_address with which the adapter
269 had to register prior to receiving proxied messages.
270 :param msg: (str) The actual message received.
271 :return: None
272 """
273
274 def register_for_proxied_messages(proxy_address):
275 """
276 A child device adapter can use this to indicate its intent to
277 receive async messages sent via a parent device. Example: an
278 ONU adapter can use this to register for OMCI messages received
279 via the OLT and the OLT adapter.
280 :param child_device_address: Address info that was given to the
281 child device by the parent device at the creation of the child
282 device. Its uniqueness acts as a router information for the
283 registration.
284 :return: None
285 """
286
287 def unregister_for_proxied_messages(proxy_address):
288 """
289 Cancel a previous registration
290 :return:
291 """
Zsolt Haraszti00d9a842016-11-23 11:18:23 -0800292
Zsolt Haraszti8925d1f2016-12-21 00:45:19 -0800293 def send_packet_in(logical_device_id, logical_port_no, packet):
294 """
295 Forward given packet to the northbound toward an SDN controller.
296 :param device_id: logical device identifier
297 :param logical_port_no: logical port_no (as numbered in openflow)
298 :param packet: the actual packet; can be a serialized string or a scapy
299 Packet.
300 :return: None returned on success
301 """
Zsolt Haraszti00d9a842016-11-23 11:18:23 -0800302
Zsolt Haraszti749b0952017-01-18 09:02:35 -0800303 def submit_kpis(kpi_event_msg):
304 """
305 Submit KPI metrics on behalf of the OLT and its adapter. This can
306 include hardware related metrics, usage and utilization metrics, as
307 well as optional adapter specific metrics.
308 :param kpi_event_msg: A protobuf message of KpiEvent type.
309 :return: None
310 """
Stephane Barbarie52198b92017-03-02 13:44:46 -0500311
Stephane Barbarieee409292017-04-24 10:30:20 -0400312 def submit_alarm(device_id, alarm_event_msg):
Stephane Barbarie52198b92017-03-02 13:44:46 -0500313 """
314 Submit an alarm on behalf of the OLT and its adapter.
315 :param alarm_event_msg: A protobuf message of AlarmEvent type.
316 :return: None
317 """