Added more (de)serialization factories + ByteBufUtils methods 96/1196/3
authormichal.polkorab <michal.polkorab@pantheon.sk>
Mon, 16 Sep 2013 11:36:22 +0000 (13:36 +0200)
committermichal.polkorab <michal.polkorab@pantheon.sk>
Tue, 17 Sep 2013 10:12:00 +0000 (12:12 +0200)
Mantaining code - extracting methods in tests

Signed-off-by: michal.polkorab <michal.polkorab@pantheon.sk>
Change-Id: I07fdf59fa2602bc78630b8b0946381c3f3e146fe

32 files changed:
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtils.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/BarrierReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/EchoRequestMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ExperimenterMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FeaturesReplyMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/HelloMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/BufferHelper.java
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java [new file with mode: 0644]

index 691041eafd22f1c980ddbd332a181614014f4630..e4122ac4e677d75ec3529327f9157390a2533368 100644 (file)
@@ -39,7 +39,9 @@ private static ErrorMessageFactory instance;
         // TODO - finish implementation after enums are generated with proper funcionality\r
         //emb.setType();\r
         emb.setCode(rawMessage.readInt());\r
-        //emb.setData(value);\r
+        byte[] data = new byte[rawMessage.readableBytes()];\r
+        rawMessage.readBytes(data);\r
+        emb.setData(data);\r
         return emb.build();\r
     }\r
 \r
index a33c8092d9fba09c68498a2cac1c962dcba9fd6f..cb111cff0eb919867185d9f041c32804768fe10b 100644 (file)
@@ -46,7 +46,6 @@ public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOu
         byte[] datapathId = new byte[8];\r
         rawMessage.readBytes(datapathId);\r
         gfob.setDatapathId(new BigInteger(datapathId));\r
-        \r
         gfob.setBuffers(rawMessage.readUnsignedInt());\r
         gfob.setTables(rawMessage.readUnsignedByte());\r
         gfob.setAuxiliaryId(rawMessage.readUnsignedByte());\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactory.java
