import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.junit.After;
import org.junit.Test;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
import org.slf4j.LoggerFactory;
/**
+ * End-to-end integration test.
+ *
* @author michal.polkorab
* @author timotej.kubas
*/
private SwitchConnectionProviderImpl switchConnectionProvider;
private ConnectionConfigurationImpl connConfig;
- private Thread t;
+ private Thread thread;
+
+ private enum ClientType {
+ SIMPLE,
+ LISTENING
+ }
- private enum ClientType {SIMPLE, LISTENING}
- /**
- * @param protocol communication protocol to be used during test
- * @throws Exception
- */
public void setUp(final TransportProtocol protocol) throws Exception {
LOGGER.debug("\n starting test -------------------------------");
"/selfSignedController", PathType.CLASSPATH,
new ArrayList<String>());
}
- connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration, SWITCH_IDLE_TIMEOUT, true, false);
+ connConfig = new ConnectionConfigurationImpl(startupAddress, 0, tlsConfiguration,
+ SWITCH_IDLE_TIMEOUT, true, false);
connConfig.setTransferProtocol(protocol);
mockPlugin = new MockPlugin();
}
}
- /**
- * @throws Exception
- */
@After
public void tearDown() throws Exception {
switchConnectionProvider.close();
}
/**
- * Library integration and communication test with handshake
- * @throws Exception
+ * Library integration and communication test with handshake.
*/
@Test
public void testHandshake() throws Exception {
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 List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+ TransportProtocol.TCP, ClientType.SIMPLE);
final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
Thread.sleep(1000);
}
/**
- * Library integration and secured communication test with handshake
- * @throws Exception
+ * Library integration and secured communication test with handshake.
*/
@Test
public void testTlsHandshake() throws Exception {
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 List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+ TransportProtocol.TLS, ClientType.SIMPLE);
final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
Thread.sleep(1000);
}
/**
- * Library integration and communication test with handshake + echo exchange
- * @throws Exception
+ * Library integration and communication test with handshake + echo exchange.
*/
@Test
public void testHandshakeAndEcho() throws Exception {
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
final ScenarioHandler handler = new ScenarioHandler(scenario);
- final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TCP, ClientType.SIMPLE);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+ TransportProtocol.TCP, ClientType.SIMPLE);
final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
}
/**
- * Library integration and secured communication test with handshake + echo exchange
- * @throws Exception
+ * Library integration and secured communication test with handshake + echo exchange.
*/
@Test
public void testTlsHandshakeAndEcho() throws Exception {
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
final ScenarioHandler handler = new ScenarioHandler(scenario);
- final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.TLS, ClientType.SIMPLE);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+ TransportProtocol.TLS, ClientType.SIMPLE);
final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
}
/**
- * Library udp integration and communication test with handshake + echo exchange
- * @throws Exception
+ * Library udp integration and communication test with handshake + echo exchange.
*/
@Test
public void testUdpHandshakeAndEcho() throws Exception {
scenario.addFirst(new SleepEvent(1000));
scenario.addFirst(new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));
final ScenarioHandler handler = new ScenarioHandler(scenario);
- final List<OFClient> clients = createAndStartClient(amountOfCLients, handler, TransportProtocol.UDP, ClientType.SIMPLE);
+ final List<OFClient> clients = createAndStartClient(amountOfCLients, handler,
+ TransportProtocol.UDP, ClientType.SIMPLE);
final OFClient firstClient = clients.get(0);
firstClient.getScenarioDone().get();
}
/**
- * Library integration and communication test (with virtual machine)
- * @throws Exception
+ * Library integration and communication test (with virtual machine).
*/
//@Test
public void testCommunicationWithVM() throws Exception {
}
/**
- * @param amountOfCLients
+ * Creates and start a client.
+ *
+ * @param amountOfCLients number of clients
* @param protocol true if encrypted connection should be used
* @return new clients up and running
* @throws ExecutionException if some client could not start
*/
private List<OFClient> createAndStartClient(final int amountOfCLients, final ScenarioHandler scenarioHandler,
- final TransportProtocol protocol, final ClientType clientType) throws ExecutionException {
+ final TransportProtocol protocol, final ClientType clientType)
+ throws ExecutionException, InterruptedException, TimeoutException {
final List<OFClient> clientsHorde = new ArrayList<>();
for (int i = 0; i < amountOfCLients; i++) {
LOGGER.debug("startup address in createclient: {}", startupAddress.getHostAddress());
sc.setScenarioHandler(scenarioHandler);
clientsHorde.add(sc);
//sc.run();
- t = new Thread(sc);
- t.start();
+ thread = new Thread(sc);
+ thread.start();
}
for (final OFClient sc : clientsHorde) {
- try {
- sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
- } catch (final Exception e) {
- LOGGER.error("createAndStartClient: Something borked ... ", e.getMessage(), e);
- throw new ExecutionException(e);
- }
+ sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
}
return clientsHorde;
}
- /**
- * @throws Exception
- */
@Test
public void testInitiateConnection() throws Exception {
setUp(TransportProtocol.TCP);
package org.opendaylight.openflowjava.protocol.it.integration;
+import com.google.common.util.concurrent.SettableFuture;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
-
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.google.common.util.concurrent.SettableFuture;
-
/**
- * @author michal.polkorab
+ * Mock plugin.
*
+ * @author michal.polkorab
*/
public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler,
SystemNotificationsListener, ConnectionReadyListener {
protected static final Logger LOGGER = LoggerFactory.getLogger(MockPlugin.class);
protected volatile ConnectionAdapter adapter;
- private SettableFuture<Void> finishedFuture;
+ private final SettableFuture<Void> finishedFuture;
private int idleCounter = 0;
- /** Creates MockPlugin */
public MockPlugin() {
LOGGER.trace("Creating MockPlugin");
finishedFuture = SettableFuture.create();
@Override
public void onEchoRequestMessage(final EchoRequestMessage notification) {
LOGGER.debug("MockPlugin.onEchoRequestMessage() adapter: {}", adapter);
- new Thread(new Runnable() {
- @Override
- public void run() {
- LOGGER.debug("MockPlugin.onEchoRequestMessage().run() started adapter: {}", adapter);
- EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder();
- replyBuilder.setVersion((short) 4);
- replyBuilder.setXid(notification.getXid());
- EchoReplyInput echoReplyInput = replyBuilder.build();
- adapter.echoReply(echoReplyInput);
- LOGGER.debug("adapter.EchoReply(Input) sent : ", echoReplyInput.toString());
- LOGGER.debug("MockPlugin.onEchoRequestMessage().run() finished adapter: {}", adapter);
- }
+ new Thread(() -> {
+ LOGGER.debug("MockPlugin.onEchoRequestMessage().run() started adapter: {}", adapter);
+ EchoReplyInputBuilder replyBuilder = new EchoReplyInputBuilder();
+ replyBuilder.setVersion((short) 4);
+ replyBuilder.setXid(notification.getXid());
+ EchoReplyInput echoReplyInput = replyBuilder.build();
+ adapter.echoReply(echoReplyInput);
+ LOGGER.debug("adapter.EchoReply(Input) sent : ", echoReplyInput.toString());
+ LOGGER.debug("MockPlugin.onEchoRequestMessage().run() finished adapter: {}", adapter);
}).start();
}
@Override
public void onHelloMessage(HelloMessage notification) {
- new Thread(new Runnable() {
- @Override
- public void run() {
- LOGGER.debug("MockPlugin.onHelloMessage().run() Hello message received");
- HelloInputBuilder hib = new HelloInputBuilder();
- hib.setVersion((short) 4);
- hib.setXid(2L);
- HelloInput hi = hib.build();
- adapter.hello(hi);
- LOGGER.debug("hello msg sent");
- new Thread(new Runnable() {
- @Override
- public void run() {
- getSwitchFeatures();
- }
- }).start();
- }
+ new Thread(() -> {
+ LOGGER.debug("MockPlugin.onHelloMessage().run() Hello message received");
+ HelloInputBuilder hib = new HelloInputBuilder();
+ hib.setVersion((short) 4);
+ hib.setXid(2L);
+ HelloInput hi = hib.build();
+ adapter.hello(hi);
+ LOGGER.debug("hello msg sent");
+ new Thread(() -> getSwitchFeatures()).start();
}).start();
}
}
}
- protected void shutdown() {
- try {
- LOGGER.debug("MockPlugin.shutdown() sleeping 5... : {}", System.identityHashCode(this));
- Thread.sleep(500);
- if (adapter != null) {
- Future<Boolean> disconnect = adapter.disconnect();
- disconnect.get();
- LOGGER.debug("MockPlugin.shutdown() Disconnected");
- }
- } catch (Exception e) {
- LOGGER.error("MockPlugin.shutdown() exception caught: ", e.getMessage(), e);
+ protected void shutdown() throws InterruptedException, ExecutionException {
+ LOGGER.debug("MockPlugin.shutdown() sleeping 5... : {}", System.identityHashCode(this));
+ Thread.sleep(500);
+ if (adapter != null) {
+ Future<Boolean> disconnect = adapter.disconnect();
+ disconnect.get();
+ LOGGER.debug("MockPlugin.shutdown() Disconnected");
}
+
finishedFuture.set(null);
}
LOGGER.debug("disconnection occured: {}", notification.getInfo());
}
- /**
- * @return finishedFuture object
- */
public SettableFuture<Void> getFinishedFuture() {
return finishedFuture;
}
}
/**
- * @return number of occured idleEvents
+ * Returns number of occurred idleEvents.
*/
public int getIdleCounter() {
return idleCounter;
}
/**
- * Initiates connection to device
- * @param switchConnectionProvider
+ * Initiates connection to device.
+ *
+ * @param switchConnectionProvider the SwitchConnectionProviderImpl
* @param host - host IP
* @param port - port number
*/
package org.opendaylight.openflowjava.protocol.spi.connection;
+import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler;
import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerExtensionProvider;
import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerExtensionProvider;
-import com.google.common.util.concurrent.ListenableFuture;
-
/**
+ * Provides handling for a swicth connection.
+ *
* @author mirehak
* @author michal.polkorab
- *
*/
public interface SwitchConnectionProvider extends AutoCloseable,
SerializerExtensionProvider, DeserializerExtensionProvider {
/**
- * return the connection configuration
+ * Returns the connection configuration.
+ *
* @return configuration [protocol, port, address and supported features]
*/
ConnectionConfiguration getConfiguration();
/**
- * start listening to switches, but please don't forget to do
- * {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first
+ * Start listening to switches, but please don't forget to do
+ * {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first.
+ *
* @return future, triggered to true, when listening channel is up and running
*/
ListenableFuture<Boolean> startup();
/**
- * stop listening to switches
+ * Stop listening to switches.
+ *
* @return future, triggered to true, when all listening channels are down
*/
ListenableFuture<Boolean> shutdown();
/**
+ * Sets the SwitchConnectionHandler.
+ *
* @param switchConHandler instance being informed when new switch connects
*/
void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler);
-}
\ No newline at end of file
+}