From 8dda3700d7c10753ead351f87d6e4b4699761fe4 Mon Sep 17 00:00:00 2001 From: "michal.polkorab" Date: Thu, 19 Sep 2013 16:19:44 +0200 Subject: [PATCH] Draft implementation of integration tests (Re)implemented funcionality in components used for lib <-> plugin communication Unit tests now uses mock objects instead of EmbeddedChannel Signed-off-by: michal.polkorab Change-Id: Ic4932bd0d6d73066ce2f51b5a9ef2966af095f4c --- .../api/connection/ConnectionAdapter.java | 8 + .../src/main/yang/openflow-protocol.yang | 103 +++++++++- openflow-protocol-impl/pom.xml | 5 + .../impl/connection/CommunicationFacade.java | 13 ++ .../connection/ConnectionAdapterFactory.java | 6 +- .../connection/ConnectionAdapterImpl.java | 24 ++- .../impl/connection/MessageConsumer.java | 7 + .../SwitchConnectionProviderImpl.java | 9 +- .../impl/core/DelegatingInboundHandler.java | 35 ++++ .../protocol/impl/core/OF13Codec.java | 109 ---------- .../protocol/impl/core/OF13Decoder.java | 38 ++++ .../protocol/impl/core/OF13Encoder.java | 25 +++ .../protocol/impl/core/OFFrameDecoder.java | 3 +- .../protocol/impl/core/OFVersionDetector.java | 28 ++- .../core/PublishingChannelInitializer.java | 10 +- .../protocol/impl/core/TcpHandler.java | 34 +++- .../protocol/impl/core/TlsDetector.java | 4 +- .../impl/core/VersionMessageWrapper.java | 40 ++++ .../MultipartReplyMessageFactory.java | 2 +- .../src/main/resources/log4j.xml | 4 +- .../protocol/impl/clients/SimpleClient.java | 8 +- .../impl/clients/SimpleClientHandler.java | 17 +- .../impl/core/OFFrameDecoderTest.java | 135 +++++++++---- .../impl/core/OFVersionDetectorTest.java | 97 ++++++--- .../protocol/impl/core/TcpHandlerTest.java | 190 ------------------ .../MultipartReplyMessageFactoryTest.java | 2 +- .../impl/integration/IntegrationTest.java | 107 ++++++++++ .../protocol/impl/integration/MockPlugin.java | 107 ++++++++++ .../integration/TestingConnConfigImpl.java | 46 +++++ .../BarrierInputMessageFactoryTest.java | 2 +- .../EchoInputMessageFactoryTest.java | 2 +- .../EchoReplyInputMessageFactoryTest.java | 2 +- .../GetConfigInputMessageFactoryTest.java | 2 +- .../GetFeaturesInputMessageFactoryTest.java | 2 +- .../HelloInputMessageFactoryTest.java | 2 +- .../protocol/impl/util/BufferHelper.java | 6 +- .../OFBinaryMessageInput.txt | Bin .../connection/SwitchConnectionProvider.java | 6 +- 38 files changed, 804 insertions(+), 436 deletions(-) create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/CommunicationFacade.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java delete mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Codec.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java create mode 100644 openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/VersionMessageWrapper.java delete mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandlerTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java create mode 100644 openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java rename openflow-protocol-impl/src/test/resources/org/opendaylight/openflowjava/protocol/impl/{core => integration}/OFBinaryMessageInput.txt (100%) diff --git a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java index 04a9ecc4..888a7391 100644 --- a/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java +++ b/openflow-protocol-api/src/main/java/org/opendaylight/openflowjava/protocol/api/connection/ConnectionAdapter.java @@ -15,6 +15,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 /** * @author mirehak + * @author michal.polkorab */ public interface ConnectionAdapter extends OpenflowProtocolService { @@ -33,4 +34,11 @@ public interface ConnectionAdapter extends OpenflowProtocolService { * @param messageListener here will be pushed all messages from switch */ public void setMessageListener(OpenflowProtocolListener messageListener); + + /** + * @param version version of OpenFlow protocol to be used for communication with switch + * (set after version negotiation) - in wire protocol format e.g. 4 (or 0x04) for OF 1.3 + * + */ + public void setVersion(int version); } diff --git a/openflow-protocol-api/src/main/yang/openflow-protocol.yang b/openflow-protocol-api/src/main/yang/openflow-protocol.yang index 0782afec..37fb5ae1 100644 --- a/openflow-protocol-api/src/main/yang/openflow-protocol.yang +++ b/openflow-protocol-api/src/main/yang/openflow-protocol.yang @@ -96,10 +96,6 @@ module openflow-protocol { type oft:hello-element-type; //reference "OpenFlow Header element type - OFPHET_*"; } - leaf length { - type uint16; - //reference "OpenFlow Header element length"; - } } grouping hello { // reference "OFPT_HELLO message in Openflow Switch 1.3 Spec" @@ -462,8 +458,45 @@ module openflow-protocol { leaf flags { type oft:multipart-request-flags; } - leaf body { - type binary; + choice body { + case multipart-flow { + leaf length { + type uint16; + } + leaf table-id { + type uint8; + } + leaf duration-sec { + type uint32; + } + leaf duration-nsec { + type uint32; + } + leaf priority { + type uint16; + } + leaf idle-timeout { + type uint16; + } + leaf hard-timeout { + type uint16; + } + leaf flags { + type uint16; + } + leaf cookie { + type uint64; + } + leaf packet-count { + type uint64; + } + leaf byte-count { + type uint64; + } + leaf match { + type uint64; + } + } } } grouping multipart-reply { @@ -478,8 +511,62 @@ module openflow-protocol { leaf flags { type oft:multipart-request-flags; } - leaf body { - type binary; + choice body { + case multipart-desc { + leaf mfr_desc { + type string; + } + leaf hw_desc { + type string; + } + leaf sw_desc { + type string; + } + leaf serial_num { + type string; + } + leaf dp_desc { + type string; + } + } + case multipart-flow { + leaf length { + type uint16; + } + leaf table-id { + type uint8; + } + leaf duration-sec { + type uint32; + } + leaf duration-nsec { + type uint32; + } + leaf priority { + type uint16; + } + leaf idle-timeout { + type uint16; + } + leaf hard-timeout { + type uint16; + } + leaf flags { + type uint16; + } + leaf cookie { + type uint64; + } + leaf packet-count { + type uint64; + } + leaf byte-count { + type uint64; + } + leaf match { + type uint64; + } + } } } /* Barrier messages. */ diff --git a/openflow-protocol-impl/pom.xml b/openflow-protocol-impl/pom.xml index ec4e1c4d..34b57ad4 100644 --- a/openflow-protocol-impl/pom.xml +++ b/openflow-protocol-impl/pom.xml @@ -45,5 +45,10 @@ junit test + + org.mockito + mockito-all + 1.9.5 + diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/CommunicationFacade.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/CommunicationFacade.java new file mode 100644 index 00000000..1ac5c2b1 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/CommunicationFacade.java @@ -0,0 +1,13 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.connection; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; + +/** + * @author michal.polkorab + * + */ +public interface CommunicationFacade extends MessageConsumer, ConnectionAdapter { + + // empty unifying superinterface +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java index 2ca3dec6..33048177 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterFactory.java @@ -10,11 +10,9 @@ package org.opendaylight.openflowjava.protocol.impl.connection; import io.netty.channel.socket.SocketChannel; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; - /** * @author mirehak - * + * @author michal.polkorab */ public abstract class ConnectionAdapterFactory { @@ -22,7 +20,7 @@ public abstract class ConnectionAdapterFactory { * @param ch * @return connection adapter tcp-implementation */ - public static ConnectionAdapter createConnectionAdapter(SocketChannel ch) { + public static CommunicationFacade createConnectionAdapter(SocketChannel ch) { ConnectionAdapterImpl connectionAdapter = new ConnectionAdapterImpl(); connectionAdapter.setChannel(ch); return connectionAdapter; diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java index 5f670132..9457373d 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/ConnectionAdapterImpl.java @@ -18,7 +18,6 @@ import java.util.concurrent.TimeUnit; import org.opendaylight.controller.sal.common.util.RpcErrors; import org.opendaylight.controller.sal.common.util.Rpcs; -import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput; @@ -73,9 +72,9 @@ import com.google.common.util.concurrent.SettableFuture; /** * @author mirehak - * + * @author michal.polkorab */ -public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer { +public class ConnectionAdapterImpl implements CommunicationFacade { /** after this time, rpc future response objects will be thrown away (in minutes) */ public static final int RPC_RESPONSE_EXPIRATION = 1; @@ -87,6 +86,7 @@ public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer private static final String TAG = "OPENFLOW"; private Channel channel; private OpenflowProtocolListener messageListener; + private int version; /** expiring cache for future rpcResponses */ protected Cache> responseCache; @@ -107,11 +107,13 @@ public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer notification.getValue().cancel(true); } }).build(); + LOG.info("ConnectionAdapter created"); } /** - * @param channel the channel to set + * @param channel the channel to be set - used for communication */ + @Override public void setChannel(Channel channel) { this.channel = channel; } @@ -238,6 +240,11 @@ public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer @Override public void consume(DataObject message) { + if (message == null) { + LOG.error("message is null"); + } else { + LOG.debug("message is ok"); + } if (message instanceof Notification) { if (message instanceof EchoRequestMessage) { messageListener.onEchoRequestMessage((EchoRequestMessage) message); @@ -248,6 +255,7 @@ public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer } else if (message instanceof FlowRemovedMessage) { messageListener.onFlowRemovedMessage((FlowRemovedMessage) message); } else if (message instanceof HelloMessage) { + LOG.info("Hello received / branch"); messageListener.onHelloMessage((HelloMessage) message); } else if (message instanceof MultipartReplyMessage) { messageListener.onMultipartReplyMessage((MultipartReplyMessage) message); @@ -464,4 +472,12 @@ public class ConnectionAdapterImpl implements ConnectionAdapter, MessageConsumer return (SettableFuture>) responseCache.getIfPresent(key); } + /* (non-Javadoc) + * @see org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter#setVersion(int) + */ + @Override + public void setVersion(int version) { + this.version = version; + } + } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java index ca6d7f76..3f1bf2d8 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/MessageConsumer.java @@ -8,6 +8,8 @@ package org.opendaylight.openflowjava.protocol.impl.connection; +import io.netty.channel.Channel; + import org.opendaylight.yangtools.yang.binding.DataObject; /** @@ -20,4 +22,9 @@ public interface MessageConsumer { * @param message to process */ public void consume(DataObject message); + + /** + * @param channel sets processing channel + */ + public void setChannel(Channel channel); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java index 858abfa7..1ce61d19 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/connection/SwitchConnectionProviderImpl.java @@ -11,6 +11,7 @@ package org.opendaylight.openflowjava.protocol.impl.connection; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.concurrent.Future; @@ -43,11 +44,15 @@ public class SwitchConnectionProviderImpl implements SwitchConnectionProvider { //TODO - add and configure servers according to configuration serverLot = new HashSet<>(); - serverLot.add(new TcpHandler(6633)); + for (Iterator iterator = connConfigs.iterator(); iterator.hasNext();) { + ConnectionConfiguration connConfig = iterator.next(); + serverLot.add(new TcpHandler(connConfig.getAddress(), connConfig.getPort())); + } } @Override - public void setSwitchConnectionListener(SwitchConnectionHandler switchConnectionHandler) { + public void setSwitchConnectionHandler(SwitchConnectionHandler switchConnectionHandler) { + LOG.debug("setSwitchConnectionHanler"); this.switchConnectionHandler = switchConnectionHandler; } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java new file mode 100644 index 00000000..66db71e2 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/DelegatingInboundHandler.java @@ -0,0 +1,35 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelInboundHandlerAdapter; + +import org.opendaylight.openflowjava.protocol.impl.connection.MessageConsumer; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * + */ +public class DelegatingInboundHandler extends ChannelInboundHandlerAdapter { + + private static final Logger LOGGER = LoggerFactory.getLogger(DelegatingInboundHandler.class); + + private MessageConsumer consumer; + + /** + * Constructs class + creates and sets MessageConsumer + * @param connectionAdapter reference for adapter communicating with upper layers outside library + */ + public DelegatingInboundHandler(MessageConsumer connectionAdapter) { + LOGGER.info("Creating DelegatingInboundHandler"); + consumer = connectionAdapter; + } + + @Override + public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { + consumer.consume((DataObject) msg); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Codec.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Codec.java deleted file mode 100644 index 4e92ad06..00000000 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Codec.java +++ /dev/null @@ -1,109 +0,0 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelInboundHandlerAdapter; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; -import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Transforms OpenFlow Protocol messages to Java messages / objects and takes appropriate - * actions - * - * @author michal.polkorab - */ -public class OF13Codec extends ChannelInboundHandlerAdapter { - - // TODO - fix with enum in API - private static final int MESSAGE_TYPES = 29; - private static final Logger LOGGER = LoggerFactory.getLogger(OF13Codec.class); - - /** - * Constructor of class - */ - public OF13Codec() { - LOGGER.info("Creating OF 1.3 Codec"); - - } - - @Override - public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { - LOGGER.info("Reading frame"); - LOGGER.debug("Received msg is of type: " + msg.getClass().getName()); - ByteBuf bb = (ByteBuf) msg; - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(ByteBufUtils.byteBufToHexString(bb)); - } - - bb.markReaderIndex(); - short type = bb.readUnsignedByte(); - int length = bb.readUnsignedShort(); - long xid = bb.readUnsignedInt(); - bb.resetReaderIndex(); - - if (!checkOFHeader(type, length)) { - bb.discardReadBytes(); - LOGGER.info("Non-OF Protocol message received (discarding)"); - return; - } - - // TODO - change hardcoded version to constant, enum, ... - DeserializationFactory.bufferToMessage(bb, (short) 0x04); - - // TODO - delete this switch case after completing deserialization factory - ByteBuf out = ctx.alloc().buffer(); - switch (type) { - case 0: { - LOGGER.info("OFPT_HELLO received"); - byte[] hello = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; - out.writeBytes(hello); - break; - } - case 1: - LOGGER.info("OFPT_ERROR received"); - break; - case 2: { - LOGGER.info("OFPT_ECHO_REQUEST received"); - byte[] echoReply = new byte[]{0x04, 0x03, 0x00, 0x08}; - out.writeBytes(echoReply); - out.writeInt((int) xid); - // TODO - append original data field - break; - } - case 3: - LOGGER.info("OFPT_ECHO_REPLY received"); - break; - case 5: - LOGGER.info("OFPT_FEATURES_REQUEST received"); - break; - case 6: - LOGGER.info("OFPT_FEATURES_REPLY received"); - break; - default: - LOGGER.info("Received message type: " + type); - break; - } - if (LOGGER.isDebugEnabled()) { - LOGGER.debug(ByteBufUtils.byteBufToHexString(out)); - } - - ctx.writeAndFlush(out); - LOGGER.info("Flushed"); - - int bytesRemaining = bb.readableBytes(); - LOGGER.debug("Skipping unread bytes"); - bb.skipBytes(bytesRemaining); - LOGGER.debug("Discarding read bytes"); - LOGGER.debug("RI: " + bb.readerIndex()); - LOGGER.debug("WI: " + bb.writerIndex()); - - } - - private static boolean checkOFHeader(short type, int length) { - return !((type > MESSAGE_TYPES) || (length < OFFrameDecoder.LENGTH_OF_HEADER)); - } -} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java new file mode 100644 index 00000000..c6c496a4 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Decoder.java @@ -0,0 +1,38 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.core; + +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageDecoder; + +import java.util.List; + +import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializationFactory; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Transforms OpenFlow Protocol messages to POJOs and reverse + * + * @author michal.polkorab + */ +public class OF13Decoder extends MessageToMessageDecoder { + + private static final Logger LOGGER = LoggerFactory.getLogger(OF13Decoder.class); + + /** + * Constructor of class + */ + public OF13Decoder() { + LOGGER.info("Creating OF 1.3 Codec"); + } + + @Override + protected void decode(ChannelHandlerContext ctx, VersionMessageWrapper msg, + List out) throws Exception { + LOGGER.debug("VersionMessageWrapper received"); + DataObject dataObject = DeserializationFactory.bufferToMessage(msg.getMessageBuffer(), + msg.getVersion()); + out.add(dataObject); + } +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java new file mode 100644 index 00000000..8e56cc40 --- /dev/null +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OF13Encoder.java @@ -0,0 +1,25 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.core; + +import org.opendaylight.openflowjava.protocol.impl.serialization.SerializationFactory; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; + +/** + * @author michal.polkorab + * + */ +public class OF13Encoder extends MessageToByteEncoder { + + @Override + protected void encode(ChannelHandlerContext ctx, OfHeader msg, ByteBuf out) + throws Exception { + SerializationFactory.messageToBuffer(msg.getVersion(), out, msg); + ctx.writeAndFlush(out); + + } + +} diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java index 650fe3b5..410ca68b 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoder.java @@ -66,7 +66,8 @@ public class OFFrameDecoder extends ByteToMessageDecoder { private static void enableOFVersionDetector(ChannelHandlerContext ctx) { if (ctx.pipeline().get(COMPONENT_NAMES.OF_VERSION_DETECTOR.name()) == null) { LOGGER.info("Adding OFVD"); - ctx.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector()); + ctx.pipeline().addAfter(COMPONENT_NAMES.OF_FRAME_DECODER.name(), + COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector()); } else { LOGGER.debug("OFVD already in pipeline"); } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java index 8ad45260..6999b574 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetector.java @@ -44,24 +44,38 @@ public class OFVersionDetector extends ByteToMessageDecoder { if (version == OF13_VERSION_ID) { LOGGER.debug("detected version: " + version); - enableOF13Codec(chc); + enableOF13Decoder(chc); + enableOF13Encoder(chc); } else { LOGGER.warn("detected version: " + version + " - currently not supported"); return; } ByteBuf messageBuffer = bb.slice(); - list.add(messageBuffer); + list.add(new VersionMessageWrapper(version, messageBuffer)); messageBuffer.retain(); bb.skipBytes(bb.readableBytes()); } - private static void enableOF13Codec(ChannelHandlerContext chc) { - if (chc.pipeline().get(COMPONENT_NAMES.OF_CODEC.name()) == null) { - LOGGER.info("Engaging OF13Codec"); - chc.pipeline().addLast(COMPONENT_NAMES.OF_CODEC.name(), new OF13Codec()); + private static void enableOF13Encoder(ChannelHandlerContext chc) { + if (chc.pipeline().get(COMPONENT_NAMES.OF_ENCODER.name()) == null) { + LOGGER.info("Engaging OF13Encoder"); + chc.pipeline().addBefore(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), + COMPONENT_NAMES.OF_ENCODER.name(), new OF13Encoder()); } else { - LOGGER.debug("OF13Codec already in pipeline"); + LOGGER.debug("OF13Encoder already in pipeline"); } + + } + + private static void enableOF13Decoder(ChannelHandlerContext chc) { + if (chc.pipeline().get(COMPONENT_NAMES.OF_DECODER.name()) == null) { + LOGGER.info("Engaging OF13Decoder"); + chc.pipeline().addBefore(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER.name(), + COMPONENT_NAMES.OF_DECODER.name(), new OF13Decoder()); + } else { + LOGGER.debug("OF13Decoder already in pipeline"); + } + } } diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java index 5f339fda..27ecc2c5 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/core/PublishingChannelInitializer.java @@ -8,6 +8,7 @@ import io.netty.channel.socket.SocketChannel; import java.util.Iterator; import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; +import org.opendaylight.openflowjava.protocol.impl.connection.CommunicationFacade; import org.opendaylight.openflowjava.protocol.impl.connection.ConnectionAdapterFactory; import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; @@ -29,14 +30,15 @@ public class PublishingChannelInitializer extends ChannelInitializer 0)); rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER); - mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array()); + //mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array()); return mrmb.build(); } diff --git a/openflow-protocol-impl/src/main/resources/log4j.xml b/openflow-protocol-impl/src/main/resources/log4j.xml index 0f4e26cd..5c5c7d9f 100644 --- a/openflow-protocol-impl/src/main/resources/log4j.xml +++ b/openflow-protocol-impl/src/main/resources/log4j.xml @@ -8,11 +8,11 @@ - + - + diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java index a7318957..bc1bbb79 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClient.java @@ -1,4 +1,4 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ + /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ package org.opendaylight.openflowjava.protocol.impl.clients; import io.netty.bootstrap.Bootstrap; @@ -18,6 +18,7 @@ import java.io.InputStreamReader; import java.net.InetAddress; import java.nio.charset.Charset; +import org.opendaylight.openflowjava.protocol.impl.integration.IntegrationTest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -97,7 +98,7 @@ public class SimpleClient extends Thread { byte[] bytearray = new byte[64]; ByteBuf buffy = ch.alloc().buffer(128); - LOGGER.debug("Before fis != null " + fis); + LOGGER.debug("Before fis != null - fis == " + fis); if (fis != null) { try { LOGGER.debug("Size to read (in bytes) : " + fis.available()); @@ -168,7 +169,8 @@ public class SimpleClient extends Thread { InetAddress[] all = InetAddress.getAllByName(ia.getHostName()); host = all[0].getHostAddress(); port = 6633; - InputStream filenamearg = SimpleClient.class.getResourceAsStream("/org/openflow/core/OFBinaryMessageInput.txt"); + InputStream filenamearg = IntegrationTest.class.getResourceAsStream( + IntegrationTest.OF_BINARY_MESSAGE_INPUT_TXT); sc = new SimpleClient(host, port, filenamearg); sc.setSecuredClient(true); } else { diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java index fa2dbf96..b2e86a46 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/clients/SimpleClientHandler.java @@ -19,22 +19,18 @@ import com.google.common.util.concurrent.SettableFuture; public class SimpleClientHandler extends ChannelInboundHandlerAdapter { private static final Logger LOGGER = LoggerFactory.getLogger(SimpleClientHandler.class); - private SettableFuture sf; + private SettableFuture isOnlineFuture; /** - * @param sf future notifier of connected channel + * @param isOnlineFuture future notifier of connected channel */ - public SimpleClientHandler(SettableFuture sf) { - this.sf = sf; + public SimpleClientHandler(SettableFuture isOnlineFuture) { + this.isOnlineFuture = isOnlineFuture; } @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { LOGGER.info("SimpleClientHandler - start of read"); - if (sf != null) { - sf.set(true); - sf = null; - } ByteBuf bb = (ByteBuf) msg; if (LOGGER.isDebugEnabled()) { LOGGER.debug(ByteBufUtils.byteBufToHexString(bb)); @@ -49,7 +45,10 @@ public class SimpleClientHandler extends ChannelInboundHandlerAdapter { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { System.out.println("CLIENT IS ACTIVE"); - //super.channelActive(ctx); + if (isOnlineFuture != null) { + isOnlineFuture.set(true); + isOnlineFuture = null; + } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java index 6ad32adb..85cd1c5e 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFFrameDecoderTest.java @@ -2,90 +2,139 @@ package org.opendaylight.openflowjava.protocol.impl.core; import io.netty.buffer.ByteBuf; -import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; + +import java.util.ArrayList; +import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; + +import com.google.common.collect.Lists; /** * Testing class of {@link OFFrameDecoder} + * * @author michal.polkorab */ +@RunWith(MockitoJUnitRunner.class) public class OFFrameDecoderTest { - private EmbeddedChannel embch; + @Mock + ChannelHandlerContext channelHandlerContext; + + @Mock + ChannelPipeline channelPipeline; + + private OFFrameDecoder decoder; + private List list = new ArrayList<>(); /** - * Sets up test environment + * Sets up tests */ @Before public void setUp() { - embch = new EmbeddedChannel(new OFFrameDecoder()); + Mockito.when(channelHandlerContext.pipeline()).thenReturn( + channelPipeline); + Mockito.when(channelPipeline.get(Matchers.anyString())) + .thenReturn(null); + Mockito.when(channelPipeline.names()).thenReturn( + Lists.newArrayList("xx")); + list.clear(); + decoder = new OFFrameDecoder(); } /** - * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * @throws Exception + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception */ @Test public void testDecode8BMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), + list); - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertEquals(8, inObj.readableBytes()); + Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); + verifyMockCalls(1); } /** - * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * @throws Exception + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception */ @Test public void testDecode16BMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x04, 0x00, - 0x00, 0x08, 0x00, 0x00, 0x00, 0x01}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); - - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertEquals(16, inObj.readableBytes()); + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 10 00 00 00 00 00 00 00 00 00 00 00 42"), + list); + + Assert.assertEquals(16, ((ByteBuf) list.get(0)).readableBytes()); + verifyMockCalls(1); } /** - * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * @throws Exception + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception */ @Test public void testDecodeIncompleteMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00"), + list); - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertNull(inObj); + Assert.assertEquals("List is not empty", 0, list.size()); + verifyMockCalls(0); } /** - * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} - * @throws Exception + * Test of decoding + * {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)} + * + * @throws Exception */ @Test public void testDecodeCompleteAndPartialMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, - 0x04, 0x00, 0x00, 0x08, 0x00}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); - - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertEquals(8, inObj.readableBytes()); - inObj = (ByteBuf) embch.readInbound(); - Assert.assertNull(inObj); + decoder.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01 04 00 00 08 00"), + list); + + Assert.assertEquals(8, ((ByteBuf) list.get(0)).readableBytes()); + Assert.assertEquals(1, list.size()); + verifyMockCalls(1); + } + + private void verifyMockCalls(int numberOfCalls) { + if (numberOfCalls > 0) { + Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)).get( + COMPONENT_NAMES.OF_VERSION_DETECTOR.name()); + Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)).addAfter( + Matchers.eq(COMPONENT_NAMES.OF_FRAME_DECODER.name()), + Matchers.eq(COMPONENT_NAMES.OF_VERSION_DETECTOR.name()), + Matchers.isA(OFVersionDetector.class)); + Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)).names(); + } else { + Mockito.verify(channelPipeline, Mockito.never()).get( + COMPONENT_NAMES.OF_VERSION_DETECTOR.name()); + Mockito.verify(channelPipeline, Mockito.never()).addAfter( + Matchers.eq(COMPONENT_NAMES.OF_FRAME_DECODER.name()), + Matchers.eq(COMPONENT_NAMES.OF_VERSION_DETECTOR.name()), + Matchers.isA(OFVersionDetector.class)); + Mockito.verify(channelPipeline, Mockito.never()).names(); + } } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java index 8bf4907a..6f549334 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/OFVersionDetectorTest.java @@ -1,62 +1,105 @@ /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ package org.opendaylight.openflowjava.protocol.impl.core; -import io.netty.buffer.ByteBuf; -import io.netty.channel.embedded.EmbeddedChannel; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.ChannelPipeline; + +import java.util.ArrayList; +import java.util.List; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler.COMPONENT_NAMES; +import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils; /** - * + * * @author michal.polkorab */ +@RunWith(MockitoJUnitRunner.class) public class OFVersionDetectorTest { - private EmbeddedChannel embch; + @Mock + ChannelHandlerContext channelHandlerContext; + + @Mock + ChannelPipeline channelPipeline; + + private OFVersionDetector detector; + private List list = new ArrayList<>(); /** * Sets up test environment */ @Before public void setUp() { - embch = new EmbeddedChannel(new OFVersionDetector()); + Mockito.when(channelHandlerContext.pipeline()).thenReturn( + channelPipeline); + Mockito.when(channelPipeline.get(Matchers.anyString())) + .thenReturn(null); + list.clear(); + detector = new OFVersionDetector(); } /** - * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) + * Test of decode + * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) * } - * @throws Exception + * + * @throws Exception */ @Test public void testDecode13ProtocolMessage() throws Exception { - byte[] msgs = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); - - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertEquals(7, inObj.readableBytes()); - Assert.assertNotNull(embch.pipeline().get(COMPONENT_NAMES.OF_CODEC.name())); + detector.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("04 00 00 08 00 00 00 01"), + list); + + Assert.assertEquals(7, ((VersionMessageWrapper) list.get(0)) + .getMessageBuffer().readableBytes()); + verifyMockCalls(1); } - + /** - * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) + * Test of decode + * {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) * } - * @throws Exception + * + * @throws Exception */ @Test public void testDecodeNotSupportedVersionProtocolMessage() throws Exception { - byte[] msgs = new byte[]{0x01, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01}; - ByteBuf writeObj = embch.alloc().buffer(64); - writeObj.writeBytes(msgs); - embch.writeInbound(writeObj); - - ByteBuf inObj = (ByteBuf) embch.readInbound(); - Assert.assertNull(inObj); - Assert.assertNull(embch.pipeline().get(COMPONENT_NAMES.OF_CODEC.name())); + detector.decode(channelHandlerContext, + ByteBufUtils.hexStringToByteBuf("01 00 00 08 00 00 00 01"), + list); + + Assert.assertEquals("List is not empty", 0, list.size()); + verifyMockCalls(0); + } + + private void verifyMockCalls(int numberOfCalls) { + if (numberOfCalls > 0) { + Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)).get( + COMPONENT_NAMES.OF_DECODER.name()); + Mockito.verify(channelPipeline, Mockito.times(numberOfCalls)) + .addBefore( + Matchers.eq(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER + .name()), + Matchers.eq(COMPONENT_NAMES.OF_DECODER.name()), + Matchers.isA(OF13Decoder.class)); + } else { + Mockito.verify(channelPipeline, Mockito.never()).get( + COMPONENT_NAMES.OF_DECODER.name()); + Mockito.verify(channelPipeline, Mockito.never()).addBefore( + Matchers.eq(COMPONENT_NAMES.DELEGATING_INBOUND_HANDLER + .name()), + Matchers.eq(COMPONENT_NAMES.OF_DECODER.name()), + Matchers.isA(OF13Decoder.class)); + } } } \ No newline at end of file diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandlerTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandlerTest.java deleted file mode 100644 index f06f0804..00000000 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/core/TcpHandlerTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.core; - -import io.netty.channel.Channel; -import io.netty.util.concurrent.Future; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.openflowjava.protocol.impl.clients.SimpleClient; -import org.opendaylight.openflowjava.protocol.impl.core.PublishingChannelInitializer; -import org.opendaylight.openflowjava.protocol.impl.core.TcpHandler; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * @author michal.polkorab - */ -public class TcpHandlerTest { - - /** Name of file in which OpenFLow protocol messages are stored in binary format */ - private static final String OF_BINARY_MESSAGE_INPUT_TXT = "OFBinaryMessageInput.txt"; - - protected static final Logger LOGGER = LoggerFactory - .getLogger(TcpHandlerTest.class); - - private static final long CONNECTION_TIMEOUT = 2000; - - protected int port; - protected String address; - protected TcpHandler tcphandler; - - /** - * @throws InterruptedException - * @throws ExecutionException - */ - @Before - public void setUp() throws InterruptedException, ExecutionException { - tcphandler = new TcpHandler(0); - new Thread(tcphandler).start(); - tcphandler.getIsOnlineFuture().get(); - port = tcphandler.getPort(); - address = tcphandler.getAddress(); - } - - /** - * stop {@link TcpHandler} - * @throws ExecutionException - * @throws InterruptedException - */ - @After - public void tearDown() throws InterruptedException, ExecutionException { - tcphandler.shutdown().get(); - } - - /** - * Test of connections in {@link TcpHandler} - accepting connection of 1 - * client - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testConnectOneClient() throws InterruptedException, ExecutionException { - int amountOfCLients = 1; - createAndStartClient(amountOfCLients); - int actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(amountOfCLients, actualConnections); - PublishingChannelInitializer channelInitializer = tcphandler.getChannelInitializer(); - for (Iterator iterator = channelInitializer.getConnectionIterator(); iterator.hasNext();) { - Channel channel = iterator.next(); - try { - channel.close().sync(); - } catch (InterruptedException e) { - LOGGER.error(e.getMessage(), e); - } - } - actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(0, actualConnections); - } - - /** - * Test of connections in {@link TcpHandler} - accepting connection of 10 - * clients - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testConnectTenClients() throws InterruptedException, ExecutionException { - int amountOfCLients = 10; - createAndStartClient(amountOfCLients); - int actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(amountOfCLients, actualConnections); - PublishingChannelInitializer channelInitializer = tcphandler.getChannelInitializer(); - for (Iterator iterator = channelInitializer.getConnectionIterator(); iterator.hasNext();) { - Channel channel = iterator.next(); - try { - channel.close().sync(); - } catch (InterruptedException e) { - LOGGER.error(e.getMessage(), e); - } - } - actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(0, actualConnections); - } - - /** - * Test of disconnecting in {@link TcpHandler} - shutting down connection of 10 - * clients - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testDisconnectTenClients() throws InterruptedException, ExecutionException { - int amountOfCLients = 10; - List clients = createAndStartClient(amountOfCLients); - int actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(amountOfCLients, actualConnections); - - disconnectClients(clients); - - actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(0, actualConnections); - } - - /** - * @param amountOfCLients - * @return new clients up and running - * @throws InterruptedException - * @throws ExecutionException - */ - private List createAndStartClient(int amountOfCLients) - throws InterruptedException, ExecutionException { - List clientsHorde = new ArrayList<>(); - for (int i = 0; i < amountOfCLients; i++) { - SimpleClient sc = new SimpleClient(address, port, getClass().getResourceAsStream( - OF_BINARY_MESSAGE_INPUT_TXT)); - sc.setSecuredClient(true); - 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; - } - - /** - * Test of disconnecting in {@link TcpHandler} - shutting down connection of 1 - * client - * @throws InterruptedException - * @throws ExecutionException - */ - @Test - public void testDisconnectOneClient() throws InterruptedException, ExecutionException { - int amountOfCLients = 1; - List clients = createAndStartClient(amountOfCLients); - int actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(amountOfCLients, actualConnections); - disconnectClients(clients); - actualConnections = tcphandler.getNumberOfConnections(); - Assert.assertEquals(0, actualConnections); - } - - /** - * @param clients - * @throws InterruptedException - */ - private static void disconnectClients(List clients) throws InterruptedException { - List> disconnectFutureBag = new ArrayList<>(); - for (SimpleClient simpleClient : clients) { - disconnectFutureBag.add(simpleClient.disconnect()); - } - for (Future toBeDisconnected : disconnectFutureBag) { - toBeDisconnected.sync(); - } - } -} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java index ed93d7ac..e4e12eb2 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java @@ -25,7 +25,7 @@ public class MultipartReplyMessageFactoryTest { BufferHelper.checkHeaderV13(builtByFactory); Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE()); - Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody()); + //Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody()); } } diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java new file mode 100644 index 00000000..363dede6 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/IntegrationTest.java @@ -0,0 +1,107 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +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.SimpleClient; +import org.opendaylight.openflowjava.protocol.impl.connection.SwitchConnectionProviderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * + */ +public class IntegrationTest { + + /** Name of file in which OpenFLow protocol messages are stored in binary format */ + public static final String OF_BINARY_MESSAGE_INPUT_TXT = "OFBinaryMessageInput.txt"; + private static final int DEFAULT_PORT = 6633; + private static final FEATURE_SUPPORT DEFAULT_TLS_SUPPORT = FEATURE_SUPPORT.NOT_SUPPORTED; + + protected static final Logger LOGGER = LoggerFactory + .getLogger(IntegrationTest.class); + + private static final long CONNECTION_TIMEOUT = 2000; + + private InetAddress startupAddress; + private MockPlugin dummyPlugin; + + /** + * @throws UnknownHostException + */ + @Before + public void setUp() throws UnknownHostException { + startupAddress = InetAddress.getLocalHost(); + } + + /** + * Library integration and communication test + * @throws Exception + */ + @Test + public void testCommunication() throws Exception { + dummyPlugin = new MockPlugin(); + SwitchConnectionProviderImpl scpimpl = new SwitchConnectionProviderImpl(); + List configs = new ArrayList<>(); + configs.add(new TestingConnConfigImpl(startupAddress, DEFAULT_PORT, DEFAULT_TLS_SUPPORT)); + scpimpl.configure(configs); + scpimpl.setSwitchConnectionHandler(dummyPlugin); + scpimpl.startup().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); + int amountOfCLients = 1; + List clients = createAndStartClient(amountOfCLients); + Thread.sleep(2000); + } + + /** + * @param amountOfCLients + * @return new clients up and running + * @throws InterruptedException + * @throws ExecutionException + */ + private List createAndStartClient(int amountOfCLients) + throws InterruptedException, 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(), DEFAULT_PORT, + getClass().getResourceAsStream(OF_BINARY_MESSAGE_INPUT_TXT)); + sc.setSecuredClient(false); + 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; + } + + /** + * @param clients + * @throws InterruptedException + */ + private static void disconnectClients(List clients) throws InterruptedException { + List> disconnectFutureBag = new ArrayList<>(); + for (SimpleClient simpleClient : clients) { + disconnectFutureBag.add(simpleClient.disconnect()); + } + for (io.netty.util.concurrent.Future toBeDisconnected : disconnectFutureBag) { + toBeDisconnected.sync(); + } + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java new file mode 100644 index 00000000..d23051c8 --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/MockPlugin.java @@ -0,0 +1,107 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; +import org.opendaylight.openflowjava.protocol.api.connection.SwitchConnectionHandler; +import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartRequestMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OpenflowProtocolListener; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author michal.polkorab + * + */ +public class MockPlugin implements OpenflowProtocolListener, SwitchConnectionHandler { + + private static final Logger LOGGER = LoggerFactory.getLogger(MockPlugin.class); + private ConnectionAdapter adapter; + + + @Override + public void onSwitchConnected(ConnectionAdapter connection) { + LOGGER.debug("onSwitchCnnected"); + this.adapter = connection; + } + + @Override + public boolean accept(InetAddress switchAddress) { + // TODO Auto-generated method stub + return true; + } + + @Override + public void onEchoRequestMessage(EchoRequestMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onErrorMessage(ErrorMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onExperimenterMessage(ExperimenterMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onFlowRemovedMessage(FlowRemovedMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onHelloMessage(HelloMessage notification) { + LOGGER.debug("Hello message received"); + HelloInputBuilder hib = new HelloInputBuilder(); + try { + BufferHelper.setupHeader(hib); + } catch (Exception e) { + LOGGER.error(e.getMessage(), e); + } + HelloInput hi = hib.build(); + adapter.hello(hi); + } + + @Override + public void onMultipartReplyMessage(MultipartReplyMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onMultipartRequestMessage(MultipartRequestMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onPacketInMessage(PacketInMessage notification) { + // TODO Auto-generated method stub + + } + + @Override + public void onPortStatusMessage(PortStatusMessage notification) { + // TODO Auto-generated method stub + + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java new file mode 100644 index 00000000..9992e5be --- /dev/null +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/integration/TestingConnConfigImpl.java @@ -0,0 +1,46 @@ +/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ +package org.opendaylight.openflowjava.protocol.impl.integration; + +import java.net.InetAddress; + +import org.opendaylight.openflowjava.protocol.api.connection.ConnectionConfiguration; + +/** + * @author michal.polkorab + * + */ +public class TestingConnConfigImpl implements ConnectionConfiguration{ + + private InetAddress address; + private int port; + private Object transferProtocol; + private FEATURE_SUPPORT tlsSupport; + + // TODO - implement transferProtocol + public TestingConnConfigImpl(InetAddress address, int port, FEATURE_SUPPORT tlsSupport) { + this.address = address; + this.port = port; + this.tlsSupport = tlsSupport; + } + + @Override + public InetAddress getAddress() { + return address; + } + + @Override + public int getPort() { + return port; + } + + @Override + public Object getTransferProtocol() { + return transferProtocol; + } + + @Override + public FEATURE_SUPPORT getTlsSupport() { + return tlsSupport; + } + +} diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java index 37b6d676..d8f59f81 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class BarrierInputMessageFactoryTest { - private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = 20; + private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = BarrierInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java index 2dc4aa16..bfeb53ba 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoInputMessageFactoryTest { - private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2; + private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = EchoInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link EchoInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java index 01b8047c..b1475434 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class EchoReplyInputMessageFactoryTest { - private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = 3; + private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = EchoReplyInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java index f2236e65..48649e80 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetConfigInputMessageFactoryTest { - private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7; + private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = GetConfigInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java index 3153b0dd..c90b0afb 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java @@ -16,7 +16,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731 */ public class GetFeaturesInputMessageFactoryTest { - private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = 5; + private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = GetFeaturesInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java index 49cfcbf4..edbb636b 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java @@ -23,7 +23,7 @@ import com.google.common.collect.Lists; */ public class HelloInputMessageFactoryTest { - private static final byte HELLO_MESSAGE_CODE_TYPE = 0; + private static final byte HELLO_MESSAGE_CODE_TYPE = HelloInputMessageFactory.MESSAGE_TYPE; /** * Testing of {@link HelloInputMessageFactory} for correct translation from POJO diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java index c8c62dfd..e06e8a61 100644 --- a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java +++ b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java @@ -60,10 +60,8 @@ public abstract class BufferHelper { /** * Use version 1.3 for encoded message - * @param input - * ByteBuf to be checked for correct OpenFlow Protocol header - * @param msgType - * type of received message + * @param input ByteBuf to be checked for correct OpenFlow Protocol header + * @param msgType type of received message * @param length TODO */ public static void checkHeaderV13(ByteBuf input, byte msgType, int length) { diff --git a/openflow-protocol-impl/src/test/resources/org/opendaylight/openflowjava/protocol/impl/core/OFBinaryMessageInput.txt b/openflow-protocol-impl/src/test/resources/org/opendaylight/openflowjava/protocol/impl/integration/OFBinaryMessageInput.txt similarity index 100% rename from openflow-protocol-impl/src/test/resources/org/opendaylight/openflowjava/protocol/impl/core/OFBinaryMessageInput.txt rename to openflow-protocol-impl/src/test/resources/org/opendaylight/openflowjava/protocol/impl/integration/OFBinaryMessageInput.txt diff --git a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java index 2d1a16ca..c6e509e3 100644 --- a/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java +++ b/openflow-protocol-spi/src/main/java/org/opendaylight/openflowjava/protocol/spi/connection/SwitchConnectionProvider.java @@ -28,7 +28,7 @@ public interface SwitchConnectionProvider { /** * start listening to switches, but please don't forget to do - * {@link #setSwitchConnectionListener(SwitchConnectionHandler)} first + * {@link #setSwitchConnectionHandler(SwitchConnectionHandler)} first * @return future, triggered to true, when all listening channels are up and running */ public Future> startup(); @@ -40,8 +40,8 @@ public interface SwitchConnectionProvider { public Future shutdown(); /** - * @param switchConListener instance being informed when new switch connects + * @param switchConHandler instance being informed when new switch connects */ - public void setSwitchConnectionListener(SwitchConnectionHandler switchConListener); + public void setSwitchConnectionHandler(SwitchConnectionHandler switchConHandler); } -- 2.36.6