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.net.UnknownHostException;
\r
6 import java.util.ArrayList;
\r
7 import java.util.List;
\r
8 import java.util.concurrent.ExecutionException;
\r
9 import java.util.concurrent.TimeUnit;
\r
11 import org.junit.Before;
\r
12 import org.junit.Test;
\r
13 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration;
\r
14 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration.FEATURE_SUPPORT;
\r
15 import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient;
\r
16 import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl;
\r
17 import org.slf4j.Logger;
\r
18 import org.slf4j.LoggerFactory;
\r
21 * @author michal.polkorab
\r
24 public class IntegrationTest {
\r
26 /** Name of file in which OpenFLow protocol messages are stored in binary format */
\r
27 public static final String OF_BINARY_MESSAGE_INPUT_TXT = "OFBinaryMessageInput.txt";
\r
28 private static final int DEFAULT_PORT = 6633;
\r
29 private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED;
\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
40 * @throws UnknownHostException
\r
43 public void setUp() throws UnknownHostException {
\r
44 startupAddress = InetAddress.getLocalHost();
\r
48 * Library integration and communication test
\r
49 * @throws Exception
\r
52 public void testCommunication() throws Exception {
\r
53 mockPlugin = new MockPlugin();
\r
54 SwitchConnectionProviderImpl scpimpl = new SwitchConnectionProviderImpl();
\r
55 scpimpl.setSwitchConnectionHandler(mockPlugin);
\r
56 List<ConnectionConfiguration> configs = new ArrayList<>();
\r
57 configs.add(new TestingConnConfigImpl(startupAddress, DEFAULT_PORT, DEFAULT_TLS_SUPPORT));
\r
58 scpimpl.configure(configs);
\r
59 scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
\r
61 int amountOfCLients = 1;
\r
62 List<SimpleClient> clients = createAndStartClient(amountOfCLients, 24);
\r
63 SimpleClient firstClient = clients.get(0);
\r
64 firstClient.getAutomatedPartDone().get();
\r
65 firstClient.getDataReceived().get();
\r
66 disconnectClients(clients);
\r
70 * @param amountOfCLients
\r
71 * @param dataLimit TODO
\r
72 * @return new clients up and running
\r
73 * @throws InterruptedException
\r
74 * @throws ExecutionException
\r
76 private List<SimpleClient> createAndStartClient(int amountOfCLients, int dataLimit)
\r
77 throws InterruptedException, ExecutionException {
\r
78 List<SimpleClient> clientsHorde = new ArrayList<>();
\r
79 for (int i = 0; i < amountOfCLients; i++) {
\r
80 LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress());
\r
81 SimpleClient sc = new SimpleClient(startupAddress.getHostAddress(), DEFAULT_PORT,
\r
82 getClass().getResourceAsStream(OF_BINARY_MESSAGE_INPUT_TXT));
\r
83 sc.setSecuredClient(false);
\r
84 clientsHorde.add(sc);
\r
85 sc.setDataLimit(dataLimit);
\r
88 for (SimpleClient sc : clientsHorde) {
\r
90 sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
\r
91 } catch (Exception e) {
\r
92 LOGGER.error(e.getMessage(), e);
\r
93 throw new ExecutionException(e);
\r
96 return clientsHorde;
\r
101 * @throws InterruptedException
\r
103 private static void disconnectClients(List<SimpleClient> clients) throws InterruptedException {
\r
104 List<io.netty.util.concurrent.Future<?>> disconnectFutureBag = new ArrayList<>();
\r
105 for (SimpleClient simpleClient : clients) {
\r
106 disconnectFutureBag.add(simpleClient.disconnect());
\r
108 for (io.netty.util.concurrent.Future<?> toBeDisconnected : disconnectFutureBag) {
\r
109 toBeDisconnected.sync();
\r