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.mockito.Mockito;
+import org.opendaylight.infrautils.diagstatus.DiagStatusService;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfiguration;
import org.opendaylight.openflowjava.protocol.api.connection.TlsConfigurationImpl;
import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;
import org.slf4j.LoggerFactory;
/**
+ * End-to-end integration test.
+ *
* @author michal.polkorab
* @author timotej.kubas
*/
private static int port;
private TlsConfiguration tlsConfiguration;
+ private static final int CHANNEL_OUTBOUND_QUEUE_SIZE = 1024;
private static final int SWITCH_IDLE_TIMEOUT = 2000;
private static final long CONNECTION_TIMEOUT = 2000;
private InetAddress startupAddress;
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, CHANNEL_OUTBOUND_QUEUE_SIZE);
connConfig.setTransferProtocol(protocol);
mockPlugin = new MockPlugin();
- switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig);
+ switchConnectionProvider = new SwitchConnectionProviderImpl(connConfig, Mockito.mock(DiagStatusService.class));
switchConnectionProvider.setSwitchConnectionHandler(mockPlugin);
switchConnectionProvider.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
if (protocol.equals(TransportProtocol.TCP) || protocol.equals(TransportProtocol.TLS)) {
}
}
- /**
- * @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);