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