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.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;
86 * Manages a switch connection.
89 * @author michal.polkorab
91 public interface ConnectionAdapter {
93 interface SystemListener {
94 void onDisconnect(DisconnectEvent disconnect);
96 void onSwitchIdle(SwitchIdleEvent switchIdle);
98 void onSslConnectionError(SslConnectionError sslConnectionError);
102 * Disconnect corresponding switch.
104 * @return future set to true, when disconnect completed
106 Future<Boolean> disconnect();
109 * Determines if the connection to the switch is alive.
111 * @return true, if connection to switch is alive
116 * Returns the address of the connected switch.
118 * @return address of the remote end - address of a switch if connected
120 InetSocketAddress getRemoteAddress();
123 * Sets the protocol message listener.
125 * @param messageListener here will be pushed all messages from switch
127 void setMessageListener(OpenflowProtocolListener messageListener);
130 * Sets the system message listener.
132 * @param systemListener here will be pushed all system messages from library
134 void setSystemListener(SystemListener systemListener);
137 * Set handler for alien messages received from device.
139 * @param alienMessageListener here will be pushed all alien messages from switch
141 void setAlienMessageListener(AlienMessageListener alienMessageListener);
144 * Throws exception if any of required listeners is missing.
146 void checkListeners();
149 * Notify listener about connection ready-to-use event.
151 void fireConnectionReadyNotification();
154 * Notify listener about switch certificate information.
156 * @param certificateChain X509 certificate chain presented by the switch
158 void onSwitchCertificateIdentified(@Nullable List<X509Certificate> certificateChain);
161 * Set listener for connection became ready-to-use event.
163 * @param connectionReadyListener listens to connection ready event
165 void setConnectionReadyListener(ConnectionReadyListener connectionReadyListener);
168 * Sets option for automatic channel reading - if set to false, incoming messages won't be read.
170 * @param autoRead target value to be switched to
172 void setAutoRead(boolean autoRead);
175 * Determines if the channel is configured to auto-read.
177 * @return true, if channel is configured to auto-read
179 boolean isAutoRead();
182 * Registers a new bypass outbound queue.
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}
191 <T extends OutboundQueueHandler> OutboundQueueHandlerRegistration<T> registerOutboundQueueHandler(T handler,
192 int maxQueueDepth, long maxBarrierNanos);
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.
199 void setPacketInFiltering(boolean enabled);
202 * Set datapathId for the dpn.
203 * @param datapathId of the dpn
205 void setDatapathId(BigInteger datapathId);
208 * Sets executorService.
209 * @param executorService for all dpns
211 void setExecutorService(ExecutorService executorService);
213 // Access to individual requests one can make on a connection.
216 * Invoke {@code barrier} RPC. See also {@link Barrier}.
218 * @param input of {@code barrier}
219 * @return output of {@code barrier}
221 @NonNull ListenableFuture<RpcResult<BarrierOutput>> barrier(BarrierInput input);
224 * Invoke {@code echo} RPC. See also {@link Echo}.
226 * @param input of {@code echo}
227 * @return output of {@code echo}
229 @NonNull ListenableFuture<RpcResult<EchoOutput>> echo(EchoInput input);
232 * Invoke {@code echo-reply} RPC. See also {@link EchoReply}.
234 * @param input of {@code echo-reply}
235 * @return output of {@code echo-reply}
237 @NonNull ListenableFuture<RpcResult<EchoReplyOutput>> echoReply(EchoReplyInput input);
240 * Invoke {@code experimenter} RPC. See also {@link Experimenter}.
242 * @param input of {@code experimenter}
243 * @return output of {@code experimenter}
245 @NonNull ListenableFuture<RpcResult<ExperimenterOutput>> experimenter(ExperimenterInput input);
248 * Invoke {@code flow-mod} RPC. See also {@link FlowMod}.
250 * @param input of {@code flow-mod}
251 * @return output of {@code flow-mod}
253 @NonNull ListenableFuture<RpcResult<FlowModOutput>> flowMod(FlowModInput input);
256 * Invoke {@code get-async} RPC. See also {@link GetAsync}.
258 * @param input of {@code get-async}
259 * @return output of {@code get-async}
261 @NonNull ListenableFuture<RpcResult<GetAsyncOutput>> getAsync(GetAsyncInput input);
264 * Invoke {@code get-config} RPC. See also {@link GetConfig}.
266 * @param input of {@code get-config}
267 * @return output of {@code get-config}
269 @NonNull ListenableFuture<RpcResult<GetConfigOutput>> getConfig(GetConfigInput input);
272 * Invoke {@code get-features} RPC. See also {@link GetFeatures}.
274 * @param input of {@code get-features}
275 * @return output of {@code get-features}
277 @NonNull ListenableFuture<RpcResult<GetFeaturesOutput>> getFeatures(GetFeaturesInput input);
280 * Invoke {@code get-queue-config} RPC. See also {@link GetQueueConfig}.
282 * @param input of {@code get-queue-config}
283 * @return output of {@code get-queue-config}
285 @NonNull ListenableFuture<RpcResult<GetQueueConfigOutput>> getQueueConfig(GetQueueConfigInput input);
288 * Invoke {@code group-mod} RPC. See also {@link GroupMod}.
290 * @param input of {@code group-mod}
291 * @return output of {@code group-mod}
293 @NonNull ListenableFuture<RpcResult<GroupModOutput>> groupMod(GroupModInput input);
296 * Invoke {@code hello} RPC. See also {@link Hello}.
298 * @param input of {@code hello}
299 * @return output of {@code hello}
301 @NonNull ListenableFuture<RpcResult<HelloOutput>> hello(HelloInput input);
304 * Invoke {@code meter-mod} RPC. See also {@link MeterMod}.
306 * @param input of {@code meter-mod}
307 * @return output of {@code meter-mod}
309 @NonNull ListenableFuture<RpcResult<MeterModOutput>> meterMod(MeterModInput input);
312 * Invoke {@code multipart-request} RPC. See also {@link MultipartRequest}.
314 * @param input of {@code multipart-request}
315 * @return output of {@code multipart-request}
317 @NonNull ListenableFuture<RpcResult<MultipartRequestOutput>> multipartRequest(MultipartRequestInput input);
320 * Invoke {@code packet-out} RPC. See also {@link PacketOut}.
322 * @param input of {@code packet-out}
323 * @return output of {@code packet-out}
325 @NonNull ListenableFuture<RpcResult<PacketOutOutput>> packetOut(PacketOutInput input);
328 * Invoke {@code port-mod} RPC. See also {@link PortMod}.
330 * @param input of {@code port-mod}
331 * @return output of {@code port-mod}
333 @NonNull ListenableFuture<RpcResult<PortModOutput>> portMod(PortModInput input);
336 * Invoke {@code role-request} RPC. See also {@link RoleRequest}.
338 * @param input of {@code role-request}
339 * @return output of {@code role-request}
341 @NonNull ListenableFuture<RpcResult<RoleRequestOutput>> roleRequest(RoleRequestInput input);
344 * Invoke {@code set-async} RPC. See also {@link SetAsync}.
346 * @param input of {@code set-async}
347 * @return output of {@code set-async}
349 @NonNull ListenableFuture<RpcResult<SetAsyncOutput>> setAsync(SetAsyncInput input);
352 * Invoke {@code set-config} RPC. See also {@link SetConfig}.
354 * @param input of {@code set-config}
355 * @return output of {@code set-config}
357 @NonNull ListenableFuture<RpcResult<SetConfigOutput>> setConfig(SetConfigInput input);
360 * Invoke {@code table-mod} RPC. See also {@link TableMod}.
362 * @param input of {@code table-mod}
363 * @return output of {@code table-mod}
365 @NonNull ListenableFuture<RpcResult<TableModOutput>> tableMod(TableModInput input);