Do not use OpenflowProtocolListener in ConnectionAdapter
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / connection / ConnectionAdapter.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowjava.protocol.api.connection;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import java.math.BigInteger;
13 import java.net.InetSocketAddress;
14 import java.security.cert.X509Certificate;
15 import java.util.List;
16 import java.util.concurrent.ExecutorService;
17 import java.util.concurrent.Future;
18 import org.eclipse.jdt.annotation.NonNull;
19 import org.eclipse.jdt.annotation.NonNullByDefault;
20 import org.eclipse.jdt.annotation.Nullable;
21 import org.opendaylight.openflowjava.protocol.api.extensibility.AlienMessageListener;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Barrier;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Echo;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReply;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Experimenter;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterOutput;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowMod;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModInput;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowModOutput;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsync;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncInput;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetAsyncOutput;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfig;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeatures;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfig;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigInput;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupMod;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModInput;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GroupModOutput;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Hello;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloOutput;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterMod;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModInput;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MeterModOutput;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;
64 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequest;
65 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestInput;
66 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestOutput;
67 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
68 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOut;
69 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;
70 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutOutput;
71 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortMod;
72 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModInput;
73 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortModOutput;
74 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
75 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequest;
76 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
77 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestOutput;
78 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsync;
79 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncInput;
80 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncOutput;
81 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfig;
82 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
83 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigOutput;
84 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableMod;
85 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
86 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModOutput;
87 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.DisconnectEvent;
88 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SslConnectionError;
89 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SwitchIdleEvent;
90 import org.opendaylight.yangtools.yang.common.RpcResult;
91
92 /**
93  * Manages a switch connection.
94  *
95  * @author mirehak
96  * @author michal.polkorab
97  */
98 public interface ConnectionAdapter {
99     @NonNullByDefault
100     interface SystemListener {
101         void onDisconnect(DisconnectEvent disconnect);
102
103         void onSwitchIdle(SwitchIdleEvent switchIdle);
104
105         void onSslConnectionError(SslConnectionError sslConnectionError);
106     }
107
108     @NonNullByDefault
109     interface MessageListener {
110
111         void onHello(HelloMessage hello);
112
113         void onError(ErrorMessage error);
114
115         void onEchoRequest(EchoRequestMessage echoRequest);
116
117         void onExperimenter(ExperimenterMessage experimenter);
118
119         void onPacketIn(PacketInMessage packetIn);
120
121         void onFlowRemoved(FlowRemovedMessage flowRemoved);
122
123         void onPortStatus(PortStatusMessage portStatus);
124
125         void onMultipartReply(MultipartReplyMessage multipartReply);
126     }
127
128     /**
129      * Disconnect corresponding switch.
130      *
131      * @return future set to true, when disconnect completed
132      */
133     Future<Boolean> disconnect();
134
135     /**
136      * Determines if the connection to the switch is alive.
137      *
138      * @return true, if connection to switch is alive
139      */
140     boolean isAlive();
141
142     /**
143      * Returns the address of the connected switch.
144      *
145      * @return address of the remote end - address of a switch if connected
146      */
147     InetSocketAddress getRemoteAddress();
148
149     /**
150      * Sets the protocol message listener.
151      *
152      * @param messageListener here will be pushed all messages from switch
153      */
154     void setMessageListener(MessageListener messageListener);
155
156     /**
157      * Sets the system message listener.
158      *
159      * @param systemListener here will be pushed all system messages from library
160      */
161     void setSystemListener(SystemListener systemListener);
162
163     /**
164      * Set handler for alien messages received from device.
165      *
166      * @param alienMessageListener here will be pushed all alien messages from switch
167      */
168     void setAlienMessageListener(AlienMessageListener alienMessageListener);
169
170     /**
171      * Throws exception if any of required listeners is missing.
172      */
173     void checkListeners();
174
175     /**
176      * Notify listener about connection ready-to-use event.
177      */
178     void fireConnectionReadyNotification();
179
180     /**
181      * Notify listener about switch certificate information.
182      *
183      * @param certificateChain X509 certificate chain presented by the switch
184      */
185     void onSwitchCertificateIdentified(@Nullable List<X509Certificate> certificateChain);
186
187     /**
188      * Set listener for connection became ready-to-use event.
189      *
190      * @param connectionReadyListener listens to connection ready event
191      */
192     void setConnectionReadyListener(ConnectionReadyListener connectionReadyListener);
193
194     /**
195      * Sets option for automatic channel reading - if set to false, incoming messages won't be read.
196      *
197      * @param autoRead target value to be switched to
198      */
199     void setAutoRead(boolean autoRead);
200
201     /**
202      * Determines if the channel is configured to auto-read.
203      *
204      * @return true, if channel is configured to auto-read
205      */
206     boolean isAutoRead();
207
208     /**
209      * Registers a new bypass outbound queue.
210      *
211      * @param <T> handler type
212      * @param handler queue handler
213      * @param maxQueueDepth max amount of not confirmed messaged in queue (i.e. edge for barrier message)
214      * @param maxBarrierNanos regular base for barrier message
215      * @return An {@link OutboundQueueHandlerRegistration}
216      */
217     @Beta
218     <T extends OutboundQueueHandler> OutboundQueueHandlerRegistration<T> registerOutboundQueueHandler(T handler,
219         int maxQueueDepth, long maxBarrierNanos);
220
221     /**
222      * Set filtering of PacketIn messages. By default these messages are not filtered.
223      * @param enabled True if PacketIn messages should be filtered, false if they should be reported.
224      */
225     @Beta
226     void setPacketInFiltering(boolean enabled);
227
228     /**
229      * Set datapathId for the dpn.
230      * @param datapathId of the dpn
231      */
232     void setDatapathId(BigInteger datapathId);
233
234     /**
235      * Sets executorService.
236      * @param executorService for all dpns
237      */
238     void setExecutorService(ExecutorService executorService);
239
240     // Access to individual requests one can make on a connection.
241
242     /**
243      * Invoke {@code barrier} RPC. See also {@link Barrier}.
244      *
245      * @param input of {@code barrier}
246      * @return output of {@code barrier}
247      */
248     @NonNull ListenableFuture<RpcResult<BarrierOutput>> barrier(BarrierInput input);
249
250     /**
251      * Invoke {@code echo} RPC. See also {@link Echo}.
252      *
253      * @param input of {@code echo}
254      * @return output of {@code echo}
255      */
256     @NonNull ListenableFuture<RpcResult<EchoOutput>> echo(EchoInput input);
257
258     /**
259      * Invoke {@code echo-reply} RPC. See also {@link EchoReply}.
260      *
261      * @param input of {@code echo-reply}
262      * @return output of {@code echo-reply}
263      */
264     @NonNull ListenableFuture<RpcResult<EchoReplyOutput>> echoReply(EchoReplyInput input);
265
266     /**
267      * Invoke {@code experimenter} RPC. See also {@link Experimenter}.
268      *
269      * @param input of {@code experimenter}
270      * @return output of {@code experimenter}
271      */
272     @NonNull ListenableFuture<RpcResult<ExperimenterOutput>> experimenter(ExperimenterInput input);
273
274     /**
275      * Invoke {@code flow-mod} RPC. See also {@link FlowMod}.
276      *
277      * @param input of {@code flow-mod}
278      * @return output of {@code flow-mod}
279      */
280     @NonNull ListenableFuture<RpcResult<FlowModOutput>> flowMod(FlowModInput input);
281
282     /**
283      * Invoke {@code get-async} RPC. See also {@link GetAsync}.
284      *
285      * @param input of {@code get-async}
286      * @return output of {@code get-async}
287      */
288     @NonNull ListenableFuture<RpcResult<GetAsyncOutput>> getAsync(GetAsyncInput input);
289
290     /**
291      * Invoke {@code get-config} RPC. See also {@link GetConfig}.
292      *
293      * @param input of {@code get-config}
294      * @return output of {@code get-config}
295      */
296     @NonNull ListenableFuture<RpcResult<GetConfigOutput>> getConfig(GetConfigInput input);
297
298     /**
299      * Invoke {@code get-features} RPC. See also {@link GetFeatures}.
300      *
301      * @param input of {@code get-features}
302      * @return output of {@code get-features}
303      */
304     @NonNull ListenableFuture<RpcResult<GetFeaturesOutput>> getFeatures(GetFeaturesInput input);
305
306     /**
307      * Invoke {@code get-queue-config} RPC. See also {@link GetQueueConfig}.
308      *
309      * @param input of {@code get-queue-config}
310      * @return output of {@code get-queue-config}
311      */
312     @NonNull ListenableFuture<RpcResult<GetQueueConfigOutput>> getQueueConfig(GetQueueConfigInput input);
313
314     /**
315      * Invoke {@code group-mod} RPC. See also {@link GroupMod}.
316      *
317      * @param input of {@code group-mod}
318      * @return output of {@code group-mod}
319      */
320     @NonNull ListenableFuture<RpcResult<GroupModOutput>> groupMod(GroupModInput input);
321
322     /**
323      * Invoke {@code hello} RPC. See also {@link Hello}.
324      *
325      * @param input of {@code hello}
326      * @return output of {@code hello}
327      */
328     @NonNull ListenableFuture<RpcResult<HelloOutput>> hello(HelloInput input);
329
330     /**
331      * Invoke {@code meter-mod} RPC. See also {@link MeterMod}.
332      *
333      * @param input of {@code meter-mod}
334      * @return output of {@code meter-mod}
335      */
336     @NonNull ListenableFuture<RpcResult<MeterModOutput>> meterMod(MeterModInput input);
337
338     /**
339      * Invoke {@code multipart-request} RPC. See also {@link MultipartRequest}.
340      *
341      * @param input of {@code multipart-request}
342      * @return output of {@code multipart-request}
343      */
344     @NonNull ListenableFuture<RpcResult<MultipartRequestOutput>> multipartRequest(MultipartRequestInput input);
345
346     /**
347      * Invoke {@code packet-out} RPC. See also {@link PacketOut}.
348      *
349      * @param input of {@code packet-out}
350      * @return output of {@code packet-out}
351      */
352     @NonNull ListenableFuture<RpcResult<PacketOutOutput>> packetOut(PacketOutInput input);
353
354     /**
355      * Invoke {@code port-mod} RPC. See also {@link PortMod}.
356      *
357      * @param input of {@code port-mod}
358      * @return output of {@code port-mod}
359      */
360     @NonNull ListenableFuture<RpcResult<PortModOutput>> portMod(PortModInput input);
361
362     /**
363      * Invoke {@code role-request} RPC. See also {@link RoleRequest}.
364      *
365      * @param input of {@code role-request}
366      * @return output of {@code role-request}
367      */
368     @NonNull ListenableFuture<RpcResult<RoleRequestOutput>> roleRequest(RoleRequestInput input);
369
370     /**
371      * Invoke {@code set-async} RPC. See also {@link SetAsync}.
372      *
373      * @param input of {@code set-async}
374      * @return output of {@code set-async}
375      */
376     @NonNull ListenableFuture<RpcResult<SetAsyncOutput>> setAsync(SetAsyncInput input);
377
378     /**
379      * Invoke {@code set-config} RPC. See also {@link SetConfig}.
380      *
381      * @param input of {@code set-config}
382      * @return output of {@code set-config}
383      */
384     @NonNull ListenableFuture<RpcResult<SetConfigOutput>> setConfig(SetConfigInput input);
385
386     /**
387      * Invoke {@code table-mod} RPC. See also {@link TableMod}.
388      *
389      * @param input of {@code table-mod}
390      * @return output of {@code table-mod}
391      */
392     @NonNull ListenableFuture<RpcResult<TableModOutput>> tableMod(TableModInput input);
393 }