new file mode 100644 (file)
index 0000000..e014748
--- /dev/null
@@ -0,0 +1,68 @@
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.math.BigInteger;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class FlowRemovedMessageFactory implements OFDeserializer<FlowRemovedMessage> {\r
+    \r
+    private static FlowRemovedMessageFactory instance;\r
+    \r
+    private FlowRemovedMessageFactory() {\r
+        // singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static FlowRemovedMessageFactory getInstance(){\r
+        if(instance == null){\r
+            instance = new FlowRemovedMessageFactory();\r
+        }\r
+        \r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public FlowRemovedMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        FlowRemovedMessageBuilder frmb = new FlowRemovedMessageBuilder();\r
+        \r
+        frmb.setVersion(version);\r
+        frmb.setXid(rawMessage.readUnsignedInt());\r
+        \r
+        byte[] cookie = new byte[8];\r
+        rawMessage.readBytes(cookie);\r
+        frmb.setCookie(new BigInteger(cookie));\r
+        frmb.setPriority(rawMessage.readUnsignedShort());\r
+        \r
+//        TODO enum! \r
+//        frmb.setReason(FlowRemovedReason.values()[rawMessage.readInt()]);\r
+        rawMessage.skipBytes(1); //instead of setReason\r
+        \r
+        frmb.setTableId(new TableId((long)rawMessage.readUnsignedByte()));\r
+        frmb.setDurationSec(rawMessage.readUnsignedInt());\r
+        frmb.setDurationNsec(rawMessage.readUnsignedInt());\r
+        frmb.setIdleTimeout(rawMessage.readUnsignedShort());\r
+        frmb.setHardTimeout(rawMessage.readUnsignedShort());\r
+        \r
+        byte[] packet_count = new byte[8];\r
+        rawMessage.readBytes(packet_count);\r
+        frmb.setPacketCount(new BigInteger(packet_count));\r
+        \r
+        byte[] byte_count = new byte[8];\r
+        rawMessage.readBytes(byte_count);\r
+        frmb.setByteCount(new BigInteger(byte_count));\r
+        \r
+        return frmb.build();\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactory.java
new file mode 100644 (file)
index 0000000..8d54899
--- /dev/null
@@ -0,0 +1,44 @@
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class GetConfigReplyMessageFactory implements OFDeserializer<GetConfigOutput> {\r
+\r
+    private static GetConfigReplyMessageFactory instance;\r
+    \r
+    private GetConfigReplyMessageFactory() {\r
+        // singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static GetConfigReplyMessageFactory getInstance(){\r
+        if(instance == null){\r
+            instance = new GetConfigReplyMessageFactory();\r
+        }\r
+        \r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public GetConfigOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
+        GetConfigOutputBuilder gcob = new GetConfigOutputBuilder();\r
+        gcob.setVersion(version);\r
+        gcob.setXid(rawMessage.readUnsignedInt());\r
+        // TODO - waiting for enum funcionality\r
+//        gcob.setFlags(SwitchConfigFlag.values()[rawMessage.readInt()]);\r
+        gcob.setMissSendLen(rawMessage.readUnsignedShort());\r
+        return gcob.build();\r
+    }\r
+    \r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/MultipartReplyMessageFactory.java
new file mode 100644 (file)
index 0000000..d43b83c
--- /dev/null
@@ -0,0 +1,52 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartRequestFlags;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessageBuilder;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class MultipartReplyMessageFactory implements OFDeserializer<MultipartReplyMessage> {\r
+\r
+    private static MultipartReplyMessageFactory instance;\r
+    private static final byte PADDING_IN_MULTIPART_REPLY_HEADER = 4;\r
+    \r
+    private MultipartReplyMessageFactory() {\r
+        // singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static MultipartReplyMessageFactory getInstance(){\r
+        if (instance == null){\r
+\r
+            instance = new MultipartReplyMessageFactory();\r
+        }\r
+        \r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public MultipartReplyMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        MultipartReplyMessageBuilder mrmb = new MultipartReplyMessageBuilder();\r
+        mrmb.setVersion(version);\r
+        mrmb.setXid(rawMessage.readUnsignedInt());\r
+        \r
+//        TODO enum MultipartType\r
+//        mrmb.setType(MultipartType.values()[rawMessage.readInt()]);\r
+        rawMessage.skipBytes(2); //instead of enum\r
+        \r
+        mrmb.setFlags(new MultipartRequestFlags((rawMessage.readUnsignedShort() & 0x01) > 0));\r
+        rawMessage.skipBytes(PADDING_IN_MULTIPART_REPLY_HEADER);\r
+        mrmb.setBody(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+        \r
+        return mrmb.build();\r
+    } \r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactory.java
new file mode 100644 (file)
index 0000000..a8733af
--- /dev/null
@@ -0,0 +1,56 @@
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.math.BigInteger;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class PacketInMessageFactory implements OFDeserializer<PacketInMessage> {\r
+\r
+    private static PacketInMessageFactory instance;\r
+    private static final byte PADDING_IN_PACKET_IN_HEADER = 2;\r
+    \r
+    private PacketInMessageFactory() {\r
+        // Singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static PacketInMessageFactory getInstance(){\r
+        if(instance == null){\r
+            instance = new PacketInMessageFactory();\r
+        }\r
+        \r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public PacketInMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        PacketInMessageBuilder pimb = new PacketInMessageBuilder();\r
+        pimb.setVersion(version);\r
+        pimb.setXid(rawMessage.readUnsignedInt());\r
+        pimb.setBufferId(rawMessage.readUnsignedInt());\r
+        pimb.setTotalLen(rawMessage.readUnsignedShort());\r
+        pimb.setReason(rawMessage.readUnsignedByte());\r
+        pimb.setTableId(new TableId((long)rawMessage.readUnsignedByte()));\r
+        \r
+        byte[] cookie = new byte[8];\r
+        rawMessage.readBytes(cookie);\r
+        pimb.setCookie(new BigInteger(cookie));\r
+        // TODO - implement match factories to finish this factory \r
+        rawMessage.skipBytes(PADDING_IN_PACKET_IN_HEADER);\r
+        \r
+        pimb.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+        \r
+        return pimb.build();\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactory.java
new file mode 100644 (file)
index 0000000..7918333
--- /dev/null
@@ -0,0 +1,50 @@
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class PortStatusMessageFactory implements OFDeserializer<PortStatusMessage> {\r
+\r
+    private static PortStatusMessageFactory instance;\r
+    private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 7;\r
+    \r
+    private PortStatusMessageFactory() {\r
+        // Singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static PortStatusMessageFactory getInstance(){\r
+        if(instance == null){\r
+            \r
+            instance = new PortStatusMessageFactory();\r
+        }\r
+        \r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public PortStatusMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        PortStatusMessageBuilder psmb = new PortStatusMessageBuilder(); \r
+        psmb.setVersion(version);\r
+        psmb.setXid(rawMessage.readUnsignedInt());\r
+   \r
+//        TODO enum portReason\r
+//        psmb.setReason(PortReason.values()[rawMessage.readInt()]);\r
+        rawMessage.skipBytes(1); //instead of portReason enum\r
+        \r
+        rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
+        return psmb.build();\r
+    }\r
+\r
+    \r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactory.java
new file mode 100644 (file)
index 0000000..fde8713
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ExperimenterInputMessageFactory implements OFSerializer<ExperimenterInput>{\r
+\r
+    /** Code type of Experimenter message */\r
+    public static final byte MESSAGE_TYPE = 4;\r
+    private static ExperimenterInputMessageFactory instance;\r
+    \r
+    private ExperimenterInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static ExperimenterInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new ExperimenterInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            ExperimenterInput message) {\r
+        out.writeByte(message.getVersion());\r
+        out.writeByte(MESSAGE_TYPE);\r
+        out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER + (Integer.SIZE/Byte.SIZE)*2);\r
+        out.writeInt(message.getXid().intValue());\r
+        out.writeInt(message.getExperimenter().intValue());\r
+        out.writeInt(message.getExpType().intValue());\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/PacketOutInputMessageFactory.java
new file mode 100644 (file)
index 0000000..9a16738
--- /dev/null
@@ -0,0 +1,51 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketOutInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class PacketOutInputMessageFactory implements OFSerializer<PacketOutInput>{\r
+\r
+    /** Code type of PacketOut message */\r
+    public static final byte MESSAGE_TYPE = 13;\r
+    private static final byte PADDING_IN_PACKET_OUT_MESSAGE = 6;\r
+    private static PacketOutInputMessageFactory instance;\r
+    \r
+    private PacketOutInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static PacketOutInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new PacketOutInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            PacketOutInput message) {\r
+        out.writeByte(message.getVersion());\r
+        out.writeByte(MESSAGE_TYPE);\r
+        out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
+        out.writeInt(message.getXid().intValue());\r
+        out.writeInt(message.getBufferId().intValue());\r
+        out.writeInt(message.getInPort().getValue().intValue());\r
+        // TODO - finish implementation after Action serialization is done\r
+        //out.writeShort(message.getActions().size());\r
+        ByteBufUtils.padBuffer(PADDING_IN_PACKET_OUT_MESSAGE, out);\r
+       \r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/RoleRequestInputMessageFactory.java
new file mode 100644 (file)
index 0000000..8789d7a
--- /dev/null
@@ -0,0 +1,49 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class RoleRequestInputMessageFactory implements OFSerializer<RoleRequestInput> {\r
+\r
+    /** Code type of RoleRequest message */\r
+    public static final byte MESSAGE_TYPE = 24;\r
+    private static final byte PADDING_IN_ROLE_REQUEST_MESSAGE = 4;\r
+    private static RoleRequestInputMessageFactory instance;\r
+    \r
+    private RoleRequestInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static RoleRequestInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new RoleRequestInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            RoleRequestInput message) {\r
+        out.writeByte(message.getVersion());\r
+        out.writeByte(MESSAGE_TYPE);\r
+        out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
+        out.writeInt(message.getXid().intValue());\r
+        // TODO - finish implementation after enum support needed funcionality\r
+        //out.writeInt(message.getRole());\r
+        ByteBufUtils.padBuffer(PADDING_IN_ROLE_REQUEST_MESSAGE, out);\r
+        out.writeLong(message.getGenerationId().longValue());\r
+    }\r
+\r
+}\r
index 130cd85e09601e82c9692d167f22c78c34a6a510..0c6d226571a5fbc96d6403927133b29e29869c54 100644 (file)
@@ -5,9 +5,6 @@ import io.netty.buffer.ByteBuf;
 \r
 import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.SwitchConfigFlag;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsync;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetAsyncMessage;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.SetConfigInput;\r
 \r
 /**\r
@@ -42,7 +39,7 @@ public class SetConfigMessageFactory implements OFSerializer<SetConfigInput> {
         out.writeShort(OFFrameDecoder.LENGTH_OF_HEADER);\r
         out.writeInt(message.getXid().intValue());\r
         // TODO - finish implementation after enums provide needed funcionality\r
-        \r
+        out.writeInt(message.getMissSendLen());\r
     }\r
 \r
 }\r
index b5e01e7917d4348731cc67132cced284f8c9c8d6..3f5e360005dccb1699ecd43f15a70909a29e7817 100644 (file)
@@ -3,6 +3,7 @@
 package org.opendaylight.openflowjava.protocol.impl.util;\r
 \r
 import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
 /** Class for common operations on ByteBuf\r
  *\r
@@ -23,4 +24,49 @@ public abstract class ByteBufUtils {
         }\r
         return sb.toString();\r
     }\r
+    \r
+    /**\r
+     * Converts String into byte[]\r
+     * @param hexSrc input String\r
+     * @return byte[] filled with input data\r
+     */\r
+    public static byte[] hexStringToBytes(String hexSrc) {\r
+        String[] byteChips = hexSrc.split("\\s+");\r
+        byte[] result = new byte[byteChips.length];\r
+        for (int i = 0; i < byteChips.length; i++) {\r
+            result[i] = (byte) Short.parseShort(byteChips[i], 16);\r
+        }\r
+        return result;\r
+    }\r
+    \r
+    /**\r
+     * Creates ByteBuf filled with specified data\r
+     * @param hexSrc input String of bytes in hex format\r
+     * @return ByteBuf with specified hexString converted\r
+     */\r
+    public static ByteBuf hexStringToByteBuf(String hexSrc) {\r
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        hexStringToByteBuf(hexSrc, out);\r
+        return out;\r
+    }\r
+    \r
+    /**\r
+     * Creates ByteBuf filled with specified data\r
+     * @param hexSrc input String of bytes in hex format\r
+     * @param out ByteBuf with specified hexString converted\r
+     */\r
+    public static void hexStringToByteBuf(String hexSrc, ByteBuf out) {\r
+        out.writeBytes(hexStringToBytes(hexSrc));\r
+    }\r
+    \r
+    /**\r
+     * Fills specified ByteBuf with 0 (zeros) of desired length, used for padding\r
+     * @param length\r
+     * @param out ByteBuf to be padded\r
+     */\r
+    public static void padBuffer(int length, ByteBuf out) {\r
+        for (int i = 0; i < length; i++) {\r
+            out.writeByte(0);\r
+        }\r
+    }\r
 }\r
index bbd8af74fec9f2576806d84a6120892806219e0f..d828c85211ad70c97989e5ffae39c22e343c18a5 100644 (file)
@@ -3,9 +3,7 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 \r
 import io.netty.buffer.ByteBuf;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
 \r
@@ -20,10 +18,10 @@ public class BarrierReplyMessageFactoryTest {
      */\r
     @Test\r
     public void test() {\r
-        ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
-        BarrierOutput builtByFactory = BarrierReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer();\r
+        BarrierOutput builtByFactory = BufferHelper.decodeV13(\r
+                BarrierReplyMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
     }\r
 }\r
index c88db4a9558c6e5061a0533cb99bf5ad858de31d..5338ed03a0d3d7e493eab3e6252bd1302d19ff30 100644 (file)
@@ -20,11 +20,11 @@ public class EchoReplyMessageFactoryTest {
      */\r
     @Test\r
     public void testWithEmptyDataField() {\r
-        ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
-        EchoOutput builtByFactory = EchoReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer();\r
+        EchoOutput builtByFactory = BufferHelper.decodeV13(\r
+                EchoReplyMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
     }\r
     \r
     /**\r
@@ -34,10 +34,10 @@ public class EchoReplyMessageFactoryTest {
     public void testWithDataFieldSet() {\r
         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};\r
         ByteBuf bb = BufferHelper.buildBuffer(data);\r
-        EchoOutput builtByFactory = EchoReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-\r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        EchoOutput builtByFactory = BufferHelper.decodeV13(\r
+                EchoReplyMessageFactory.getInstance(), bb);\r
+        \r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
         Assert.assertArrayEquals(builtByFactory.getData(), data);\r
     }\r
 \r
index de2c807e1886b008214fefd4fd02a120bca2718a..e136f5ad7a1d9c62d4ff5aeb98f6a79dce3a1a22 100644 (file)
@@ -20,11 +20,11 @@ public class EchoRequestMessageFactoryTest {
      */\r
     @Test\r
     public void testWithEmptyDataField() {\r
-        ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
-        EchoRequestMessage builtByFactory = EchoRequestMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer();\r
+        EchoRequestMessage builtByFactory = BufferHelper.decodeV13(\r
+                EchoRequestMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
     }\r
     \r
     /**\r
@@ -34,10 +34,11 @@ public class EchoRequestMessageFactoryTest {
     public void testWithDataFieldSet() {\r
         byte[] data = new byte[]{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};\r
         ByteBuf bb = BufferHelper.buildBuffer(data);\r
-        EchoRequestMessage builtByFactory = EchoRequestMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        EchoRequestMessage builtByFactory = BufferHelper.decodeV13(\r
+                EchoRequestMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        Assert.assertArrayEquals(builtByFactory.getData(), data);\r
     }\r
 \r
 }\r
index 4991a48b7c622c929a5985ef3d5463d21d24385e..091e6a52321573098e62addd05612d2424a81521 100644 (file)
@@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf;
 \r
 import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterMessage;\r
 \r
@@ -20,14 +19,13 @@ public class ExperimenterMessageFactoryTest {
      */\r
     @Test\r
     public void test() {\r
-        byte[] data = new byte[]{0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04};\r
-        ByteBuf bb = BufferHelper.buildBuffer(data);\r
-        ExperimenterMessage builtByFactory = ExperimenterMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer("01 02 03 04 01 02 03 04");\r
+        ExperimenterMessage builtByFactory = BufferHelper.decodeV13(\r
+                ExperimenterMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
-        Assert.assertEquals(builtByFactory.getExperimenter().longValue(), 16909060L);\r
-        Assert.assertEquals(builtByFactory.getExpType().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        Assert.assertEquals(builtByFactory.getExperimenter().longValue(), 0x01020304L);\r
+        Assert.assertEquals(builtByFactory.getExpType().longValue(), 0x01020304L);\r
     }\r
 \r
 }\r
index 7f158c99c04d3ed6d8033e2f8530c9452e5f1fe4..44cd96647e3972068e1aef26ef58129b3b3a9be2 100644 (file)
@@ -5,7 +5,6 @@ import io.netty.buffer.ByteBuf;
 \r
 import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
 \r
@@ -20,20 +19,19 @@ public class FeaturesReplyMessageFactoryTest {
      */\r
     @Test\r
     public void test() {\r
-        byte[] data = new byte[]{ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, \r
-                                  0x00, 0x01, 0x02, 0x03, 0x01, 0x01, 0x00, 0x00,\r
-                                  0x00, 0x01, 0x02, 0x03, 0x00, 0x01, 0x02, 0x03 };\r
-        ByteBuf bb = BufferHelper.buildBuffer(data);\r
-        GetFeaturesOutput builtByFactory = FeaturesReplyMessageFactory.getInstance().bufferToMessage(bb, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 01 02 03 01 01 00 00 00"\r
+                + " 01 02 03 00 01 02 03");\r
+        GetFeaturesOutput builtByFactory = BufferHelper.decodeV13(\r
+                FeaturesReplyMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
-        Assert.assertTrue(builtByFactory.getTables() == 1);\r
-        Assert.assertTrue(builtByFactory.getAuxiliaryId() == 1);\r
-        Assert.assertEquals(66051L, builtByFactory.getBuffers().longValue());\r
-        Assert.assertEquals(66051L, builtByFactory.getCapabilities().longValue());\r
-        Assert.assertEquals(66051L, builtByFactory.getReserved().longValue());\r
-        Assert.assertTrue(builtByFactory.getDatapathId().longValue() == 283686952306183L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        Assert.assertEquals("Wrong datapathId", 0x0001020304050607L, builtByFactory.getDatapathId().longValue());\r
+        Assert.assertEquals("Wrong buffers", 0x00010203L, builtByFactory.getBuffers().longValue());\r
+        Assert.assertEquals("Wrong number of tables", 0x01, builtByFactory.getTables().shortValue());\r
+        Assert.assertEquals("Wrong auxiliaryId", 0x01, builtByFactory.getAuxiliaryId().shortValue());\r
+        Assert.assertEquals("Wrong capabilities", 0x00010203L, builtByFactory.getCapabilities().longValue());\r
+        Assert.assertEquals("Wrong reserved", 0x00010203L, builtByFactory.getReserved().longValue());\r
+        \r
     }\r
 \r
 }\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/FlowRemovedMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..7f1aa2e
--- /dev/null
@@ -0,0 +1,43 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemovedMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class FlowRemovedMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link FlowRemovedMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    public void test(){\r
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 04 05 06 07 00 03 00 04 00 00 00 02"\r
+                + " 00 00 00 05 00 01 00 03 00 01 02 03 04 05 06 07 00 01 02 03 04 05 06 07");\r
+        FlowRemovedMessage builtByFactory = BufferHelper.decodeV13(FlowRemovedMessageFactory.getInstance(), bb);\r
+\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        \r
+        Assert.assertTrue(builtByFactory.getCookie().longValue() == 0x0001020304050607L);\r
+        Assert.assertTrue(builtByFactory.getPriority() == 0x03);\r
+\r
+        //        TODO enum type!\r
+        //        builtByFactory.getReason()\r
+        Assert.assertEquals("Wrong tableId", new TableId((long) 4), builtByFactory.getTableId());\r
+        Assert.assertEquals("Wrong durationSec", 0x02L, builtByFactory.getDurationSec().longValue());\r
+        Assert.assertEquals("Wrong durationNsec", 0x05L, builtByFactory.getDurationNsec().longValue());\r
+        Assert.assertEquals("Wrong idleTimeout", 0x01, builtByFactory.getIdleTimeout().intValue());\r
+        Assert.assertEquals("Wrong hardTimeout", 0x03, builtByFactory.getHardTimeout().intValue());\r
+        Assert.assertEquals("Wrong packetCount", 0x0001020304050607L, builtByFactory.getPacketCount().longValue());\r
+        Assert.assertEquals("Wrong byteCount", 0x0001020304050607L, builtByFactory.getByteCount().longValue());\r
+    }\r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/GetConfigReplyMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..06ef8b5
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigOutput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @author timotej.kubas\r
+ */\r
+public class GetConfigReplyMessageFactoryTest {\r
+\r
+\r
+    /**\r
+     * Testing {@link GetConfigReplyMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 00 03");\r
+        GetConfigOutput builtByFactory = BufferHelper.decodeV13(\r
+                GetConfigReplyMessageFactory.getInstance(), bb);\r
+\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        // TODO - enum problem !\r
+//        Assert.assertEquals(builtByFactory.getFlags().toString(),"OFPCFRAGDROP"); \r
+        Assert.assertEquals("Wrong missSendLen", 0x01, builtByFactory.getMissSendLen().intValue());\r
+        \r
+    }\r
+    \r
+}\r
index de3ce14c154ebaf7f72f35be3c61280e23d9898d..04af39d409260065eb7fab6fa9c8a8a529534f71 100644 (file)
@@ -3,32 +3,28 @@ package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
 \r
 import io.netty.buffer.ByteBuf;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;\r
 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
 \r
 /**\r
  * @author michal.polkorab\r
- *\r
+ * \r
  */\r
 public class HelloMessageFactoryTest {\r
-    \r
+\r
     /** Number of currently supported version / codec */\r
-    public static final short VERSION_YET_SUPPORTED = 0x04;\r
-    /** Index of Xid in OpenFlow 1.3 header */\r
-    public static final byte INDEX_OF_XID_IN_HEADER = 4;\r
+    public static final Short VERSION_YET_SUPPORTED = 0x04;\r
 \r
     /**\r
      * Testing {@link HelloMessageFactory} for correct translation into POJO\r
      */\r
     @Test\r
     public void test() {\r
-        ByteBuf bb = BufferHelper.buildBuffer(new byte[0]);\r
-        HelloMessage builtByFactory = HelloMessageFactory.getInstance().bufferToMessage(bb, VERSION_YET_SUPPORTED);\r
+        ByteBuf bb = BufferHelper.buildBuffer();\r
+        HelloMessage builtByFactory = BufferHelper.decodeV13(\r
+                HelloMessageFactory.getInstance(), bb);\r
 \r
-        Assert.assertTrue(builtByFactory.getVersion() == VERSION_YET_SUPPORTED);\r
-        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
     }\r
 }\r
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
new file mode 100644 (file)
index 0000000..ed93d7a
--- /dev/null
@@ -0,0 +1,31 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReplyMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class MultipartReplyMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link MultipartReplyMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    public void test(){\r
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 00 01 00 00 00 00 01 02 03 04");\r
+        MultipartReplyMessage builtByFactory = BufferHelper.decodeV13(MultipartReplyMessageFactory.getInstance(), bb);\r
+        \r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        \r
+        Assert.assertEquals("Wrong flag", true, builtByFactory.getFlags().isOFPMPFREQMORE());\r
+        Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getBody());\r
+    }\r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PacketInMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..fa94c27
--- /dev/null
@@ -0,0 +1,36 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.openflowjava.protocol.impl.util.ByteBufUtils;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.TableId;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ *\r
+ */\r
+public class PacketInMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link PacketInMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    public void test(){\r
+        ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 01 02 01 04 00 01 02 03 04 05 06 07 00 00 01 02 03 04");\r
+        PacketInMessage builtByFactory = BufferHelper.decodeV13(PacketInMessageFactory.getInstance(), bb); \r
+        \r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        \r
+        Assert.assertEquals("Wrong bufferID", 0x00010203L, builtByFactory.getBufferId().longValue());\r
+        Assert.assertEquals("Wrong totalLen", 0x0102, builtByFactory.getTotalLen().intValue());\r
+        Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason().shortValue());\r
+        Assert.assertEquals("Wrong tableID", new TableId((long) 4), builtByFactory.getTableId());\r
+        Assert.assertEquals("Wrong cookie", 0x0001020304050607L, builtByFactory.getCookie().longValue());\r
+        Assert.assertArrayEquals("Wrong data", ByteBufUtils.hexStringToBytes("01 02 03 04"), builtByFactory.getData());\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/PortStatusMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..2100a5a
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+\r
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;\r
+\r
+/**\r
+ * @author timotej.kubas\r
+ * @author michal.polkorab\r
+ */\r
+public class PortStatusMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link PortStatusMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    public void test(){\r
+        ByteBuf bb = BufferHelper.buildBuffer("01 00 00 00 00 00 00 00");\r
+        \r
+        PortStatusMessage builtByFactory = BufferHelper.decodeV13(PortStatusMessageFactory.getInstance(), bb);\r
+        \r
+        BufferHelper.checkHeaderV13(builtByFactory);\r
+        //Assert.assertEquals("Wrong reason", 0x01, builtByFactory.getReason());\r
+    }\r
+}\r
index b65beb215627983103599f75f7a95a854d8d3e5b..37b6d6761f90cd14aba443946310e4d433c5cbc7 100644 (file)
@@ -4,10 +4,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInputBuilder;\r
 \r
@@ -21,22 +20,19 @@ public class BarrierInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void test() {\r
+    public void test() throws Exception {\r
         BarrierInputBuilder bib = new BarrierInputBuilder();\r
-        bib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        bib.setXid(16909060L);\r
+        BufferHelper.setupHeader(bib);\r
         BarrierInput bi = bib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         BarrierInputMessageFactory bimf = BarrierInputMessageFactory.getInstance();\r
         bimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, bi);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == BARRIER_REQUEST_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, BARRIER_REQUEST_MESSAGE_CODE_TYPE, 8);\r
     }\r
 \r
 }\r
index 07ecc19455f8a0b3df753841e01ceedc3630f5a0..2dc4aa16fe051e8a4db085f69f9c9efbb681c2c2 100644 (file)
@@ -4,10 +4,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoInputBuilder;\r
 \r
@@ -21,22 +20,19 @@ public class EchoInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link EchoInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void test() {\r
+    public void test() throws Exception {\r
         EchoInputBuilder eib = new EchoInputBuilder();\r
-        eib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        eib.setXid(16909060L);\r
+        BufferHelper.setupHeader(eib);\r
         EchoInput ei = eib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         EchoInputMessageFactory eimf = EchoInputMessageFactory.getInstance();\r
         eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, ei);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == ECHO_REQUEST_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, ECHO_REQUEST_MESSAGE_CODE_TYPE, 8);\r
     }\r
 \r
 }\r
index 8ebe18f89bcc7ad8ebd164a35bcf550920291d5a..01b8047ccca810c6078ac3d570317f7698e07458 100644 (file)
@@ -4,10 +4,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoReplyInputBuilder;\r
 \r
@@ -21,22 +20,19 @@ public class EchoReplyInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void test() {\r
+    public void test() throws Exception {\r
         EchoReplyInputBuilder erib = new EchoReplyInputBuilder();\r
-        erib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        erib.setXid(16909060L);\r
+        BufferHelper.setupHeader(erib);\r
         EchoReplyInput eri = erib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         EchoReplyInputMessageFactory eimf = EchoReplyInputMessageFactory.getInstance();\r
         eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, eri);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == ECHO_REPLY_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, ECHO_REPLY_MESSAGE_CODE_TYPE, 8);\r
     }\r
 \r
 }\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/ExperimenterInputMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..a7de110
--- /dev/null
@@ -0,0 +1,44 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ExperimenterInputMessageFactoryTest {\r
+\r
+    private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE;\r
+    \r
+    /**\r
+     * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
+     */\r
+    @Test\r
+    public void test() throws Exception {\r
+        ExperimenterInputBuilder eib = new ExperimenterInputBuilder();\r
+        BufferHelper.setupHeader(eib);\r
+        eib.setExperimenter(0x0001020304L);\r
+        eib.setExpType(0x0001020304L);\r
+        ExperimenterInput ei = eib.build();\r
+        \r
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        ExperimenterInputMessageFactory eimf = ExperimenterInputMessageFactory.getInstance();\r
+        eimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, ei);\r
+        \r
+        BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, 16);\r
+        Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());\r
+        Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());\r
+    }\r
+\r
+\r
+}\r
index eb18faad846ad8ebdf15670230fe61e9daf06caa..f2236e651c55d7321f3376e499a920cb7fc0feff 100644 (file)
@@ -4,10 +4,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetConfigInputBuilder;\r
 \r
@@ -21,22 +20,19 @@ public class GetConfigInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void test() {\r
+    public void test() throws Exception {\r
         GetConfigInputBuilder gcib = new GetConfigInputBuilder();\r
-        gcib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        gcib.setXid(16909060L);\r
+        BufferHelper.setupHeader(gcib);\r
         GetConfigInput gci = gcib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         GetConfigInputMessageFactory gcimf = GetConfigInputMessageFactory.getInstance();\r
         gcimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, gci);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE, 8);\r
     }\r
 \r
 }\r
