Search in sources :

Example 1 with OFClient

use of org.opendaylight.openflowjava.protocol.impl.clients.OFClient in project openflowplugin by opendaylight.

the class IntegrationTest method testTlsHandshake.

/**
 * Library integration and secured communication test with handshake.
 */
@Test
public void testTlsHandshake() throws Exception {
    setUp(TransportProtocol.TLS);
    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);
    LOGGER.debug("testTlsHandshake() Finished");
}
Also used : ScenarioHandler(org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler) OFClient(org.opendaylight.openflowjava.protocol.impl.clients.OFClient) ClientEvent(org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent) Test(org.junit.Test)

Example 2 with OFClient

use of org.opendaylight.openflowjava.protocol.impl.clients.OFClient in project openflowplugin by opendaylight.

the class IntegrationTest method testTlsHandshakeAndEcho.

/**
 * Library integration and secured communication test with handshake + echo exchange.
 */
@Test
public void testTlsHandshakeAndEcho() throws Exception {
    setUp(TransportProtocol.TLS);
    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")));
    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");
}
Also used : ScenarioHandler(org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler) OFClient(org.opendaylight.openflowjava.protocol.impl.clients.OFClient) WaitForMessageEvent(org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent) ClientEvent(org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent) SendEvent(org.opendaylight.openflowjava.protocol.impl.clients.SendEvent) SleepEvent(org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent) Test(org.junit.Test)

Example 3 with OFClient

use of org.opendaylight.openflowjava.protocol.impl.clients.OFClient in project openflowplugin by opendaylight.

the class IntegrationTest method createAndStartClient.

/**
 * 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, InterruptedException, TimeoutException {
    final List<OFClient> clientsHorde = new ArrayList<>();
    for (int i = 0; i < amountOfCLients; i++) {
        LOGGER.debug("startup address in createclient: {}", startupAddress.getHostAddress());
        OFClient sc = null;
        if (clientType == ClientType.SIMPLE) {
            if (protocol.equals(TransportProtocol.TCP)) {
                sc = new SimpleClient(startupAddress.getHostAddress(), port);
                sc.setSecuredClient(false);
            } else if (protocol.equals(TransportProtocol.TLS)) {
                sc = new SimpleClient(startupAddress.getHostAddress(), port);
                sc.setSecuredClient(true);
            } else {
                sc = new UdpSimpleClient(startupAddress.getHostAddress(), port);
            }
        } else if (clientType == ClientType.LISTENING) {
            sc = new ListeningSimpleClient(0);
            sc.setScenarioHandler(scenarioHandler);
            sc.setSecuredClient(false);
        } else {
            LOGGER.error("Unknown type of client.");
            throw new IllegalStateException("Unknown type of client.");
        }
        sc.setScenarioHandler(scenarioHandler);
        clientsHorde.add(sc);
        // sc.run();
        thread = new Thread(sc);
        thread.start();
    }
    for (final OFClient sc : clientsHorde) {
        sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
    }
    return clientsHorde;
}
Also used : ListeningSimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient) ArrayList(java.util.ArrayList) UdpSimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.UdpSimpleClient) OFClient(org.opendaylight.openflowjava.protocol.impl.clients.OFClient) UdpSimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.UdpSimpleClient) ListeningSimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient) SimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient)

Example 4 with OFClient

use of org.opendaylight.openflowjava.protocol.impl.clients.OFClient in project openflowplugin by opendaylight.

the class IntegrationTest method testUdpHandshakeAndEcho.

/**
 * Library udp integration and communication test with handshake + echo exchange.
 */
@Test
public void testUdpHandshakeAndEcho() throws Exception {
    setUp(TransportProtocol.UDP);
    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")));
    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");
}
Also used : ScenarioHandler(org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler) OFClient(org.opendaylight.openflowjava.protocol.impl.clients.OFClient) WaitForMessageEvent(org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent) ClientEvent(org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent) SendEvent(org.opendaylight.openflowjava.protocol.impl.clients.SendEvent) SleepEvent(org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent) Test(org.junit.Test)

Example 5 with OFClient

use of org.opendaylight.openflowjava.protocol.impl.clients.OFClient in project openflowplugin by opendaylight.

the class IntegrationTest method testHandshakeAndEcho.

/**
 * Library integration and communication test with handshake + echo exchange.
 */
@Test
public void testHandshakeAndEcho() throws Exception {
    setUp(TransportProtocol.TCP);
    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")));
    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");
}
Also used : ScenarioHandler(org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler) OFClient(org.opendaylight.openflowjava.protocol.impl.clients.OFClient) WaitForMessageEvent(org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent) ClientEvent(org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent) SendEvent(org.opendaylight.openflowjava.protocol.impl.clients.SendEvent) SleepEvent(org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent) Test(org.junit.Test)

Aggregations

OFClient (org.opendaylight.openflowjava.protocol.impl.clients.OFClient)7 Test (org.junit.Test)6 ClientEvent (org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent)6 ScenarioHandler (org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler)6 SendEvent (org.opendaylight.openflowjava.protocol.impl.clients.SendEvent)3 SleepEvent (org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent)3 WaitForMessageEvent (org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent)3 ListeningSimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient)2 ArrayList (java.util.ArrayList)1 SimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient)1 UdpSimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.UdpSimpleClient)1