From: Michal Polkorab Date: Wed, 23 Oct 2013 13:32:27 +0000 (+0200) Subject: Improved logging in ScenarioHandler X-Git-Tag: jenkins-openflowjava-bulk-release-prepare-only-1~89 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7c86aed239dce0513fda70c0e4d464e2f2e94742;p=openflowjava.git Improved logging in ScenarioHandler Removed warnings from SimpleClient and IntegrationTest bundles Signed-off-by: Michal Polkorab --- 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 75e5a72a..31c9c635 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 @@ -28,18 +28,15 @@ import org.slf4j.LoggerFactory; /** * @author michal.polkorab - * + * @author timotej.kubas */ public class IntegrationTest { - /** Name of file in which OpenFLow protocol messages are stored in binary format */ + 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; - - protected static final Logger LOGGER = LoggerFactory - .getLogger(IntegrationTest.class); - private static final long CONNECTION_TIMEOUT = 2000; private InetAddress startupAddress; private MockPlugin mockPlugin; @@ -64,13 +61,16 @@ public class IntegrationTest { port = server.getPort(); } + /** + * @throws Exception + */ @After public void tearDown() throws Exception { Thread.sleep(500); } /** - * Library integration and communication test + * Library integration and communication test with handshake * @throws Exception */ @Test @@ -86,7 +86,7 @@ public class IntegrationTest { } /** - * Library integration and communication test + * Library integration and communication test with handshake + echo exchange * @throws Exception */ @Test @@ -117,11 +117,10 @@ public class IntegrationTest { /** * @param amountOfCLients * @return new clients up and running - * @throws InterruptedException - * @throws ExecutionException + * @throws ExecutionException if some client could not start */ private List createAndStartClient(int amountOfCLients, ScenarioHandler scenarioHandler) - throws InterruptedException, ExecutionException { + throws ExecutionException { List clientsHorde = new ArrayList<>(); for (int i = 0; i < amountOfCLients; i++) { LOGGER.debug("startup address in createclient: " + startupAddress.getHostAddress()); diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java index 3ba78a42..73d88fa5 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java @@ -47,7 +47,8 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan private ConnectionAdapter adapter; private SettableFuture finishedFuture; private int idleCounter = 0; - + + /** Creates MockPlugin */ public MockPlugin() { LOGGER.info("Creating MockPlugin"); finishedFuture = SettableFuture.create(); @@ -182,6 +183,9 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan LOGGER.debug("adapter: "+adapter); } + /** + * @return finishedFuture object + */ public SettableFuture getFinishedFuture() { return finishedFuture; } @@ -191,7 +195,10 @@ public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHan LOGGER.debug("switch status: "+notification.getInfo()); idleCounter ++; } - + + /** + * @return number of occured idleEvents + */ public int getIdleCounter() { return idleCounter; } diff --git a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java index a7e9ef0e..3a9bd55b 100644 --- a/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java +++ b/openflow-protocol-it/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java @@ -16,15 +16,21 @@ public class TestingConnConfigImpl implements ConnectionConfiguration { private Object transferProtocol; private FEATURE_SUPPORT tlsSupport; private long switchIdleTimeout; - - // TODO - implement transferProtocol + + /** + * Creates {@link TestingConnConfigImpl} + * @param address + * @param port + * @param tlsSupport + * @param switchIdleTimeout + */ public TestingConnConfigImpl(InetAddress address, int port, FEATURE_SUPPORT tlsSupport, long switchIdleTimeout) { this.address = address; this.port = port; this.tlsSupport = tlsSupport; this.switchIdleTimeout = switchIdleTimeout; } - + @Override public InetAddress getAddress() { return address; diff --git a/openflow-protocol-it/src/test/resources/log4j.xml b/openflow-protocol-it/src/test/resources/log4j.xml index c06081f0..23b1b663 100644 --- a/openflow-protocol-it/src/test/resources/log4j.xml +++ b/openflow-protocol-it/src/test/resources/log4j.xml @@ -12,6 +12,10 @@ + + + + diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java index d5b5332a..2f2d80ba 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ClientEvent.java @@ -1,8 +1,16 @@ /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ package org.opendaylight.openflowjava.protocol.impl.clients; - +/** + * Uniting interface used for scenario support + * @author michal.polkorab + * + */ public interface ClientEvent { + /** + * Common method for triggering events + * @return true if event executed successfully + */ public boolean eventExecuted(); } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java index 633bc7ca..25091960 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioFactory.java @@ -6,8 +6,9 @@ import java.util.Stack; import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; /** + * Class for providing prepared handshake scenario + * * @author michal.polkorab - * */ public class ScenarioFactory { diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java index 45c1ef99..29244dba 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/ScenarioHandler.java @@ -11,13 +11,18 @@ import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +/** + * + * @author michal.polkorab + * + */ public class ScenarioHandler extends Thread { private static final Logger LOGGER = LoggerFactory.getLogger(ScenarioHandler.class); private Stack scenario; private BlockingQueue ofMsg; private ChannelHandlerContext ctx; + private int eventNumber; /** * @@ -32,6 +37,7 @@ public class ScenarioHandler extends Thread { public void run() { int freezeCounter = 0; while (!scenario.isEmpty()) { + LOGGER.debug("Running event #" + eventNumber); ClientEvent peek = scenario.peek(); if (peek instanceof WaitForMessageEvent) { LOGGER.debug("WaitForMessageEvent"); @@ -49,6 +55,7 @@ public class ScenarioHandler extends Thread { } if (peek.eventExecuted()) { scenario.pop(); + eventNumber++; freezeCounter = 0; } else { freezeCounter++; @@ -68,23 +75,38 @@ public class ScenarioHandler extends Thread { this.notify(); } } - + + /** + * @return true if scenario is done / empty + */ public boolean isEmpty() { return scenario.isEmpty(); } + /** + * @return scenario + */ public Stack getScenario() { return scenario; } + /** + * @param scenario scenario filled with desired events + */ public void setScenario(Stack scenario) { this.scenario = scenario; } + /** + * @param ctx context which will be used for sending messages (SendEvents) + */ public void setCtx(ChannelHandlerContext ctx) { this.ctx = ctx; } + /** + * @param message received message that is compared to expected message + */ public void addOfMsg(byte[] message) { ofMsg.add(message); } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java index 57445bd6..d0ec8b9f 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SendEvent.java @@ -8,13 +8,20 @@ import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - +/** + * Class representing sending message event + * + * @author michal.polkorab + */ public class SendEvent implements ClientEvent { protected static final Logger LOGGER = LoggerFactory.getLogger(SendEvent.class); protected byte[] msgToSend; protected ChannelHandlerContext ctx; + /** + * @param msgToSend message to be sent + */ public SendEvent(byte[] msgToSend) { this.msgToSend = msgToSend; } @@ -42,6 +49,9 @@ public class SendEvent implements ClientEvent { return true; } + /** + * @param ctx context which will be used for sending messages (SendEvents) + */ public void setCtx(ChannelHandlerContext ctx) { this.ctx = ctx; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java index f0990dae..110570cd 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java @@ -24,6 +24,7 @@ public class SimpleClientHandler extends ChannelInboundHandlerAdapter { /** * @param isOnlineFuture future notifier of connected channel + * @param scenarioHandler handler of scenario events */ public SimpleClientHandler(SettableFuture isOnlineFuture, ScenarioHandler scenarioHandler) { this.isOnlineFuture = isOnlineFuture; @@ -62,6 +63,9 @@ public class SimpleClientHandler extends ChannelInboundHandlerAdapter { } } + /** + * @param scenarioHandler handler of scenario events + */ public void setScenario(ScenarioHandler scenarioHandler) { this.scenarioHandler = scenarioHandler; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java index c495cbc5..8ca01e8e 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientInitializer.java @@ -25,6 +25,7 @@ public class SimpleClientInitializer extends ChannelInitializer { /** * @param isOnlineFuture future notifier of connected channel + * @param secured true if {@link SimpleClient} should use encrypted communication */ public SimpleClientInitializer(SettableFuture isOnlineFuture, boolean secured) { this.isOnlineFuture = isOnlineFuture; @@ -46,7 +47,10 @@ public class SimpleClientInitializer extends ChannelInitializer { isOnlineFuture = null; } - + + /** + * @param scenarioHandler handler of scenario events + */ public void setScenario(ScenarioHandler scenarioHandler) { this.scenarioHandler = scenarioHandler; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java index eb496ab3..490a094b 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/SleepEvent.java @@ -4,11 +4,20 @@ package org.opendaylight.openflowjava.protocol.impl.clients; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * Class representing sleep (wait) event + * + * @author michal.polkorab + */ public class SleepEvent implements ClientEvent { private static final Logger LOGGER = LoggerFactory.getLogger(SleepEvent.class); private long sleepTime; - + + /** + * + * @param sleepTime time of {@link Thread#sleep(long)} in milliseconds + */ public SleepEvent(long sleepTime) { this.sleepTime = sleepTime; } diff --git a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java index d9a38b02..1ad9b944 100644 --- a/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java +++ b/simple-client/src/main/java/org/opendaylight/openflowjava/protocol/impl/clients/WaitForMessageEvent.java @@ -7,16 +7,21 @@ import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - - +/** + * Class representing waiting on message + * @author michal.polkorab + */ public class WaitForMessageEvent implements ClientEvent { private static final Logger LOGGER = LoggerFactory.getLogger(WaitForMessageEvent.class); private byte[] headerExpected; private byte[] headerReceived; - public WaitForMessageEvent(byte[] headerAwaited) { - this.headerExpected = headerAwaited; + /** + * @param headerExpected header (first 8 bytes) of expected message + */ + public WaitForMessageEvent(byte[] headerExpected) { + this.headerExpected = headerExpected; } @Override @@ -33,6 +38,9 @@ public class WaitForMessageEvent implements ClientEvent { return true; } + /** + * @param headerReceived header (first 8 bytes) of expected message + */ public void setHeaderReceived(byte[] headerReceived) { this.headerReceived = headerReceived; }