index b43854d94503384b0ff943f1435fb9d37590bc0b..3153b0ddb9c46b44d0566d65b63a376f020531f9 100644 (file)
@@ -4,10 +4,9 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesInputBuilder;\r
 \r
@@ -21,22 +20,19 @@ public class GetFeaturesInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void test() {\r
+    public void test() throws Exception {\r
         GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder();\r
-        gfib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        gfib.setXid(16909060L);\r
+        BufferHelper.setupHeader(gfib);\r
         GetFeaturesInput gfi = gfib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         GetFeaturesInputMessageFactory gfimf = GetFeaturesInputMessageFactory.getInstance();\r
         gfimf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, gfi);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == FEATURES_REQUEST_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, FEATURES_REQUEST_MESSAGE_CODE_TYPE, 8);\r
     }\r
 \r
 }\r
index 523419c93f5eeabe609bdb1bbed1a3fdb0e74c82..49cfcbf416ef07d9a7d9c1868a97faa9ddcdfa86 100644 (file)
@@ -4,13 +4,18 @@ package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
-import org.junit.Assert;\r
+import java.util.List;\r
+\r
 import org.junit.Test;\r
-import org.opendaylight.openflowjava.protocol.impl.core.OFFrameDecoder;\r
 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
-import org.opendaylight.openflowjava.protocol.impl.serialization.factories.HelloInputMessageFactory;\r
+import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInputBuilder;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;\r
+\r
+import com.google.common.collect.Lists;\r
 \r
 /**\r
  * @author michal.polkorab\r
@@ -22,22 +27,42 @@ public class HelloInputMessageFactoryTest {
     \r
     /**\r
      * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
+     */\r
+    @Test\r
+    public void testWithoutElementsSet() throws Exception {\r
+        HelloInputBuilder hib = new HelloInputBuilder();\r
+        BufferHelper.setupHeader(hib);\r
+        HelloInput hi = hib.build();\r
+        \r
+        ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
+        himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
+        \r
+        BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
+    }\r
+    \r
+    /**\r
+     * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
+     * @throws Exception \r
      */\r
     @Test\r
