X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fintegration%2FIntegrationTest.java;h=2627d61fbe760870b475a3f9cd74cc43dea0a641;hb=0d942e8fb70b2c21f97eea3ed8904336ab5c54a4;hp=d7d3ccf17f623111488894b80cfcacb953a97373;hpb=537927d0952c74dd362ede53fbbed7db8d53fc7b;p=openflowjava.git diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java index d7d3ccf1..2627d61f 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java @@ -1,144 +1,151 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.integration; - -import java.net.InetAddress; -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; -import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory; -import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler; -import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient; -import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent; -import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent; -import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl; -import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author michal.polkorab - * @author timotej.kubas - */ -public class IntegrationTest { - - private static final Logger LOGGER = LoggerFactory - .getLogger(IntegrationTest.class); - private static int port; - private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED; - private static final int SWITCH_IDLE_TIMEOUT = 2000; - private static final long CONNECTION_TIMEOUT = 2000; - private InetAddress startupAddress; - private MockPlugin mockPlugin; - private SwitchConnectionProviderImpl scpimpl; - private List configs; - - /** - * @throws Exception - */ - @Before - public void setUp() throws Exception { - LOGGER.debug("\n\nstarting test -------------------------------"); - startupAddress = InetAddress.getLocalHost(); - mockPlugin = new MockPlugin(); - scpimpl = new SwitchConnectionProviderImpl(); - scpimpl.setSwitchConnectionHandler(mockPlugin); - configs = new ArrayList<>(); - configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT)); - scpimpl.configure(configs); - scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); - TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next(); - port = server.getPort(); - } - - /** - * @throws Exception - */ - @After - public void tearDown() throws Exception { - Thread.sleep(500); - } - - /** - * Library integration and communication test with handshake - * @throws Exception - */ - @Test - public void testHandshake() throws Exception { - int amountOfCLients = 1; - Stack scenario = ScenarioFactory.createHandshakeScenario(); - ScenarioHandler handler = new ScenarioHandler(scenario); - List clients = createAndStartClient(amountOfCLients, handler); - SimpleClient firstClient = clients.get(0); - firstClient.getScenarioDone().get(); - mockPlugin.shutdown(); - mockPlugin.getFinishedFuture().get(); - } - - /** - * Library integration and communication test with handshake + echo exchange - * @throws Exception - */ - @Test - public void testHandshakeAndEcho() throws Exception { - int amountOfCLients = 1; - Stack scenario = ScenarioFactory.createHandshakeScenario(); - scenario.add(0, new SleepEvent(100)); - scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04"))); - scenario.add(0, new SleepEvent(100)); - scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04"))); - ScenarioHandler handler = new ScenarioHandler(scenario); - List clients = createAndStartClient(amountOfCLients, handler); - SimpleClient firstClient = clients.get(0); - firstClient.getScenarioDone().get(); - mockPlugin.shutdown(); - mockPlugin.getFinishedFuture().get(); - } - - /** - * Library integration and communication test (with virtual machine) - * @throws Exception - */ - //@Test - public void testCommunicationWithVM() throws Exception { - mockPlugin.getFinishedFuture().get(); - } - - /** - * @param amountOfCLients - * @return new clients up and running - * @throws ExecutionException if some client could not start - */ - private List createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler) - throws ExecutionException { - List clientsHorde = new ArrayList<>(); - for (int i = 0; i < amountOfCLients; i++) { - LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); - SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), port); - sc.setSecuredClient(false); - sc.setScenarioHandler(scenarioHandler); - clientsHorde.add(sc); - sc.start(); - } - for (SimpleClient sc : clientsHorde) { - try { - sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); - } catch (Exception e) { - LOGGER.error(e.getMessage(), e); - throw new ExecutionException(e); - } - } - return clientsHorde; - } - -} +/* + * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT; +import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory; +import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler; +import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient; +import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent; +import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent; +import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl; +import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * @author timotej.kubas + */ +public class IntegrationTest { + + private static final Logger LOGGER = LoggerFactory + .getLogger(IntegrationTest.class); + private static int port; + private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED; + private static final int SWITCH_IDLE_TIMEOUT = 2000; + private static final long CONNECTION_TIMEOUT = 2000; + private InetAddress startupAddress; + private MockPlugin mockPlugin; + private SwitchConnectionProviderImpl scpimpl; + private List configs; + + /** + * @throws Exception + */ + @Before + public void setUp() throws Exception { + LOGGER.debug("\n\nstarting test -------------------------------"); + startupAddress = InetAddress.getLocalHost(); + mockPlugin = new MockPlugin(); + scpimpl = new SwitchConnectionProviderImpl(); + scpimpl.setSwitchConnectionHandler(mockPlugin); + configs = new ArrayList<>(); + configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT)); + scpimpl.configure(configs); + scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next(); + port = server.getPort(); + } + + /** + * @throws Exception + */ + @After + public void tearDown() throws Exception { + Thread.sleep(500); + } + + /** + * Library integration and communication test with handshake + * @throws Exception + */ + @Test + public void testHandshake() throws Exception { + int amountOfCLients = 1; + Stack scenario = ScenarioFactory.createHandshakeScenario(); + ScenarioHandler handler = new ScenarioHandler(scenario); + List clients = createAndStartClient(amountOfCLients, handler); + SimpleClient firstClient = clients.get(0); + firstClient.getScenarioDone().get(); + mockPlugin.shutdown(); + mockPlugin.getFinishedFuture().get(); + } + + /** + * Library integration and communication test with handshake + echo exchange + * @throws Exception + */ + @Test + public void testHandshakeAndEcho() throws Exception { + int amountOfCLients = 1; + Stack scenario = ScenarioFactory.createHandshakeScenario(); + scenario.add(0, new SleepEvent(100)); + scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04"))); + scenario.add(0, new SleepEvent(100)); + scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04"))); + ScenarioHandler handler = new ScenarioHandler(scenario); + List clients = createAndStartClient(amountOfCLients, handler); + SimpleClient firstClient = clients.get(0); + firstClient.getScenarioDone().get(); + mockPlugin.shutdown(); + mockPlugin.getFinishedFuture().get(); + } + + /** + * Library integration and communication test (with virtual machine) + * @throws Exception + */ + //@Test + public void testCommunicationWithVM() throws Exception { + mockPlugin.getFinishedFuture().get(); + } + + /** + * @param amountOfCLients + * @return new clients up and running + * @throws ExecutionException if some client could not start + */ + private List createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler) + throws ExecutionException { + List clientsHorde = new ArrayList<>(); + for (int i = 0; i < amountOfCLients; i++) { + LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); + SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), port); + sc.setSecuredClient(false); + sc.setScenarioHandler(scenarioHandler); + clientsHorde.add(sc); + sc.start(); + } + for (SimpleClient sc : clientsHorde) { + try { + sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + throw new ExecutionException(e); + } + } + return clientsHorde; + } + +}