* @return thread numbers for TcpHandler's eventloopGroups
*/
ThreadConfiguration getThreadConfiguration();
+
+ /**
+ * @return boolean value for usability of Barrier
+ */
+ boolean useBarrier();
}
private SerializationFactory serializationFactory;
private TlsConfiguration tlsConfig;
private SwitchConnectionHandler switchConnectionHandler;
+ private boolean useBarrier;
/**
* @return PublishingChannelInitializer that initializes new channels
*/
public TcpChannelInitializer createPublishingChannelInitializer() {
- TcpChannelInitializer initializer = new TcpChannelInitializer();
+ final TcpChannelInitializer initializer = new TcpChannelInitializer();
initializer.setSwitchIdleTimeout(switchIdleTimeOut);
initializer.setDeserializationFactory(deserializationFactory);
initializer.setSerializationFactory(serializationFactory);
initializer.setTlsConfiguration(tlsConfig);
initializer.setSwitchConnectionHandler(switchConnectionHandler);
+ initializer.setUseBarrier(useBarrier);
return initializer;
}
* @return PublishingChannelInitializer that initializes new channels
*/
public UdpChannelInitializer createUdpChannelInitializer() {
- UdpChannelInitializer initializer = new UdpChannelInitializer();
+ final UdpChannelInitializer initializer = new UdpChannelInitializer();
initializer.setSwitchIdleTimeout(switchIdleTimeOut);
initializer.setDeserializationFactory(deserializationFactory);
initializer.setSerializationFactory(serializationFactory);
/**
* @param switchIdleTimeOut
*/
- public void setSwitchIdleTimeout(long switchIdleTimeOut) {
+ public void setSwitchIdleTimeout(final long switchIdleTimeOut) {
this.switchIdleTimeOut = switchIdleTimeOut;
}
/**
* @param deserializationFactory
*/
- public void setDeserializationFactory(DeserializationFactory deserializationFactory) {
+ public void setDeserializationFactory(final DeserializationFactory deserializationFactory) {
this.deserializationFactory = deserializationFactory;
}
/**
* @param serializationFactory
*/
- public void setSerializationFactory(SerializationFactory serializationFactory) {
+ public void setSerializationFactory(final SerializationFactory serializationFactory) {
this.serializationFactory = serializationFactory;
}
/**
* @param tlsConfig
*/
- public void setTlsConfig(TlsConfiguration tlsConfig) {
+ public void setTlsConfig(final TlsConfiguration tlsConfig) {
this.tlsConfig = tlsConfig;
}
/**
* @param switchConnectionHandler
*/
- public void setSwitchConnectionHandler(SwitchConnectionHandler switchConnectionHandler) {
+ public void setSwitchConnectionHandler(final SwitchConnectionHandler switchConnectionHandler) {
this.switchConnectionHandler = switchConnectionHandler;
}
+
+ /**
+ * @param useBarrier
+ */
+ public void setUseBarrier(final boolean useBarrier) {
+ this.useBarrier = useBarrier;
+ }
}
\ No newline at end of file
MessageConsumer consumer = UdpConnectionMap.getMessageConsumer(msg.sender());
if (consumer == null) {
ConnectionFacade connectionFacade =
- adapterFactory.createConnectionFacade(ctx.channel(), msg.sender());
+ adapterFactory.createConnectionFacade(ctx.channel(), msg.sender(), false);
connectionHandler.onSwitchConnected(connectionFacade);
connectionFacade.checkListeners();
UdpConnectionMap.addConnection(msg.sender(), connectionFacade);
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
-
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory;
private SerializationFactory serializationFactory;
private DeserializationFactory deserializationFactory;
private TlsConfiguration tlsConfiguration;
+ private boolean useBarrier;
/**
* @param switchConnectionHandler the switchConnectionHandler to set
/**
* @param tlsConfiguration
*/
- public void setTlsConfiguration(TlsConfiguration tlsConfiguration) {
+ public void setTlsConfiguration(final TlsConfiguration tlsConfiguration) {
this.tlsConfiguration = tlsConfiguration;
}
public TlsConfiguration getTlsConfiguration() {
return tlsConfiguration;
}
+
+ /**
+ * @param useBarrier
+ */
+ public void setUseBarrier(final boolean useBarrier) {
+ this.useBarrier = useBarrier;
+ }
+
+ /**
+ * @return useBarrrier
+ */
+ public boolean useBarrier() {
+ return useBarrier;
+ }
}
\ No newline at end of file
private SwitchConnectionHandler switchConnectionHandler;
private ServerFacade serverFacade;
private ConnectionConfiguration connConfig;
- private SerializationFactory serializationFactory;
- private SerializerRegistry serializerRegistry;
- private DeserializerRegistry deserializerRegistry;
- private DeserializationFactory deserializationFactory;
+ private final SerializationFactory serializationFactory;
+ private final SerializerRegistry serializerRegistry;
+ private final DeserializerRegistry deserializerRegistry;
+ private final DeserializationFactory deserializationFactory;
private TcpConnectionInitializer connectionInitializer;
/** Constructor */
}
@Override
- public void setConfiguration(ConnectionConfiguration connConfig) {
+ public void setConfiguration(final ConnectionConfiguration connConfig) {
this.connConfig = connConfig;
}
@Override
- public void setSwitchConnectionHandler(SwitchConnectionHandler switchConnectionHandler) {
+ public void setSwitchConnectionHandler(final SwitchConnectionHandler switchConnectionHandler) {
LOGGER.debug("setSwitchConnectionHandler");
this.switchConnectionHandler = switchConnectionHandler;
}
}
new Thread(serverFacade).start();
result = serverFacade.getIsOnlineFuture();
- } catch (Exception e) {
- SettableFuture<Boolean> exResult = SettableFuture.create();
+ } catch (final Exception e) {
+ final SettableFuture<Boolean> exResult = SettableFuture.create();
exResult.setException(e);
result = exResult;
}
private ServerFacade createAndConfigureServer() {
LOGGER.debug("Configuring ..");
ServerFacade server = null;
- ChannelInitializerFactory factory = new ChannelInitializerFactory();
+ final ChannelInitializerFactory factory = new ChannelInitializerFactory();
factory.setSwitchConnectionHandler(switchConnectionHandler);
factory.setSwitchIdleTimeout(connConfig.getSwitchIdleTimeout());
factory.setTlsConfig(connConfig.getTlsConfiguration());
factory.setSerializationFactory(serializationFactory);
factory.setDeserializationFactory(deserializationFactory);
- TransportProtocol transportProtocol = (TransportProtocol) connConfig.getTransferProtocol();
+ factory.setUseBarrier(connConfig.useBarrier());
+ final TransportProtocol transportProtocol = (TransportProtocol) connConfig.getTransferProtocol();
if (transportProtocol.equals(TransportProtocol.TCP) || transportProtocol.equals(TransportProtocol.TLS)) {
server = new TcpHandler(connConfig.getAddress(), connConfig.getPort());
- TcpChannelInitializer channelInitializer = factory.createPublishingChannelInitializer();
+ final TcpChannelInitializer channelInitializer = factory.createPublishingChannelInitializer();
((TcpHandler) server).setChannelInitializer(channelInitializer);
((TcpHandler) server).initiateEventLoopGroups(connConfig.getThreadConfiguration());
- NioEventLoopGroup workerGroupFromTcpHandler = ((TcpHandler) server).getWorkerGroup();
+ final NioEventLoopGroup workerGroupFromTcpHandler = ((TcpHandler) server).getWorkerGroup();
connectionInitializer = new TcpConnectionInitializer(workerGroupFromTcpHandler);
connectionInitializer.setChannelInitializer(channelInitializer);
connectionInitializer.run();
}
@Override
- public boolean unregisterSerializer(ExperimenterSerializerKey key) {
+ public boolean unregisterSerializer(final ExperimenterSerializerKey key) {
return serializerRegistry.unregisterSerializer((MessageTypeKey<?>) key);
}
@Override
- public boolean unregisterDeserializer(ExperimenterDeserializerKey key) {
+ public boolean unregisterDeserializer(final ExperimenterDeserializerKey key) {
return deserializerRegistry.unregisterDeserializer((MessageCodeKey) key);
}
@Override
- public void registerActionSerializer(ActionSerializerKey<?> key,
- OFGeneralSerializer serializer) {
+ public void registerActionSerializer(final ActionSerializerKey<?> key,
+ final OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void registerActionDeserializer(ExperimenterActionDeserializerKey key,
- OFGeneralDeserializer deserializer) {
+ public void registerActionDeserializer(final ExperimenterActionDeserializerKey key,
+ final OFGeneralDeserializer deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
@Override
- public void registerInstructionSerializer(InstructionSerializerKey<?> key,
- OFGeneralSerializer serializer) {
+ public void registerInstructionSerializer(final InstructionSerializerKey<?> key,
+ final OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void registerInstructionDeserializer(ExperimenterInstructionDeserializerKey key,
- OFGeneralDeserializer deserializer) {
+ public void registerInstructionDeserializer(final ExperimenterInstructionDeserializerKey key,
+ final OFGeneralDeserializer deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
@Override
- public <C extends OxmClassBase, F extends MatchField> void registerMatchEntrySerializer(MatchEntrySerializerKey<C, F> key,
- OFGeneralSerializer serializer) {
+ public <C extends OxmClassBase, F extends MatchField> void registerMatchEntrySerializer(final MatchEntrySerializerKey<C, F> key,
+ final OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void registerMatchEntryDeserializer(MatchEntryDeserializerKey key,
- OFGeneralDeserializer deserializer) {
+ public void registerMatchEntryDeserializer(final MatchEntryDeserializerKey key,
+ final OFGeneralDeserializer deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
@Override
- public void registerErrorDeserializer(ExperimenterIdDeserializerKey key,
- OFDeserializer<ErrorMessage> deserializer) {
+ public void registerErrorDeserializer(final ExperimenterIdDeserializerKey key,
+ final OFDeserializer<ErrorMessage> deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
}
@Override
- public void registerMultipartReplyTFDeserializer(ExperimenterIdDeserializerKey key,
- OFGeneralDeserializer deserializer) {
+ public void registerMultipartReplyTFDeserializer(final ExperimenterIdDeserializerKey key,
+ final OFGeneralDeserializer deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
@Override
- public void registerQueuePropertyDeserializer(ExperimenterIdDeserializerKey key,
- OFDeserializer<QueueProperty> deserializer) {
+ public void registerQueuePropertyDeserializer(final ExperimenterIdDeserializerKey key,
+ final OFDeserializer<QueueProperty> deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
@Override
- public void registerMeterBandDeserializer(ExperimenterIdDeserializerKey key,
- OFDeserializer<MeterBandExperimenterCase> deserializer) {
+ public void registerMeterBandDeserializer(final ExperimenterIdDeserializerKey key,
+ final OFDeserializer<MeterBandExperimenterCase> deserializer) {
deserializerRegistry.registerDeserializer(key, deserializer);
}
}
@Override
- public void registerMultipartRequestTFSerializer(ExperimenterIdSerializerKey<TableFeatureProperties> key,
- OFGeneralSerializer serializer) {
+ public void registerMultipartRequestTFSerializer(final ExperimenterIdSerializerKey<TableFeatureProperties> key,
+ final OFGeneralSerializer serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void registerMeterBandSerializer(ExperimenterIdSerializerKey<MeterBandExperimenterCase> key,
- OFSerializer<MeterBandExperimenterCase> serializer) {
+ public void registerMeterBandSerializer(final ExperimenterIdSerializerKey<MeterBandExperimenterCase> key,
+ final OFSerializer<MeterBandExperimenterCase> serializer) {
serializerRegistry.registerSerializer(key, serializer);
}
@Override
- public void initiateConnection(String host, int port) {
+ public void initiateConnection(final String host, final int port) {
connectionInitializer.initiateConnection(host, port);
}
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ssl.SslHandler;
-
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
import java.net.InetAddress;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
-
import javax.net.ssl.SSLEngine;
-
-import io.netty.util.concurrent.Future;
-import io.netty.util.concurrent.GenericFutureListener;
import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterFactory;
import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterFactoryImpl;
import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade;
private static final Logger LOGGER = LoggerFactory
.getLogger(TcpChannelInitializer.class);
private final DefaultChannelGroup allChannels;
- private ConnectionAdapterFactory connectionAdapterFactory;
+ private final ConnectionAdapterFactory connectionAdapterFactory;
/**
* default ctor
* Testing Constructor
*
*/
- protected TcpChannelInitializer( DefaultChannelGroup channelGroup, ConnectionAdapterFactory connAdaptorFactory ) {
+ protected TcpChannelInitializer( final DefaultChannelGroup channelGroup, final ConnectionAdapterFactory connAdaptorFactory ) {
allChannels = channelGroup ;
connectionAdapterFactory = connAdaptorFactory ;
}
@Override
protected void initChannel(final SocketChannel ch) {
if (ch.remoteAddress() != null) {
- InetAddress switchAddress = ch.remoteAddress().getAddress();
- int port = ch.localAddress().getPort();
- int remotePort = ch.remoteAddress().getPort();
+ final InetAddress switchAddress = ch.remoteAddress().getAddress();
+ final int port = ch.localAddress().getPort();
+ final int remotePort = ch.remoteAddress().getPort();
LOGGER.debug("Incoming connection from (remote address): {}:{} --> :{}",
switchAddress.toString(), remotePort, port);
LOGGER.debug("Incoming connection accepted - building pipeline");
allChannels.add(ch);
ConnectionFacade connectionFacade = null;
- connectionFacade = connectionAdapterFactory.createConnectionFacade(ch, null);
+ connectionFacade = connectionAdapterFactory.createConnectionFacade(ch, null, useBarrier());
try {
LOGGER.debug("calling plugin: {}", getSwitchConnectionHandler());
getSwitchConnectionHandler().onSwitchConnected(connectionFacade);
// If this channel is configured to support SSL it will only support SSL
if (getTlsConfiguration() != null) {
tlsPresent = true;
- SslContextFactory sslFactory = new SslContextFactory(getTlsConfiguration());
- SSLEngine engine = sslFactory.getServerContext().createSSLEngine();
+ final SslContextFactory sslFactory = new SslContextFactory(getTlsConfiguration());
+ final SSLEngine engine = sslFactory.getServerContext().createSSLEngine();
engine.setNeedClientAuth(true);
engine.setUseClientMode(false);
- SslHandler ssl = new SslHandler(engine);
- Future<Channel> handshakeFuture = ssl.handshakeFuture();
+ final SslHandler ssl = new SslHandler(engine);
+ final Future<Channel> handshakeFuture = ssl.handshakeFuture();
final ConnectionFacade finalConnectionFacade = connectionFacade;
handshakeFuture.addListener(new GenericFutureListener<Future<? super Channel>>() {
@Override
- public void operationComplete(Future<? super Channel> future) throws Exception {
+ public void operationComplete(final Future<? super Channel> future) throws Exception {
finalConnectionFacade.fireConnectionReadyNotification();
}
});
ch.pipeline().addLast(PipelineHandlers.OF_FRAME_DECODER.name(),
new OFFrameDecoder(connectionFacade, tlsPresent));
ch.pipeline().addLast(PipelineHandlers.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
- OFDecoder ofDecoder = new OFDecoder();
+ final OFDecoder ofDecoder = new OFDecoder();
ofDecoder.setDeserializationFactory(getDeserializationFactory());
ch.pipeline().addLast(PipelineHandlers.OF_DECODER.name(), ofDecoder);
- OFEncoder ofEncoder = new OFEncoder();
+ final OFEncoder ofEncoder = new OFEncoder();
ofEncoder.setSerializationFactory(getSerializationFactory());
ch.pipeline().addLast(PipelineHandlers.OF_ENCODER.name(), ofEncoder);
ch.pipeline().addLast(PipelineHandlers.DELEGATING_INBOUND_HANDLER.name(), new DelegatingInboundHandler(connectionFacade));
if (!tlsPresent) {
connectionFacade.fireConnectionReadyNotification();
}
- } catch (Exception e) {
+ } catch (final Exception e) {
LOGGER.warn("Failed to initialize channel", e);
ch.close();
}
package org.opendaylight.openflowjava.protocol.impl.core.connection;
-import java.net.InetSocketAddress;
-
import io.netty.channel.Channel;
+import java.net.InetSocketAddress;
/**
* @author mirehak
public interface ConnectionAdapterFactory {
/**
- * @param ch
+ * @param ch {@link Channel} channel
+ * @param address {@link InetSocketAddress}
+ * @param useBarrier
* @return connection adapter tcp-implementation
*/
- ConnectionFacade createConnectionFacade(Channel ch, InetSocketAddress address) ;
+ ConnectionFacade createConnectionFacade(Channel ch, InetSocketAddress address, boolean useBarrier);
}
package org.opendaylight.openflowjava.protocol.impl.core.connection;
-import java.net.InetSocketAddress;
-
import io.netty.channel.Channel;
+import java.net.InetSocketAddress;
/**
* @author mirehak
* @return connection adapter tcp-implementation
*/
@Override
- public ConnectionFacade createConnectionFacade(Channel ch, InetSocketAddress address) {
- return new ConnectionAdapterImpl(ch, address);
+ public ConnectionFacade createConnectionFacade(final Channel ch, final InetSocketAddress address,
+ final boolean useBarrier) {
+ return new ConnectionAdapterImpl(ch, address, useBarrier);
}
}
private OFVersionDetector versionDetector;
private final InetSocketAddress address;
+ private final boolean useBarrier;
+
/**
* default ctor
* @param channel the channel to be set - used for communication
* @param address client address (used only in case of UDP communication,
* as there is no need to store address over tcp (stable channel))
*/
- public ConnectionAdapterImpl(final Channel channel, final InetSocketAddress address) {
+ public ConnectionAdapterImpl(final Channel channel, final InetSocketAddress address, final boolean useBarrier) {
+ this.channel = Preconditions.checkNotNull(channel);
+ this.output = new ChannelOutboundQueue(channel, DEFAULT_QUEUE_DEPTH, address);
+ this.address = address;
+
responseCache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
- this.channel = Preconditions.checkNotNull(channel);
- this.output = new ChannelOutboundQueue(channel, DEFAULT_QUEUE_DEPTH, address);
- this.address = address;
+
+ this.useBarrier = useBarrier;
channel.pipeline().addLast(output);
statisticsCounters = StatisticsCounters.getInstance();
@Override
public Future<Boolean> disconnect() {
- ChannelFuture disconnectResult = channel.disconnect();
+ final ChannelFuture disconnectResult = channel.disconnect();
responseCache.invalidateAll();
disconnectOccured = true;
LOG.debug("OFheader msg received");
if (outputManager == null || !outputManager.onMessage((OfHeader) message)) {
- RpcResponseKey key = createRpcResponseKey((OfHeader) message);
+ final RpcResponseKey key = createRpcResponseKey((OfHeader) message);
final ResponseExpectedRpcListener<?> listener = findRpcResponse(key);
if (listener != null) {
LOG.debug("corresponding rpcFuture found");
final T handler, final int maxQueueDepth, final long maxBarrierNanos) {
Preconditions.checkState(outputManager == null, "Manager %s already registered", outputManager);
+ if (useBarrier) {
+
+ }
+
final OutboundQueueManager<T> ret = new OutboundQueueManager<>(this, address, handler, maxQueueDepth, maxBarrierNanos);
outputManager = ret;
channel.pipeline().addLast(outputManager);
@Override
public java.lang.AutoCloseable createInstance() {
LOG.info("SwitchConnectionProvider started.");
- SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
+ final SwitchConnectionProviderImpl switchConnectionProviderImpl = new SwitchConnectionProviderImpl();
try {
- ConnectionConfiguration connConfiguration = createConnectionConfiguration();
+ final ConnectionConfiguration connConfiguration = createConnectionConfiguration();
switchConnectionProviderImpl.setConfiguration(connConfiguration);
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
return switchConnectionProviderImpl;
final long switchIdleTimeout = getSwitchIdleTimeout();
final Tls tlsConfig = getTls();
final Threads threads = getThreads();
+ final Boolean useBarrier = getUseBarrier();
final TransportProtocol transportProtocol = getTransportProtocol();
return new ConnectionConfiguration() {
}
};
}
+
+ @Override
+ public boolean useBarrier() {
+ return useBarrier;
+ }
};
}
case openflow-switch-connection-provider-impl {
when "/config:modules/config:module/config:type = 'openflow-switch-connection-provider-impl'";
+ leaf use-barrier {
+ description "Enable barrier in Openflow java";
+ type boolean;
+ default true;
+ }
+
leaf port {
description "local listening port";
type uint16;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.ssl.SslHandler;
-
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
-
import javax.net.ssl.SSLEngine;
-
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
pubChInitializer.setDeserializationFactory(mockDeserializationFactory);
pubChInitializer.setSwitchIdleTimeout(1) ;
pubChInitializer.getConnectionIterator() ;
+ pubChInitializer.setUseBarrier(true);
when( mockChGrp.size()).thenReturn(1) ;
pubChInitializer.setSwitchConnectionHandler( mockSwConnHandler ) ;
inetSockAddr = new InetSocketAddress(InetAddress.getLocalHost(), 8675 ) ;
- when(mockConnAdaptorFactory.createConnectionFacade(mockSocketCh, null))
+ when(mockConnAdaptorFactory.createConnectionFacade(mockSocketCh, null, true))
.thenReturn(mockConnFacade);
when(mockSocketCh.remoteAddress()).thenReturn(inetSockAddr) ;
when(mockSocketCh.localAddress()).thenReturn(inetSockAddr) ;
*/
package org.opendaylight.openflowjava.protocol.impl.core.connection;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel;
-
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ChannelOutboundQueue;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-
/**
* @author madamjak
*
*/
@Test
public void test01() throws Exception {
- EmbeddedChannel ec = new EmbeddedChannel(new EmbededChannelHandler());
- adapter = new ConnectionAdapterImpl(ec,InetSocketAddress.createUnresolved("localhost", 9876));
+ final EmbeddedChannel ec = new EmbeddedChannel(new EmbededChannelHandler());
+ adapter = new ConnectionAdapterImpl(ec, InetSocketAddress.createUnresolved("localhost", 9876), true);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
- ChannelOutboundQueue cq = (ChannelOutboundQueue) ec.pipeline().last();
+ final ChannelOutboundQueue cq = (ChannelOutboundQueue) ec.pipeline().last();
counter=0;
adapter.barrier(barrierInput);
adapter.echo(echoInput);
*/
@Test
public void test02(){
- ChangeWritableEmbededChannel ec = new ChangeWritableEmbededChannel(new EmbededChannelHandler());
- adapter = new ConnectionAdapterImpl(ec,InetSocketAddress.createUnresolved("localhost", 9876));
+ final ChangeWritableEmbededChannel ec = new ChangeWritableEmbededChannel(new EmbededChannelHandler());
+ adapter = new ConnectionAdapterImpl(ec, InetSocketAddress.createUnresolved("localhost", 9876), true);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
*/
private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
@Override
- public void write(ChannelHandlerContext ctx, Object msg,
- ChannelPromise promise) throws Exception {
+ public void write(final ChannelHandlerContext ctx, final Object msg,
+ final ChannelPromise promise) throws Exception {
if(msg instanceof MessageListenerWrapper){
counter++;
}
*/
private class ChangeWritableEmbededChannel extends EmbeddedChannel {
private boolean isWrittable;
- public ChangeWritableEmbededChannel(ChannelHandler channelHandler){
+ public ChangeWritableEmbededChannel(final ChannelHandler channelHandler){
super(channelHandler);
setReadOnly();
}
import static org.mockito.Mockito.when;
import io.netty.channel.Channel;
import io.netty.channel.ChannelPipeline;
-
import java.net.InetSocketAddress;
-
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterFactoryImpl;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionFacade;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
/**
*
* @author madamjak
@Test
public void test(){
- ConnectionAdapterFactoryImpl connAdapterFactory = new ConnectionAdapterFactoryImpl();
- ConnectionFacade connFacade = connAdapterFactory.createConnectionFacade(channel, address);
+ final ConnectionAdapterFactoryImpl connAdapterFactory = new ConnectionAdapterFactoryImpl();
+ final ConnectionFacade connFacade = connAdapterFactory.createConnectionFacade(channel, address, true);
Assert.assertNotNull("Wrong - ConnectionFacade has not created.", connFacade);
Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionFacade.isAlive()", channel.isOpen(), connFacade.isAlive());
}
*/
package org.opendaylight.openflowjava.protocol.impl.core.connection;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel;
-
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-
/**
* @author madamjak
* @author michal.polkorab
*/
@Test
public void testRcp() {
- EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
- adapter = new ConnectionAdapterImpl(embChannel,InetSocketAddress.createUnresolved("localhost", 9876));
+ final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
+ adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
*/
private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
@Override
- public void write(ChannelHandlerContext ctx, Object msg,
- ChannelPromise promise) throws Exception {
+ public void write(final ChannelHandlerContext ctx, final Object msg,
+ final ChannelPromise promise) throws Exception {
responseOfCall = null;
if(msg instanceof MessageListenerWrapper){
- MessageListenerWrapper listener = (MessageListenerWrapper) msg;
- OfHeader ofHeader = listener.getMsg();
+ final MessageListenerWrapper listener = (MessageListenerWrapper) msg;
+ final OfHeader ofHeader = listener.getMsg();
responseOfCall = ofHeader;
}
}
*/
package org.opendaylight.openflowjava.protocol.impl.core.connection;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelOutboundHandlerAdapter;
import io.netty.channel.ChannelPromise;
import io.netty.channel.embedded.EmbeddedChannel;
-
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
-
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.MessageListenerWrapper;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.TableModInput;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-
/**
* @author madamjak
* @author michal.polkorab
*/
@Test
public void testRcp() {
- EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
- adapter = new ConnectionAdapterImpl(embChannel,InetSocketAddress.createUnresolved("localhost", 9876));
+ final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
+ adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
*/
private class EmbededChannelHandler extends ChannelOutboundHandlerAdapter {
@Override
- public void write(ChannelHandlerContext ctx, Object msg,
- ChannelPromise promise) throws Exception {
+ public void write(final ChannelHandlerContext ctx, final Object msg,
+ final ChannelPromise promise) throws Exception {
responseOfCall = null;
if(msg instanceof MessageListenerWrapper){
- MessageListenerWrapper listener = (MessageListenerWrapper) msg;
- OfHeader ofHeader = listener.getMsg();
+ final MessageListenerWrapper listener = (MessageListenerWrapper) msg;
+ final OfHeader ofHeader = listener.getMsg();
responseOfCall = ofHeader;
}
}
if(!statCounters.isCounterEnabled(CounterEventTypes.DS_FLOW_MODS_ENTERED)){
Assert.fail("Counter " + CounterEventTypes.DS_FLOW_MODS_ENTERED + " is not enabled");
}
- EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
- adapter = new ConnectionAdapterImpl(embChannel,InetSocketAddress.createUnresolved("localhost", 9876));
+ final EmbeddedChannel embChannel = new EmbeddedChannel(new EmbededChannelHandler());
+ adapter = new ConnectionAdapterImpl(embChannel, InetSocketAddress.createUnresolved("localhost", 9876), true);
cache = CacheBuilder.newBuilder().concurrencyLevel(1).expireAfterWrite(RPC_RESPONSE_EXPIRATION, TimeUnit.MINUTES)
.removalListener(REMOVAL_LISTENER).build();
adapter.setResponseCache(cache);
Assert.fail("Counter " + CounterEventTypes.US_MESSAGE_PASS + " is not enabled");
}
when(channel.pipeline()).thenReturn(pipeline);
- adapter = new ConnectionAdapterImpl(channel, InetSocketAddress.createUnresolved("10.0.0.1", 6653));
+ adapter = new ConnectionAdapterImpl(channel, InetSocketAddress.createUnresolved("10.0.0.1", 6653), true);
adapter.setMessageListener(messageListener);
adapter.setSystemListener(systemListener);
adapter.setConnectionReadyListener(readyListener);
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalListener;
+import com.google.common.cache.RemovalNotification;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
-
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;
-
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.MockitoAnnotations;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ConnectionAdapterImpl;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.ResponseExpectedRpcListener;
-import org.opendaylight.openflowjava.protocol.impl.core.connection.RpcResponseKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.system.rev130927.SystemNotificationsListener;
import org.opendaylight.yangtools.yang.binding.DataObject;
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
-import com.google.common.cache.RemovalListener;
-import com.google.common.cache.RemovalNotification;
-
/**
* @author michal.polkorab
* @author madamjak
public void setUp() {
MockitoAnnotations.initMocks(this);
when(channel.pipeline()).thenReturn(pipeline);
- adapter = new ConnectionAdapterImpl(channel, InetSocketAddress.createUnresolved("10.0.0.1", 6653));
+ adapter = new ConnectionAdapterImpl(channel, InetSocketAddress.createUnresolved("10.0.0.1", 6653), true);
adapter.setMessageListener(messageListener);
adapter.setSystemListener(systemListener);
adapter.setConnectionReadyListener(readyListener);
@Test
public void testConsume2() {
adapter.setResponseCache(mockCache);
- BarrierOutputBuilder barrierBuilder = new BarrierOutputBuilder();
+ final BarrierOutputBuilder barrierBuilder = new BarrierOutputBuilder();
barrierBuilder.setXid(42L);
- BarrierOutput barrier = barrierBuilder.build();
+ final BarrierOutput barrier = barrierBuilder.build();
adapter.consume(barrier);
verify(mockCache, times(1)).getIfPresent(any(RpcResponseKey.class));
}
*/
@Test
public void testConsume3() {
- BarrierInputBuilder inputBuilder = new BarrierInputBuilder();
+ final BarrierInputBuilder inputBuilder = new BarrierInputBuilder();
inputBuilder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
inputBuilder.setXid(42L);
- BarrierInput barrierInput = inputBuilder.build();
- RpcResponseKey key = new RpcResponseKey(42L, "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput");
- ResponseExpectedRpcListener<OfHeader> listener = new ResponseExpectedRpcListener<>(barrierInput,
+ final BarrierInput barrierInput = inputBuilder.build();
+ final RpcResponseKey key = new RpcResponseKey(42L, "org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput");
+ final ResponseExpectedRpcListener<OfHeader> listener = new ResponseExpectedRpcListener<>(barrierInput,
"failure", mockCache, key);
cache.put(key, listener);
- BarrierOutputBuilder barrierBuilder = new BarrierOutputBuilder();
+ final BarrierOutputBuilder barrierBuilder = new BarrierOutputBuilder();
barrierBuilder.setXid(42L);
- BarrierOutput barrierOutput = barrierBuilder.build();
+ final BarrierOutput barrierOutput = barrierBuilder.build();
adapter.consume(barrierOutput);
- ResponseExpectedRpcListener<?> ifPresent = cache.getIfPresent(key);
+ final ResponseExpectedRpcListener<?> ifPresent = cache.getIfPresent(key);
Assert.assertNull("Listener was not discarded", ifPresent);
}
/**
*/
@Test
public void testIsAlive(){
- int port = 9876;
- String host ="localhost";
- InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
- ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel,inetSockAddr);
+ final int port = 9876;
+ final String host ="localhost";
+ final InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
+ final ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel, inetSockAddr, true);
Assert.assertEquals("Wrong - diffrence between channel.isOpen() and ConnectionAdapterImpl.isAlive()", channel.isOpen(), connAddapter.isAlive());
connAddapter.disconnect();
*/
@Test(expected = java.lang.IllegalStateException.class)
public void testMissingListeners(){
- int port = 9876;
- String host ="localhost";
- InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
- ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel,inetSockAddr);
+ final int port = 9876;
+ final String host ="localhost";
+ final InetSocketAddress inetSockAddr = InetSocketAddress.createUnresolved(host, port);
+ final ConnectionAdapterImpl connAddapter = new ConnectionAdapterImpl(channel, inetSockAddr, true);
connAddapter.setSystemListener(null);
connAddapter.setMessageListener(null);
connAddapter.setConnectionReadyListener(null);
package org.opendaylight.openflowjava.protocol.impl.core.connection;
import java.net.InetAddress;
-
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
*/
public class ConnectionConfigurationImpl implements ConnectionConfiguration {
- private InetAddress address;
- private int port;
+ private final InetAddress address;
+ private final int port;
private Object transferProtocol;
- private TlsConfiguration tlsConfig;
- private long switchIdleTimeout;
+ private final TlsConfiguration tlsConfig;
+ private final long switchIdleTimeout;
private ThreadConfiguration threadConfig;
+ private final boolean useBarrier;
/**
* Creates {@link ConnectionConfigurationImpl}
+ *
* @param address
* @param port
* @param tlsConfig
* @param switchIdleTimeout
+ * @param useBarrier
*/
- public ConnectionConfigurationImpl(InetAddress address, int port, TlsConfiguration tlsConfig, long switchIdleTimeout) {
+ public ConnectionConfigurationImpl(final InetAddress address, final int port, final TlsConfiguration tlsConfig,
+ final long switchIdleTimeout, final boolean useBarrier) {
this.address = address;
this.port = port;
this.tlsConfig = tlsConfig;
this.switchIdleTimeout = switchIdleTimeout;
+ this.useBarrier = useBarrier;
}
@Override
* Used for testing - sets transport protocol
* @param protocol
*/
- public void setTransferProtocol(TransportProtocol protocol) {
+ public void setTransferProtocol(final TransportProtocol protocol) {
this.transferProtocol = protocol;
}
/**
* @param threadConfig thread model configuration (configures threads used)
*/
- public void setThreadConfiguration(ThreadConfiguration threadConfig) {
+ public void setThreadConfiguration(final ThreadConfiguration threadConfig) {
this.threadConfig = threadConfig;
}
+
+ @Override
+ public boolean useBarrier() {
+ return useBarrier;
+ }
}
\ No newline at end of file
* Creates new {@link SwitchConnectionProvider} instance for each test
* @param protocol communication protocol
*/
- public void startUp(TransportProtocol protocol) {
+ public void startUp(final TransportProtocol protocol) {
MockitoAnnotations.initMocks(this);
config = null;
if (protocol != null) {
provider = new SwitchConnectionProviderImpl();
}
- private void createConfig(TransportProtocol protocol) {
+ private void createConfig(final TransportProtocol protocol) {
try {
startupAddress = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
e.printStackTrace();
}
tlsConfiguration = null;
"/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,
"/selfSignedController", PathType.CLASSPATH) ;
}
- config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT);
+ config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
config.setTransferProtocol(protocol);
}
public void testServerFacade(){
startUp(TransportProtocol.TCP);
provider.setConfiguration(config);
- ListenableFuture<Boolean> future = provider.startup();
- ServerFacade serverFacade = provider.getServerFacade();
+ final ListenableFuture<Boolean> future = provider.startup();
+ final ServerFacade serverFacade = provider.getServerFacade();
Assert.assertNotNull("Wrong -- getServerFacade return null",serverFacade);
}
public void testUnregisterWrongKeys(){
startUp(TransportProtocol.TCP);
provider.setConfiguration(config);
- ExperimenterInstructionSerializerKey testSerKey
+ final ExperimenterInstructionSerializerKey testSerKey
= new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID,42L);
Assert.assertFalse("Wrong -- unregisterSerializer",provider.unregisterSerializer(testSerKey));
- ExperimenterInstructionDeserializerKey tesDeserKey
+ final ExperimenterInstructionDeserializerKey tesDeserKey
= new ExperimenterInstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID,24L);
Assert.assertFalse("Wrong -- unregisterDeserializer",provider.unregisterDeserializer(tesDeserKey));
}
startUp(TransportProtocol.TCP);
provider.setConfiguration(config);
// -- registerActionSerializer
- ExperimenterActionSerializerKey key1
+ final ExperimenterActionSerializerKey key1
= new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
provider.registerActionSerializer(key1, serializer);
Assert.assertTrue("Wrong -- unregister ActionSerializer", provider.unregisterSerializer(key1));
Assert.assertFalse("Wrong -- unregister ActionSerializer by not existing key", provider.unregisterSerializer(key1));
// -- registerActionDeserializer
- ExperimenterActionDeserializerKey key2
+ final ExperimenterActionDeserializerKey key2
= new ExperimenterActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L);
provider.registerActionDeserializer(key2, deserializer);
Assert.assertTrue("Wrong -- unregister ActionDeserializer", provider.unregisterDeserializer(key2));
Assert.assertFalse("Wrong -- unregister ActionDeserializer by not existing key", provider.unregisterDeserializer(key2));
// -- registerInstructionSerializer
- ExperimenterInstructionSerializerKey key3
+ final ExperimenterInstructionSerializerKey key3
= new ExperimenterInstructionSerializerKey(EncodeConstants.OF10_VERSION_ID,42L);
provider.registerInstructionSerializer(key3, serializer);
Assert.assertTrue("Wrong -- unregister InstructionSerializer", provider.unregisterSerializer(key3));
Assert.assertFalse("Wrong -- unregister InstructionSerializer by not existing key", provider.unregisterSerializer(key3));
// -- registerInstructionDeserializer
- ExperimenterInstructionDeserializerKey key4
+ final ExperimenterInstructionDeserializerKey key4
= new ExperimenterInstructionDeserializerKey(EncodeConstants.OF10_VERSION_ID,42L);
provider.registerInstructionDeserializer(key4, deserializer);
Assert.assertTrue("Wrong -- unregister InstructionDeserializer", provider.unregisterDeserializer(key4));
Assert.assertFalse("Wrong -- unregister InstructionDeserializer by not existing key", provider.unregisterDeserializer(key4));
// -- registerMatchEntryDeserializer
- MatchEntryDeserializerKey key5
+ final MatchEntryDeserializerKey key5
= new MatchEntryDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0x8000, 42);
provider.registerMatchEntryDeserializer(key5, deserializer);
Assert.assertTrue("Wrong -- unregister MatchEntryDeserializer", provider.unregisterDeserializer(key5));
Assert.assertFalse("Wrong -- unregister MatchEntryDeserializer by not existing key", provider.unregisterDeserializer(key5));
// -- registerErrorDeserializer
- ExperimenterIdDeserializerKey key6
+ final ExperimenterIdDeserializerKey key6
= new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ErrorMessage.class);
provider.registerErrorDeserializer(key6, deserializerError);
Assert.assertTrue("Wrong -- unregister ErrorDeserializer", provider.unregisterDeserializer(key6));
Assert.assertFalse("Wrong -- unregister ErrorDeserializer by not existing key", provider.unregisterDeserializer(key6));
// -- registerExperimenterMessageDeserializer
- ExperimenterIdDeserializerKey key7
+ final ExperimenterIdDeserializerKey key7
= new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, ExperimenterMessage.class);
provider.registerExperimenterMessageDeserializer(key7, deserializerExpMsg);
Assert.assertTrue("Wrong -- unregister ExperimenterMessageDeserializer", provider.unregisterDeserializer(key7));
Assert.assertFalse("Wrong -- unregister ExperimenterMessageDeserializer by not existing key", provider.unregisterDeserializer(key7));
// -- registerMultipartReplyMessageDeserializer
- ExperimenterIdDeserializerKey key8
+ final ExperimenterIdDeserializerKey key8
= new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
provider.registerMultipartReplyMessageDeserializer(key8, deserializerMultipartRplMsg);
Assert.assertTrue("Wrong -- unregister MultipartReplyMessageDeserializer", provider.unregisterDeserializer(key8));
Assert.assertFalse("Wrong -- unregister MultipartReplyMessageDeserializer by not existing key", provider.unregisterDeserializer(key8));
// -- registerMultipartReplyTFDeserializer
- ExperimenterIdDeserializerKey key9 =
+ final ExperimenterIdDeserializerKey key9 =
new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MultipartReplyMessage.class);
provider.registerMultipartReplyTFDeserializer(key9, deserializer);
Assert.assertTrue("Wrong -- unregister MultipartReplyTFDeserializer", provider.unregisterDeserializer(key9));
Assert.assertFalse("Wrong -- unregister MultipartReplyTFDeserializer by non existing key", provider.unregisterDeserializer(key9));
// -- registerQueuePropertyDeserializer
- ExperimenterIdDeserializerKey key10
+ final ExperimenterIdDeserializerKey key10
= new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, QueueProperty.class);
provider.registerQueuePropertyDeserializer(key10, deserializerQueueProperty);
Assert.assertTrue("Wrong -- unregister QueuePropertyDeserializer", provider.unregisterDeserializer(key10));
Assert.assertFalse("Wrong -- unregister QueuePropertyDeserializer by not existing key", provider.unregisterDeserializer(key10));
// -- registerMeterBandDeserializer
- ExperimenterIdDeserializerKey key11
+ final ExperimenterIdDeserializerKey key11
= new ExperimenterIdDeserializerKey(EncodeConstants.OF10_VERSION_ID, 42L, MeterBandExperimenterCase.class);
provider.registerMeterBandDeserializer(key11, deserializerMeterBandExpCase);
Assert.assertTrue("Wrong -- unregister MeterBandDeserializer", provider.unregisterDeserializer(key11));
Assert.assertTrue("Wrong -- unregister MultipartRequestSerializer", provider.unregisterSerializer(key13));
Assert.assertFalse("Wrong -- unregister MultipartRequestSerializer by not existing key", provider.unregisterSerializer(key13));
// -- registerMultipartRequestTFSerializer
- ExperimenterIdSerializerKey<TableFeatureProperties> key14
+ final ExperimenterIdSerializerKey<TableFeatureProperties> key14
= new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,TableFeatureProperties.class);
provider.registerMultipartRequestTFSerializer(key14, serializer);
Assert.assertTrue("Wrong -- unregister MultipartRequestTFSerializer", provider.unregisterSerializer(key14));
Assert.assertFalse("Wrong -- unregister MultipartRequestTFSerializer by not existing key", provider.unregisterSerializer(key14));
// -- registerMeterBandSerializer
- ExperimenterIdSerializerKey<MeterBandExperimenterCase> key15
+ final ExperimenterIdSerializerKey<MeterBandExperimenterCase> key15
= new ExperimenterIdSerializerKey<>(EncodeConstants.OF10_VERSION_ID,42L,MeterBandExperimenterCase.class);
provider.registerMeterBandSerializer(key15, serializerMeterBandExpCase);
Assert.assertTrue("Wrong -- unregister MeterBandSerializer", provider.unregisterSerializer(key15));
Assert.assertFalse("Wrong -- unregister MeterBandSerializer by not existing key", provider.unregisterSerializer(key15));
// -- registerMatchEntrySerializer
- MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16
+ final MatchEntrySerializerKey<OpenflowBasicClass, InPort> key16
= new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);
provider.registerMatchEntrySerializer(key16, serializer);
Assert.assertTrue("Wrong -- unregister MatchEntrySerializer", provider.unregisterSerializer(key16));
package org.opendaylight.openflowjava.protocol.impl.core.connection;
+import com.google.common.util.concurrent.ListenableFuture;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mock;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.PathType;
import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.config.rev140630.TransportProtocol;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
* @author michal.polkorab
*
* Creates new {@link SwitchConnectionProvider} instance for each test
* @param protocol communication protocol
*/
- public void startUp(TransportProtocol protocol) {
+ public void startUp(final TransportProtocol protocol) {
MockitoAnnotations.initMocks(this);
config = null;
if (protocol != null) {
provider = new SwitchConnectionProviderImpl();
}
- private void createConfig(TransportProtocol protocol) {
+ private void createConfig(final TransportProtocol protocol) {
try {
startupAddress = InetAddress.getLocalHost();
- } catch (UnknownHostException e) {
+ } catch (final UnknownHostException e) {
e.printStackTrace();
}
tlsConfiguration = null;
"/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,
"/selfSignedController", PathType.CLASSPATH) ;
}
- config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT);
+ config = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
config.setTransferProtocol(protocol);
}
@Test
public void testStartup1() {
provider = new SwitchConnectionProviderImpl();
- ListenableFuture<Boolean> future = provider.startup();
+ final ListenableFuture<Boolean> future = provider.startup();
try {
future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
public void testStartup2() {
startUp(null);
provider.setSwitchConnectionHandler(handler);
- ListenableFuture<Boolean> future = provider.startup();
+ final ListenableFuture<Boolean> future = provider.startup();
try {
future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
public void testStartup3() {
startUp(TransportProtocol.TCP);
provider.setConfiguration(config);
- ListenableFuture<Boolean> future = provider.startup();
+ final ListenableFuture<Boolean> future = provider.startup();
try {
future.get(WAIT_TIMEOUT, TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-
import org.junit.After;
import org.junit.Test;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
* @param protocol communication protocol to be used during test
* @throws Exception
*/
- public void setUp(TransportProtocol protocol) throws Exception {
+ public void setUp(final TransportProtocol protocol) throws Exception {
LOGGER.debug("\n starting test -------------------------------");
- String currentDir = System.getProperty("user.dir");
+ final String currentDir = System.getProperty("user.dir");
LOGGER.debug("Current dir using System: {}", currentDir);
startupAddress = InetAddress.getLocalHost();
tlsConfiguration = null;
"/selfSignedSwitch", PathType.CLASSPATH, KeystoreType.JKS,
"/selfSignedController", PathType.CLASSPATH) ;
}
- connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT);
+ connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true);
connConfig.setTransferProtocol(protocol);
mockPlugin = new MockPlugin();
switchConnectionProvider.setConfiguration(connConfig);
switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
- TcpHandler tcpHandler = (TcpHandler) switchConnectionProvider.getServerFacade();
+ final TcpHandler tcpHandler = (TcpHandler) switchConnectionProvider.getServerFacade();
port = tcpHandler.getPort();
} else {
- UdpHandler udpHandler = (UdpHandler) switchConnectionProvider.getServerFacade();
+ final UdpHandler udpHandler = (UdpHandler) switchConnectionProvider.getServerFacade();
port = udpHandler.getPort();
}
}
@Test
public void testHandshake() throws Exception {
setUp(TransportProtocol.TCP);
- int amountOfCLients = 1;
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
- OFClient firstClient = clients.get(0);
+ final int amountOfCLients = 1;
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
+ final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
Thread.sleep(1000);
@Test
public void testTlsHandshake() throws Exception {
setUp(TransportProtocol.TLS);
- int amountOfCLients = 1;
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
- OFClient firstClient = clients.get(0);
+ final int amountOfCLients = 1;
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
+ final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
Thread.sleep(1000);
@Test
public void testHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.TCP);
- int amountOfCLients = 1;
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final int amountOfCLients = 1;
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
- OFClient firstClient = clients.get(0);
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
+ final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
LOGGER.debug("testHandshakeAndEcho() Finished") ;
@Test
public void testTlsHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.TLS);
- int amountOfCLients = 1;
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final int amountOfCLients = 1;
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
- OFClient firstClient = clients.get(0);
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
+ final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
LOGGER.debug("testTlsHandshakeAndEcho() Finished") ;
@Test
public void testUdpHandshakeAndEcho() throws Exception {
setUp(TransportProtocol.UDP);
- int amountOfCLients = 1;
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final int amountOfCLients = 1;
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP, ClientType.SIMPLE);
- OFClient firstClient = clients.get(0);
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP, ClientType.SIMPLE);
+ final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
LOGGER.debug("testUdpHandshakeAndEcho() Finished") ;
* @return new clients up and running
* @throws ExecutionException if some client could not start
*/
- private List<OFClient> createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler,
- TransportProtocol protocol, ClientType clientType) throws ExecutionException {
- List<OFClient> clientsHorde = new ArrayList<>();
+ private List<OFClient> createAndStartClient(final int amountOfCLients, final ScenarioHandler scenarioHandler,
+ final TransportProtocol protocol, final ClientType clientType) throws ExecutionException {
+ final List<OFClient> clientsHorde = new ArrayList<>();
for (int i = 0; i < amountOfCLients; i++) {
LOGGER.debug("startup address in createclient: {}", startupAddress.getHostAddress());
OFClient sc = null;
t = new Thread(sc);
t.start();
}
- for (OFClient sc : clientsHorde) {
+ for (final OFClient sc : clientsHorde) {
try {
sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (Exception e) {
+ } catch (final Exception e) {
LOGGER.error("createAndStartClient: Something borked ... ", e.getMessage(), e);
throw new ExecutionException(e);
}
public void testInitiateConnection() throws Exception {
setUp(TransportProtocol.TCP);
- Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
- ScenarioHandler handler = new ScenarioHandler(scenario);
- List<OFClient> clients = createAndStartClient(1, handler, TransportProtocol.TCP, ClientType.LISTENING);
- OFClient ofClient = clients.get(0);
+ final Deque<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+ final ScenarioHandler handler = new ScenarioHandler(scenario);
+ final List<OFClient> clients = createAndStartClient(1, handler, TransportProtocol.TCP, ClientType.LISTENING);
+ final OFClient ofClient = clients.get(0);
ofClient.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- int listeningClientPort = ((ListeningSimpleClient) ofClient).getPort();
+ final int listeningClientPort = ((ListeningSimpleClient) ofClient).getPort();
mockPlugin.initiateConnection(switchConnectionProvider, "localhost", listeningClientPort);
ofClient.getScenarioDone().get();
LOGGER.debug("testInitiateConnection() Finished") ;