-    public void testWithoutElementsSet() {\r
+    public void testWithElementsSet() throws Exception {\r
         HelloInputBuilder hib = new HelloInputBuilder();\r
-        hib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        hib.setXid(16909060L);\r
+        BufferHelper.setupHeader(hib);\r
+        ElementsBuilder eb = new ElementsBuilder();\r
+        eb.setType(HelloElementType.VERSIONBITMAP);\r
+        eb.setData(new byte[]{0x01, 0x02, 0x42, 0x03});\r
+        List<Elements> elementList = Lists.newArrayList(eb.build());\r
+        hib.setElements(elementList);\r
         HelloInput hi = hib.build();\r
         \r
         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();\r
         HelloInputMessageFactory himf = HelloInputMessageFactory.getInstance();\r
         himf.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, hi);\r
         \r
-        Assert.assertTrue(out.readByte() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
-        Assert.assertTrue(out.readByte() == HELLO_MESSAGE_CODE_TYPE);\r
-        Assert.assertTrue(out.readUnsignedShort() == OFFrameDecoder.LENGTH_OF_HEADER);\r
-        Assert.assertTrue(out.readUnsignedInt() == 16909060L);\r
+        BufferHelper.checkHeaderV13(out, HELLO_MESSAGE_CODE_TYPE, 8);\r
+        // TODO - element list\r
     }\r
 \r
 }\r
