Added more serialization factories 72/1172/1
authormichal.polkorab <michal.polkorab@pantheon.sk>
Thu, 12 Sep 2013 19:51:54 +0000 (12:51 -0700)
committermichal.polkorab <michal.polkorab@pantheon.sk>
Thu, 12 Sep 2013 19:52:47 +0000 (12:52 -0700)
Signed-off-by: michal.polkorab <michal.polkorab@pantheon.sk>
14 files changed:
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactory.java
openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/HelloInputMessageFactoryTest.java

diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/ErrorMessageFactory.java
new file mode 100644 (file)
index 0000000..691041e
--- /dev/null
@@ -0,0 +1,46 @@
+/* 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.ErrorType;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class ErrorMessageFactory implements OFDeserializer<ErrorMessage> {\r
+\r
+private static ErrorMessageFactory instance;\r
+    \r
+    private ErrorMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static ErrorMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new ErrorMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public ErrorMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        ErrorMessageBuilder emb = new ErrorMessageBuilder();\r
+        emb.setVersion(version);\r
+        emb.setXid(rawMessage.readUnsignedInt());\r
+        ErrorType[] errorTypes = ErrorType.values();\r
+        // TODO - finish implementation after enums are generated with proper funcionality\r
+        //emb.setType();\r
+        emb.setCode(rawMessage.readInt());\r
+        //emb.setData(value);\r
+        return emb.build();\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/BarrierInputMessageFactory.java
new file mode 100644 (file)
index 0000000..3d74d7c
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.BarrierInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class BarrierInputMessageFactory implements OFSerializer<BarrierInput> {\r
+\r
+    /** Code type of BarrierRequest message */\r
+    public static final byte MESSAGE_TYPE = 20;\r
+    private static BarrierInputMessageFactory instance;\r
+    \r
+    private BarrierInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static BarrierInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new BarrierInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out, BarrierInput 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
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoInputMessageFactory.java
new file mode 100644 (file)
index 0000000..6d799fe
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.EchoInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoInputMessageFactory implements OFSerializer<EchoInput> {\r
+\r
+    /** Code type of EchoRequest message */\r
+    public static final byte MESSAGE_TYPE = 2;\r
+    private static EchoInputMessageFactory instance;\r
+    \r
+    private EchoInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static EchoInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new EchoInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out, EchoInput 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
+    }\r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/EchoReplyInputMessageFactory.java
new file mode 100644 (file)
index 0000000..3b3e188
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.EchoReplyInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoReplyInputMessageFactory implements OFSerializer<EchoReplyInput>{\r
+\r
+    /** Code type of EchoReply message */\r
+    public static final byte MESSAGE_TYPE = 3;\r
+    private static EchoReplyInputMessageFactory instance;\r
+    \r
+    private EchoReplyInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static EchoReplyInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new EchoReplyInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            EchoReplyInput 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
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetConfigInputMessageFactory.java
new file mode 100644 (file)
index 0000000..b722dae
--- /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
+\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.GetConfigInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class GetConfigInputMessageFactory implements OFSerializer<GetConfigInput> {\r
+\r
+    /** Code type of GetConfigRequest message */\r
+    public static final byte MESSAGE_TYPE = 7;\r
+    private static GetConfigInputMessageFactory instance;\r
+    \r
+    private GetConfigInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static GetConfigInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new GetConfigInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            GetConfigInput 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
+        \r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/GetFeaturesInputMessageFactory.java
new file mode 100644 (file)
index 0000000..de5cb5d
--- /dev/null
@@ -0,0 +1,43 @@
+/* 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.GetFeaturesInput;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class GetFeaturesInputMessageFactory implements OFSerializer<GetFeaturesInput>{\r
+\r
+    /** Code type of FeaturesRequest message */\r
+    public static final byte MESSAGE_TYPE = 5;\r
+    private static GetFeaturesInputMessageFactory instance;\r
+    \r
+    private GetFeaturesInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static GetFeaturesInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new GetFeaturesInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            GetFeaturesInput 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
+    }\r
+\r
+}\r
index 86c612a3f118a40cb5b85e9ee99ab6d7c2cbd97c..c1ea5d4a455ed454cac66c231c4b6a2405778ec8 100644 (file)
@@ -13,7 +13,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
  */\r
 public class HelloInputMessageFactory implements OFSerializer<HelloInput>{\r
 \r
-    /** Code type of HelloMessage */\r
+    /** Code type of Hello message */\r
     public static final byte MESSAGE_TYPE = 0;\r
     private static HelloInputMessageFactory instance;\r
     \r
diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/serialization/factories/SetConfigMessageFactory.java
new file mode 100644 (file)
index 0000000..130cd85
--- /dev/null
@@ -0,0 +1,48 @@
+/* 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.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
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class SetConfigMessageFactory implements OFSerializer<SetConfigInput> {\r
+\r
+    /** Code type of SetConfig message */\r
+    public static final byte MESSAGE_TYPE = 9;\r
+    private static SetConfigMessageFactory instance;\r
+    \r
+    private SetConfigMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static SetConfigMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new SetConfigMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out,\r
+            SetConfigInput 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 enums provide needed funcionality\r
+        \r
+    }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..b65beb2
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\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
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class BarrierInputMessageFactoryTest {\r
+\r
+    private static final byte BARRIER_REQUEST_MESSAGE_CODE_TYPE = 20;\r
+    \r
+    /**\r
+     * Testing of {@link BarrierInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        BarrierInputBuilder bib = new BarrierInputBuilder();\r
+        bib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        bib.setXid(16909060L);\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
+    }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..07ecc19
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\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
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoInputMessageFactoryTest {\r
+\r
+    private static final byte ECHO_REQUEST_MESSAGE_CODE_TYPE = 2;\r
+    \r
+    /**\r
+     * Testing of {@link EchoInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        EchoInputBuilder eib = new EchoInputBuilder();\r
+        eib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        eib.setXid(16909060L);\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
+    }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..8ebe18f
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\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
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoReplyInputMessageFactoryTest {\r
+\r
+    private static final byte ECHO_REPLY_MESSAGE_CODE_TYPE = 3;\r
+    \r
+    /**\r
+     * Testing of {@link EchoReplyInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        EchoReplyInputBuilder erib = new EchoReplyInputBuilder();\r
+        erib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        erib.setXid(16909060L);\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
+    }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..eb18faa
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\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
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class GetConfigInputMessageFactoryTest {\r
+\r
+    private static final byte GET_CONFIG_REQUEST_MESSAGE_CODE_TYPE = 7;\r
+    \r
+    /**\r
+     * Testing of {@link GetConfigInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        GetConfigInputBuilder gcib = new GetConfigInputBuilder();\r
+        gcib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        gcib.setXid(16909060L);\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
+    }\r
+\r
+}\r
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
new file mode 100644 (file)
index 0000000..b43854d
--- /dev/null
@@ -0,0 +1,42 @@
+/* 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.core.OFFrameDecoder;\r
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactoryTest;\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
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class GetFeaturesInputMessageFactoryTest {\r
+\r
+    private static final byte FEATURES_REQUEST_MESSAGE_CODE_TYPE = 5;\r
+    \r
+    /**\r
+     * Testing of {@link GetFeaturesInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void test() {\r
+        GetFeaturesInputBuilder gfib = new GetFeaturesInputBuilder();\r
+        gfib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        gfib.setXid(16909060L);\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
+    }\r
+\r
+}\r
index 4bed9a28714e2efce47022a96031138bc6e0ddbe..523419c93f5eeabe609bdb1bbed1a3fdb0e74c82 100644 (file)
@@ -19,6 +19,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 public class HelloInputMessageFactoryTest {\r
 \r
     private static final byte HELLO_MESSAGE_CODE_TYPE = 0;\r
+    \r
     /**\r
      * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
      */\r