Search in sources :

Example 1 with ListeningSimpleClient

use of org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient 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 2 with ListeningSimpleClient

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

the class IntegrationTest method testInitiateConnection.

@Test
public void testInitiateConnection() throws Exception {
    setUp(TransportProtocol.TCP);
    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);
    final int listeningClientPort = ((ListeningSimpleClient) ofClient).getPort();
    mockPlugin.initiateConnection(switchConnectionProvider, "localhost", listeningClientPort);
    ofClient.getScenarioDone().get();
    LOGGER.debug("testInitiateConnection() Finished");
}
Also used : ListeningSimpleClient(org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient) 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)

Aggregations

ListeningSimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.ListeningSimpleClient)2 OFClient (org.opendaylight.openflowjava.protocol.impl.clients.OFClient)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ClientEvent (org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent)1 ScenarioHandler (org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler)1 SimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient)1 UdpSimpleClient (org.opendaylight.openflowjava.protocol.impl.clients.UdpSimpleClient)1