index d6f0fd0832632a55aee92c04a3fbecfbe0c62261..c8c62dfd3cd1ab1a95ab59357bf01dbf2c7a9f5b 100644 (file)
@@ -4,20 +4,32 @@ package org.opendaylight.openflowjava.protocol.impl.util;
 import io.netty.buffer.ByteBuf;\r
 import io.netty.buffer.UnpooledByteBufAllocator;\r
 \r
+import java.lang.reflect.InvocationTargetException;\r
+import java.lang.reflect.Method;\r
+\r
+import org.junit.Assert;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\r
+import org.opendaylight.openflowjava.protocol.impl.serialization.OFSerializer;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
 /**\r
  * @author michal.polkorab\r
- *\r
+ * \r
  */\r
 public abstract class BufferHelper {\r
 \r
     /**\r
      * \r
      */\r
-    private static final byte[] XID = new byte[]{0x01, 0x02, 0x03, 0x04};\r
+    public static final Long DEFAULT_XID = 0x01020304L;\r
+    private static final byte[] XID = new byte[] { 0x01, 0x02, 0x03, 0x04 };\r
 \r
     /**\r
      * @param payload\r
-     * @return ByteBuf filled with OpenFlow protocol message without first 2 bytes\r
+     * @return ByteBuf filled with OpenFlow protocol message without first 4\r
+     *         bytes\r
      */\r
     public static ByteBuf buildBuffer(byte[] payload) {\r
         ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer();\r
@@ -25,5 +37,100 @@ public abstract class BufferHelper {
         bb.writeBytes(payload);\r
         return bb;\r
     }\r
+    \r
+    /**\r
+     * @param payload String in hex format\r
+     * @return ByteBuf filled with OpenFlow protocol message without first 4\r
+     *         bytes\r
+     */\r
+    public static ByteBuf buildBuffer(String payload) {\r
+        return buildBuffer(ByteBufUtils.hexStringToBytes(payload));\r
+    }\r
+    \r
+    /**\r
+     * @return ByteBuf filled with OpenFlow protocol header message without first 4\r
+     *         bytes\r
+     */\r
+    public static ByteBuf buildBuffer() {\r
+        ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        bb.writeBytes(XID);\r
+        bb.writeBytes(new byte[0]);\r
+        return bb;\r
+    }\r
+\r
+    /**\r
+     * Use version 1.3 for encoded message\r
+     * @param input\r
+     *            ByteBuf to be checked for correct OpenFlow Protocol header\r
+     * @param msgType\r
+     *            type of received message\r
+     * @param length TODO\r
+     */\r
+    public static void checkHeaderV13(ByteBuf input, byte msgType, int length) {\r
+        checkHeader(input, msgType, length, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+    }\r
+    \r
+    private static void checkHeader(ByteBuf input, byte msgType, int length, Short version) {\r
+        Assert.assertEquals("Wrong version", version, Short.valueOf(input.readByte()));\r
+        Assert.assertEquals("Wrong type", msgType, input.readByte());\r
+        Assert.assertEquals("Wrong length", length, input.readUnsignedShort());\r
+        Assert.assertEquals("Wrong Xid", DEFAULT_XID, Long.valueOf(input.readUnsignedInt()));\r
+    }\r
+    \r
 \r
+    /**\r
+     * @param ofHeader OpenFlow protocol header\r
+     */\r
+    public static void checkHeaderV13(OfHeader ofHeader) {\r
+        checkHeader(ofHeader,  HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+    }\r
+    \r
+    private static void checkHeader(OfHeader ofHeader, Short version) {\r
+        Assert.assertEquals("Wrong version", version, ofHeader.getVersion());\r
+        Assert.assertEquals("Wrong Xid", DEFAULT_XID, ofHeader.getXid());\r
+    }\r
+    \r
+    /**\r
+     * @param builder\r
+     * @throws NoSuchMethodException\r
+     * @throws SecurityException\r
+     * @throws IllegalAccessException\r
+     * @throws IllegalArgumentException\r
+     * @throws InvocationTargetException\r
+     */\r
+    public static void setupHeader(Object builder) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {\r
+        Method m = builder.getClass().getMethod("setVersion", Short.class);\r
+        m.invoke(builder, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        Method m2 = builder.getClass().getMethod("setXid", Long.class);\r
+        m2.invoke(builder, BufferHelper.DEFAULT_XID);\r
+    }\r
+    \r
+    /**\r
+     * Use version 1.3 for decoding message\r
+     * @param decoder decoder instance\r
+     * @param bb data input buffer\r
+     * @return message decoded pojo\r
+     */\r
+    public static <E extends DataObject> E decodeV13(OFDeserializer<E> decoder, ByteBuf bb) {\r
+        return bufferToMessage(decoder, HelloMessageFactoryTest.VERSION_YET_SUPPORTED, bb);\r
+    }\r
+    \r
+    private static <E extends DataObject> E bufferToMessage(OFDeserializer<E> decoder, short version, ByteBuf bb) {\r
+        return decoder.bufferToMessage(bb, version);\r
+    }\r
+    \r
+    /**\r
+     * Use OF-protocol version 1.3\r
+     * @param encoder serialize factory\r
+     * @param out buffer the result will be written into\r
+     * @param pojo input message\r
+     */\r
+    public static <E extends DataObject> void encodeV13(OFSerializer<E> encoder, ByteBuf out, E pojo) {\r
+        messageToBuffer(encoder, out, pojo, HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+    }\r
+    \r
+    private static <E extends DataObject> void messageToBuffer(\r
+            OFSerializer<E> encoder, ByteBuf out, E pojo, Short version) {\r
+        encoder.messageToBuffer(version, out, pojo);\r
+    }\r
 }\r
diff --git a/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java b/openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/util/ByteBufUtilsTest.java
new file mode 100644 (file)
index 0000000..b8919a8
--- /dev/null
@@ -0,0 +1,55 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.opendaylight.openflowjava.protocol.impl.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ByteBufUtilsTest {\r
+\r
+    private byte[] expected = new byte[]{0x01, 0x02, 0x03, 0x04, 0x05, (byte) 0xff};\r
+    \r
+    /**\r
+     * Test of {@link ByteBufUtils#hexStringToBytes(String)}\r
+     */\r
+    @Test\r
+    public void hexStringToBytesTest() {\r
+        byte[] data = ByteBufUtils.hexStringToBytes("01 02 03 04 05 ff");\r
+\r
+        Assert.assertArrayEquals(expected, data);\r
+    }\r
+    \r
+    /**\r
+     * Test of {@link ByteBufUtils#hexStringToByteBuf(String)}\r
+     */\r
+    @Test\r
+    public void hexStringToByteBufTest() {\r
+        ByteBuf bb = ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff");\r
+        \r
+        Assert.assertArrayEquals(expected, byteBufToByteArray(bb));\r
+    }\r
+    \r
+    /**\r
+     * Test of {@link ByteBufUtils#hexStringToByteBuf(String, ByteBuf)}\r
+     */\r
+    @Test\r
+    public void hexStringToGivenByteBufTest() {\r
+        ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        ByteBufUtils.hexStringToByteBuf("01 02 03 04 05 ff", buffer);\r
+\r
+        Assert.assertArrayEquals(expected, byteBufToByteArray(buffer));\r
+    }\r
+    \r
+    private static byte[] byteBufToByteArray(ByteBuf bb) {\r
+        byte[] result = new byte[bb.readableBytes()];\r
+        bb.readBytes(result);\r
+        return result;\r
+    }\r
+\r
+}\r