2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowjava.protocol.api.connection;
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;
93 * Manages a switch connection.
96 * @author michal.polkorab
98 public interface ConnectionAdapter {
100 interface SystemListener {
101 void onDisconnect(DisconnectEvent disconnect);
103 void onSwitchIdle(SwitchIdleEvent switchIdle);
105 void onSslConnectionError(SslConnectionError sslConnectionError);
109 interface MessageListener {
111 void onHello(HelloMessage hello);
113 void onError(ErrorMessage error);
115 void onEchoRequest(EchoRequestMessage echoRequest);
117 void onExperimenter(ExperimenterMessage experimenter);
119 void onPacketIn(PacketInMessage packetIn);
121 void onFlowRemoved(FlowRemovedMessage flowRemoved);
123 void onPortStatus(PortStatusMessage portStatus);
125 void onMultipartReply(MultipartReplyMessage multipartReply);
129 * Disconnect corresponding switch.
131 * @return future set to true, when disconnect completed
133 Future<Boolean> disconnect();
136 * Determines if the connection to the switch is alive.
138 * @return true, if connection to switch is alive
143 * Returns the address of the connected switch.
145 * @return address of the remote end - address of a switch if connected
147 InetSocketAddress getRemoteAddress();
150 * Sets the protocol message listener.
152 * @param messageListener here will be pushed all messages from switch
154 void setMessageListener(MessageListener messageListener);
157 * Sets the system message listener.
159 * @param systemListener here will be pushed all system messages from library
161 void setSystemListener(SystemListener systemListener);
164 * Set handler for alien messages received from device.
166 * @param alienMessageListener here will be pushed all alien messages from switch
168 void setAlienMessageListener(AlienMessageListener alienMessageListener);
171 * Throws exception if any of required listeners is missing.
173 void checkListeners();
176 * Notify listener about connection ready-to-use event.
178 void fireConnectionReadyNotification();
181 * Notify listener about switch certificate information.
183 * @param certificateChain X509 certificate chain presented by the switch
185 void onSwitchCertificateIdentified(@Nullable List<X509Certificate> certificateChain);
188 * Set listener for connection became ready-to-use event.
190 * @param connectionReadyListener listens to connection ready event
192 void setConnectionReadyListener(ConnectionReadyListener connectionReadyListener);
195 * Sets option for automatic channel reading - if set to false, incoming messages won't be read.
197 * @param autoRead target value to be switched to
199 void setAutoRead(boolean autoRead);
202 * Determines if the channel is configured to auto-read.
204 * @return true, if channel is configured to auto-read
206 boolean isAutoRead();
209 * Registers a new bypass outbound queue.
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}
218 <T extends OutboundQueueHandler> OutboundQueueHandlerRegistration<T> registerOutboundQueueHandler(T handler,
219 int maxQueueDepth, long maxBarrierNanos);
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.
226 void setPacketInFiltering(boolean enabled);
229 * Set datapathId for the dpn.
230 * @param datapathId of the dpn
232 void setDatapathId(BigInteger datapathId);
235 * Sets executorService.
236 * @param executorService for all dpns
238 void setExecutorService(ExecutorService executorService);
240 // Access to individual requests one can make on a connection.
243 * Invoke {@code barrier} RPC. See also {@link Barrier}.
245 * @param input of {@code barrier}
246 * @return output of {@code barrier}
248 @NonNull ListenableFuture<RpcResult<BarrierOutput>> barrier(BarrierInput input);
251 * Invoke {@code echo} RPC. See also {@link Echo}.
253 * @param input of {@code echo}
254 * @return output of {@code echo}
256 @NonNull ListenableFuture<RpcResult<EchoOutput>> echo(EchoInput input);
259 * Invoke {@code echo-reply} RPC. See also {@link EchoReply}.
261 * @param input of {@code echo-reply}
262 * @return output of {@code echo-reply}
264 @NonNull ListenableFuture<RpcResult<EchoReplyOutput>> echoReply(EchoReplyInput input);
267 * Invoke {@code experimenter} RPC. See also {@link Experimenter}.
269 * @param input of {@code experimenter}
270 * @return output of {@code experimenter}
272 @NonNull ListenableFuture<RpcResult<ExperimenterOutput>> experimenter(ExperimenterInput input);
275 * Invoke {@code flow-mod} RPC. See also {@link FlowMod}.
277 * @param input of {@code flow-mod}
278 * @return output of {@code flow-mod}
280 @NonNull ListenableFuture<RpcResult<FlowModOutput>> flowMod(FlowModInput input);
283 * Invoke {@code get-async} RPC. See also {@link GetAsync}.
285 * @param input of {@code get-async}
286 * @return output of {@code get-async}
288 @NonNull ListenableFuture<RpcResult<GetAsyncOutput>> getAsync(GetAsyncInput input);
291 * Invoke {@code get-config} RPC. See also {@link GetConfig}.
293 * @param input of {@code get-config}
294 * @return output of {@code get-config}
296 @NonNull ListenableFuture<RpcResult<GetConfigOutput>> getConfig(GetConfigInput input);
299 * Invoke {@code get-features} RPC. See also {@link GetFeatures}.
301 * @param input of {@code get-features}
302 * @return output of {@code get-features}
304 @NonNull ListenableFuture<RpcResult<GetFeaturesOutput>> getFeatures(GetFeaturesInput input);
307 * Invoke {@code get-queue-config} RPC. See also {@link GetQueueConfig}.
309 * @param input of {@code get-queue-config}
310 * @return output of {@code get-queue-config}
312 @NonNull ListenableFuture<RpcResult<GetQueueConfigOutput>> getQueueConfig(GetQueueConfigInput input);
315 * Invoke {@code group-mod} RPC. See also {@link GroupMod}.
317 * @param input of {@code group-mod}
318 * @return output of {@code group-mod}
320 @NonNull ListenableFuture<RpcResult<GroupModOutput>> groupMod(GroupModInput input);
323 * Invoke {@code hello} RPC. See also {@link Hello}.
325 * @param input of {@code hello}
326 * @return output of {@code hello}
328 @NonNull ListenableFuture<RpcResult<HelloOutput>> hello(HelloInput input);
331 * Invoke {@code meter-mod} RPC. See also {@link MeterMod}.
333 * @param input of {@code meter-mod}
334 * @return output of {@code meter-mod}
336 @NonNull ListenableFuture<RpcResult<MeterModOutput>> meterMod(MeterModInput input);
339 * Invoke {@code multipart-request} RPC. See also {@link MultipartRequest}.
341 * @param input of {@code multipart-request}
342 * @return output of {@code multipart-request}
344 @NonNull ListenableFuture<RpcResult<MultipartRequestOutput>> multipartRequest(MultipartRequestInput input);
347 * Invoke {@code packet-out} RPC. See also {@link PacketOut}.
349 * @param input of {@code packet-out}
350 * @return output of {@code packet-out}
352 @NonNull ListenableFuture<RpcResult<PacketOutOutput>> packetOut(PacketOutInput input);
355 * Invoke {@code port-mod} RPC. See also {@link PortMod}.
357 * @param input of {@code port-mod}
358 * @return output of {@code port-mod}
360 @NonNull ListenableFuture<RpcResult<PortModOutput>> portMod(PortModInput input);
363 * Invoke {@code role-request} RPC. See also {@link RoleRequest}.
365 * @param input of {@code role-request}
366 * @return output of {@code role-request}
368 @NonNull ListenableFuture<RpcResult<RoleRequestOutput>> roleRequest(RoleRequestInput input);
371 * Invoke {@code set-async} RPC. See also {@link SetAsync}.
373 * @param input of {@code set-async}
374 * @return output of {@code set-async}
376 @NonNull ListenableFuture<RpcResult<SetAsyncOutput>> setAsync(SetAsyncInput input);
379 * Invoke {@code set-config} RPC. See also {@link SetConfig}.
381 * @param input of {@code set-config}
382 * @return output of {@code set-config}
384 @NonNull ListenableFuture<RpcResult<SetConfigOutput>> setConfig(SetConfigInput input);
387 * Invoke {@code table-mod} RPC. See also {@link TableMod}.
389 * @param input of {@code table-mod}
390 * @return output of {@code table-mod}
392 @NonNull ListenableFuture<RpcResult<TableModOutput>> tableMod(TableModInput input);