Copyright update
[openflowjava.git] / openflow-protocol-it / src / test / java / org / opendaylight / openflowjava / protocol / impl / integration / IntegrationTest.java
index d7d3ccf17f623111488894b80cfcacb953a97373..2627d61fbe760870b475a3f9cd74cc43dea0a641 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.integration;\r
-\r
-import java.net.InetAddress;\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-import java.util.Stack;\r
-import java.util.concurrent.ExecutionException;\r
-import java.util.concurrent.TimeUnit;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;\r
-import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.ClientEvent;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.ScenarioHandler;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.SendEvent;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.SleepEvent;\r
-import org.opendaylight.openflowjava.protocol.impl.clients.WaitForMessageEvent;\r
-import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;\r
-import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler;\r
-import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- * @author michal.polkorab\r
- * @author timotej.kubas\r
- */\r
-public class IntegrationTest {\r
-\r
-    private static final Logger LOGGER = LoggerFactory\r
-            .getLogger(IntegrationTest.class);\r
-    private static int port;\r
-    private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED;\r
-    private static final int SWITCH_IDLE_TIMEOUT = 2000;\r
-    private static final long CONNECTION_TIMEOUT = 2000;\r
-    private InetAddress startupAddress;\r
-    private MockPlugin mockPlugin;\r
-    private SwitchConnectionProviderImpl scpimpl;\r
-    private List<ConnectionConfiguration> configs;\r
-\r
-    /**\r
-     * @throws Exception\r
-     */\r
-    @Before\r
-    public void setUp() throws Exception {\r
-        LOGGER.debug("\n\nstarting test -------------------------------");\r
-        startupAddress = InetAddress.getLocalHost();\r
-        mockPlugin = new MockPlugin();\r
-        scpimpl = new SwitchConnectionProviderImpl();\r
-        scpimpl.setSwitchConnectionHandler(mockPlugin);\r
-        configs = new ArrayList<>();\r
-        configs.add(new TestingConnConfigImpl(startupAddress, 0, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT));\r
-        scpimpl.configure(configs);\r
-        scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);\r
-        TcpHandler server = (TcpHandler) scpimpl.getServerLot().iterator().next();\r
-        port = server.getPort();\r
-    }\r
-\r
-    /**\r
-     * @throws Exception\r
-     */\r
-    @After\r
-    public void tearDown() throws Exception {\r
-        Thread.sleep(500);\r
-    }\r
-\r
-    /**\r
-     * Library integration and communication test with handshake\r
-     * @throws Exception \r
-     */\r
-    @Test\r
-    public void testHandshake() throws Exception {\r
-        int amountOfCLients = 1;\r
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();\r
-        ScenarioHandler handler = new ScenarioHandler(scenario);\r
-        List<SimpleClient> clients = createAndStartClient(amountOfCLients, handler);\r
-        SimpleClient firstClient = clients.get(0);\r
-        firstClient.getScenarioDone().get();\r
-        mockPlugin.shutdown();\r
-        mockPlugin.getFinishedFuture().get();\r
-    }\r
-\r
-    /**\r
-     * Library integration and communication test with handshake + echo exchange\r
-     * @throws Exception \r
-     */\r
-    @Test\r
-    public void testHandshakeAndEcho() throws Exception {\r
-        int amountOfCLients = 1;\r
-        Stack<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();\r
-        scenario.add(0, new SleepEvent(100));\r
-        scenario.add(0, new SendEvent(ByteBufUtils.hexStringToBytes("04 02 00 08 00 00 00 04")));\r
-        scenario.add(0, new SleepEvent(100));\r
-        scenario.add(0, new WaitForMessageEvent(ByteBufUtils.hexStringToBytes("04 03 00 08 00 00 00 04")));\r
-        ScenarioHandler handler = new ScenarioHandler(scenario);\r
-        List<SimpleClient> clients = createAndStartClient(amountOfCLients, handler);\r
-        SimpleClient firstClient = clients.get(0);\r
-        firstClient.getScenarioDone().get();\r
-        mockPlugin.shutdown();\r
-        mockPlugin.getFinishedFuture().get();\r
-    }\r
-\r
-    /**\r
-     * Library integration and communication test (with virtual machine)\r
-     * @throws Exception\r
-     */\r
-    //@Test\r
-    public void testCommunicationWithVM() throws Exception {\r
-        mockPlugin.getFinishedFuture().get();\r
-    }\r
-    \r
-    /**\r
-     * @param amountOfCLients \r
-     * @return new clients up and running\r
-     * @throws ExecutionException if some client could not start\r
-     */\r
-    private List<SimpleClient> createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler)\r
-            throws ExecutionException {\r
-        List<SimpleClient> clientsHorde = new ArrayList<>();\r
-        for (int i = 0; i < amountOfCLients; i++) {\r
-            LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress());\r
-            SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), port);\r
-            sc.setSecuredClient(false);\r
-            sc.setScenarioHandler(scenarioHandler);\r
-            clientsHorde.add(sc);\r
-            sc.start();\r
-        }\r
-        for (SimpleClient sc : clientsHorde) {\r
-            try {\r
-                sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);\r
-            } catch (Exception e) {\r
-                LOGGER.error(e.getMessage(), e);\r
-                throw new ExecutionException(e);\r
-            }\r
-        }\r
-        return clientsHorde;\r
-    }\r
-\r
-}\r
+/*
+ * 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<ConnectionConfiguration> 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<ClientEvent> scenario = ScenarioFactory.createHandshakeScenario();
+        ScenarioHandler handler = new ScenarioHandler(scenario);
+        List<SimpleClient> 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<ClientEvent> 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<SimpleClient> 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<SimpleClient> createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler)
+            throws ExecutionException {
+        List<SimpleClient> 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;
+    }
+
+}