1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
\r
2 package org.opendaylight.openflowjava.protocol.impl.integration;
\r
4 import java.net.InetAddress;
\r
5 import java.util.ArrayList;
\r
6 import java.util.List;
\r
7 import java.util.concurrent.ExecutionException;
\r
8 import java.util.concurrent.TimeUnit;
\r
10 import org.junit.Before;
\r
11 import org.junit.Test;
\r
12 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
\r
13 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT;
\r
14 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
\r
15 import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;
\r
16 import org.slf4j.Logger;
\r
17 import org.slf4j.LoggerFactory;
\r
20 * @author michal.polkorab
\r
23 public class IntegrationTest {
\r
25 /** Name of file in which OpenFLow protocol messages are stored in binary format */
\r
26 public static final String OF_BINARY_MESSAGE_INPUT_TXT = "OFBinaryMessageInput.txt";
\r
27 private static final int DEFAULT_PORT = 6633;
\r
28 private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED;
\r
29 private static final int SWITCH_IDLE_TIMEOUT = 2000;
\r
31 protected static final Logger LOGGER = LoggerFactory
\r
32 .getLogger(IntegrationTest.class);
\r
34 private static final long CONNECTION_TIMEOUT = 2000;
\r
36 private InetAddress startupAddress;
\r
37 private MockPlugin mockPlugin;
\r
43 public void setUp() throws Exception {
\r
44 startupAddress = InetAddress.getLocalHost();
\r
45 mockPlugin = new MockPlugin();
\r
46 SwitchConnectionProviderImpl scpimpl = new SwitchConnectionProviderImpl();
\r
47 scpimpl.setSwitchConnectionHandler(mockPlugin);
\r
48 List<ConnectionConfiguration> configs = new ArrayList<>();
\r
49 configs.add(new TestingConnConfigImpl(startupAddress, DEFAULT_PORT, DEFAULT_TLS_SUPPORT, SWITCH_IDLE_TIMEOUT));
\r
50 scpimpl.configure(configs);
\r
51 scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
\r
55 * Library integration and communication test
\r
56 * @throws Exception
\r
59 public void testCommunication() throws Exception {
\r
60 int amountOfCLients = 1;
\r
61 List<SimpleClient> clients = createAndStartClient(amountOfCLients);
\r
62 SimpleClient firstClient = clients.get(0);
\r
63 firstClient.getAutomatedPartDone().get();
\r
64 mockPlugin.getFinishedFuture().get();
\r
68 * Library integration and communication test (with virtual machine)
\r
72 public void testCommunicationWithVM() throws Exception {
\r
73 mockPlugin.getFinishedFuture().get();
\r
77 * @param amountOfCLients
\r
78 * @return new clients up and running
\r
79 * @throws InterruptedException
\r
80 * @throws ExecutionException
\r
82 private List<SimpleClient> createAndStartClient(int amountOfCLients)
\r
83 throws InterruptedException, ExecutionException {
\r
84 List<SimpleClient> clientsHorde = new ArrayList<>();
\r
85 for (int i = 0; i < amountOfCLients; i++) {
\r
86 LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress());
\r
87 SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), DEFAULT_PORT,
\r
88 getClass().getResourceAsStream(OF_BINARY_MESSAGE_INPUT_TXT));
\r
89 sc.setSecuredClient(false);
\r
90 clientsHorde.add(sc);
\r
93 for (SimpleClient sc : clientsHorde) {
\r
95 sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
\r
96 } catch (Exception e) {
\r
97 LOGGER.error(e.getMessage(), e);
\r
98 throw new ExecutionException(e);
\r
101 return clientsHorde;
\r
106 * @throws InterruptedException
\r
108 private static void disconnectClients(List<SimpleClient> clients) throws InterruptedException {
\r
109 List<io.netty.util.concurrent.Future<?>> disconnectFutureBag = new ArrayList<>();
\r
110 for (SimpleClient simpleClient : clients) {
\r
111 disconnectFutureBag.add(simpleClient.disconnect());
\r
113 for (io.netty.util.concurrent.Future<?> toBeDisconnected : disconnectFutureBag) {
\r
114 toBeDisconnected.sync();
\r