Merge "add basic lib - plugin communication"
authorDaniel Bartos <daniel.bartos@pantheon.sk>
Thu, 12 Sep 2013 05:54:23 +0000 (05:54 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 12 Sep 2013 05:54:23 +0000 (05:54 +0000)
41 files changed:
openflow-protocol-api/pom.xml
openflow-protocol-impl/pom.xml
openflow-protocol-impl/src/main/java/org/openflow/core/DeserializationFactory.java [deleted file]
openflow-protocol-impl/src/main/java/org/openflow/core/SerializationFactory.java [deleted file]
openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoReplyMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoRequestMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/FeaturesReplyMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/HelloMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/Of13Codec.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/OF13Codec.java with 82% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/OfFrameDecoder.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/OFFrameDecoder.java with 90% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/OfVersionDetector.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/OFVersionDetector.java with 84% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/PublishingChannelInitializer.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/PublishingChannelInitializer.java with 75% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/SslContextFactory.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/SslContextFactory.java with 98% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/SslKeyStore.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/SslKeyStore.java with 79% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/SslTrustManagerFactory.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/SslTrustManagerFactory.java with 98% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/TcpHandler.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/TCPHandler.java with 85% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/TlsDetector.java [moved from openflow-protocol-impl/src/main/java/org/openflow/core/TLSDetector.java with 92% similarity]
openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DecoderTable.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DeserializationFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/MessageTypeCodeKey.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/OfDeserializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/EncoderTable.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/MessageTypeKey.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/OfSerializer.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/SerializationFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/factories/HelloInputMessageFactory.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/DummyDecoder.java [moved from openflow-protocol-impl/src/test/java/org/openflow/core/DummyDecoder.java with 92% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/OFFrameDecoderTest.java [moved from openflow-protocol-impl/src/test/java/org/openflow/core/OFFrameDecoderTest.java with 83% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/OFVersionDetectorTest.java [moved from openflow-protocol-impl/src/test/java/org/openflow/core/OFVersionDetectorTest.java with 81% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/TCPHandlerTest.java [moved from openflow-protocol-impl/src/test/java/org/openflow/core/TCPHandlerTest.java with 83% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/TLSDetectorTest.java [moved from openflow-protocol-impl/src/test/java/org/openflow/core/TLSDetectorTest.java with 74% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClient.java [moved from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClient.java with 99% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClientHandler.java [moved from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClientHandler.java with 75% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClientInitializer.java [moved from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClientInitializer.java with 93% similarity]
openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoReplyMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoRequestMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/FeaturesReplyMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/HelloMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/serialization/factories/HelloInputMessageFactoryTest.java [new file with mode: 0644]
openflow-protocol-impl/src/test/java/org/openflow/lib/util/BufferHelper.java [new file with mode: 0644]
openflow-protocol-impl/src/test/resources/org/openflow/lib/OFBinaryMessageInput.txt [moved from openflow-protocol-impl/src/test/resources/org/openflow/core/OFBinaryMessageInput.txt with 100% similarity]

index fa3e58840814141d4c5c01182e63613e1e25472c..63757a7749c34f96291201f53ffe9a1f1ab720a5 100644 (file)
                                 <pluginExecution>\r
                                     <pluginExecutionFilter>\r
                                         <groupId>\r
-                                            org.opendaylight.controller\r
+                                            org.opendaylight.yangtools\r
                                         </groupId>\r
                                         <artifactId>\r
                                             yang-maven-plugin\r
                                         </artifactId>\r
                                         <versionRange>\r
-                                            [0.5,)\r
+                                            (0.5.6,)\r
                                         </versionRange>\r
                                         <goals>\r
                                             <goal>\r
index b4eb362fc36fceb405d275514b9dc390fdf371f9..659cc64118ccbc96cddb3c6c2d99bbce0a7996ec 100644 (file)
@@ -28,7 +28,7 @@
         <dependency>
             <groupId>io.netty</groupId>
             <artifactId>netty-all</artifactId>
-            <version>4.0.4.Final</version>
+            <version>4.0.8.Final</version>
         </dependency>
         <dependency>
             <groupId>org.slf4j</groupId>
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/core/DeserializationFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/core/DeserializationFactory.java
deleted file mode 100644 (file)
index 712bde0..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-import org.slf4j.LoggerFactory;\r
-\r
-/**\r
- *\r
- * @author michal.polkorab\r
- */\r
-public class DeserializationFactory {\r
-\r
-    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(DeserializationFactory.class);\r
-\r
-    /**\r
-     * Transforms ByteBuf into correct POJO message\r
-     * @param inputBuffer \r
-     */\r
-    public DeserializationFactory(ByteBuf inputBuffer) {\r
-        short type = inputBuffer.readUnsignedByte();\r
-\r
-        switch (type) {\r
-            // HELLO\r
-            case 0: {\r
-                LOGGER.info("OFPT_HELLO received");\r
-                \r
-                byte[] hello = new byte[]{0x04, 0x0, 0x0, 0x08, 0x0, 0x0, 0x0, 0x01};\r
-                //out.writeBytes(hello);\r
-                break;\r
-            }\r
-            // ERROR\r
-            case 1:\r
-                LOGGER.info("OFPT_ERROR received");\r
-                break;\r
-            // ECHO_REQUEST\r
-            case 2: {\r
-                LOGGER.info("OFPT_ECHO_REQUEST received");\r
-                byte[] echoReply = new byte[]{0x04, 0x03, 0x00, 0x08};\r
-                // TODO - append original data field\r
-                break;\r
-            }\r
-            // ECHO_REPLY\r
-            case 3:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // EXPERIMENTER\r
-            case 4:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // FEATURES_REQUEST\r
-            case 5:\r
-                LOGGER.info("OFPT_FEATURES_REQUEST received");\r
-                break;\r
-            // FEATURES_REPLY\r
-            case 6:\r
-                LOGGER.info("OFPT_FEATURES_REPLY received");\r
-                break;\r
-            // GET_CONFIG_REQUEST\r
-            case 7:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // GET_CONFIG_REPLY\r
-            case 8:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // SET_CONFIG\r
-            case 9:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // PACKET_IN\r
-            case 10:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // FLOW_REMOVED\r
-            case 11:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // PORT_STATUS\r
-            case 12:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // PACKET_OUT\r
-            case 13:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // FLOW_MOD\r
-            case 14:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // GROUP_MOD\r
-            case 15:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // PORT_MOD\r
-            case 16:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // TABLE_MOD\r
-            case 17:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // MULTIPART_REQUEST\r
-            case 18:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // MULTIPART_REPLY\r
-            case 19:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // BARRIER_REQUEST\r
-            case 20:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // BARRIER_REPLY\r
-            case 21:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // QUEUE_GET_CONFIG_REQUEST\r
-            case 22:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // QUEUE_GET_CONFIG_REPLY\r
-            case 23:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // ROLE_REQUEST\r
-            case 24:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // ROLE_REPLY    \r
-            case 25:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // GET_ASYNC_REQUEST\r
-            case 26:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // GET_ASYNC_REPLY\r
-            case 27:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // SET_ASYNC\r
-            case 28:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-            // METER_MOD\r
-            case 29:\r
-                LOGGER.info("OFPT_ECHO_REPLY received");\r
-                break;\r
-\r
-            default:\r
-                LOGGER.info("Received message type: " + type);\r
-                break;\r
-        }\r
-    }\r
-}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/core/SerializationFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/core/SerializationFactory.java
deleted file mode 100644 (file)
index 4d3bf33..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-\r
-package org.openflow.core;\r
-\r
-/**\r
- *\r
- * @author michal.polkorab\r
- */\r
-public abstract class SerializationFactory {\r
-    // TODO - implement this class funcionality\r
-    \r
-    \r
-}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoReplyMessageFactory.java
new file mode 100644 (file)
index 0000000..4b0b3c5
--- /dev/null
@@ -0,0 +1,45 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutputBuilder;\r
+import org.openflow.lib.deserialization.OfDeserializer;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoReplyMessageFactory implements OfDeserializer<EchoOutput> {\r
+\r
+    private static EchoReplyMessageFactory instance;\r
+\r
+    private EchoReplyMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static EchoReplyMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new EchoReplyMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    /* (non-Javadoc)\r
+     * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short)\r
+     */\r
+    @Override\r
+    public EchoOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
+        EchoOutputBuilder eob = new EchoOutputBuilder();\r
+        eob.setVersion(version);\r
+        eob.setXid(rawMessage.readUnsignedInt());\r
+        // read the rest of EchoReply message\r
+        eob.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+        return eob.build();\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoRequestMessageFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/EchoRequestMessageFactory.java
new file mode 100644 (file)
index 0000000..357936a
--- /dev/null
@@ -0,0 +1,42 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessageBuilder;\r
+import org.openflow.lib.deserialization.OfDeserializer;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoRequestMessageFactory implements OfDeserializer<EchoRequestMessage>{\r
+\r
+    \r
+    private static EchoRequestMessageFactory instance;\r
+\r
+    private EchoRequestMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static EchoRequestMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new EchoRequestMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public EchoRequestMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        EchoRequestMessageBuilder emb = new EchoRequestMessageBuilder();\r
+        emb.setVersion(version);\r
+        emb.setXid(rawMessage.readUnsignedInt());\r
+        // read the rest of EchoRequest message\r
+        emb.setData(rawMessage.readBytes(rawMessage.readableBytes()).array());\r
+        return emb.build();\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/FeaturesReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/FeaturesReplyMessageFactory.java
new file mode 100644 (file)
index 0000000..01d5c3f
--- /dev/null
@@ -0,0 +1,59 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import java.math.BigInteger;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;\r
+import org.openflow.lib.deserialization.OfDeserializer;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class FeaturesReplyMessageFactory implements OfDeserializer<GetFeaturesOutput>{\r
+    \r
+    private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;\r
+    \r
+    private static FeaturesReplyMessageFactory instance;\r
+\r
+    private FeaturesReplyMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static FeaturesReplyMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new FeaturesReplyMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    /* (non-Javadoc)\r
+     * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short)\r
+     */\r
+    @Override\r
+    public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
+        GetFeaturesOutputBuilder gfob = new GetFeaturesOutputBuilder();\r
+        gfob.setVersion(version);\r
+        gfob.setXid(rawMessage.readUnsignedInt());\r
+        \r
+        // TODO - unsigned long - check for appropriate process\r
+        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
+        rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
+        gfob.setCapabilities(rawMessage.readUnsignedInt());\r
+        gfob.setReserved(rawMessage.readUnsignedInt());\r
+        return gfob.build();\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/HelloMessageFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/deserialization/factories/HelloMessageFactory.java
new file mode 100644 (file)
index 0000000..9b25dad
--- /dev/null
@@ -0,0 +1,39 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessageBuilder;\r
+import org.openflow.lib.deserialization.OfDeserializer;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class HelloMessageFactory implements OfDeserializer<HelloMessage> {\r
+\r
+    private static HelloMessageFactory instance;\r
+    \r
+    private HelloMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static HelloMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new HelloMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    @Override\r
+    public HelloMessage bufferToMessage(ByteBuf rawMessage, short version) {\r
+        HelloMessageBuilder hmb = new HelloMessageBuilder();\r
+        hmb.setVersion(version);\r
+        hmb.setXid(rawMessage.readUnsignedInt());\r
+        return hmb.build();\r
+    }\r
+}\r
similarity index 82%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/OF13Codec.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/Of13Codec.java
index 8b85f6493d7364c38e4400c18945b1adcd218c2a..1867eeeb1f6820853cc915ea4e46c06e39f2f0ef 100644 (file)
@@ -1,11 +1,12 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
+package org.openflow.lib;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.ChannelHandlerContext;\r
 import io.netty.channel.ChannelInboundHandlerAdapter;\r
-import org.openflow.util.ByteBufUtils;\r
 \r
+import org.openflow.lib.deserialization.DeserializationFactory;\r
+import org.openflow.util.ByteBufUtils;\r
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
@@ -15,16 +16,16 @@ import org.slf4j.LoggerFactory;
  *\r
  * @author michal.polkorab\r
  */\r
-public class OF13Codec extends ChannelInboundHandlerAdapter {\r
+public class Of13Codec extends ChannelInboundHandlerAdapter {\r
 \r
     // TODO - fix with enum in API\r
     private static final int MESSAGE_TYPES = 29;\r
-    private static final Logger LOGGER = LoggerFactory.getLogger(OF13Codec.class);\r
+    private static final Logger LOGGER = LoggerFactory.getLogger(Of13Codec.class);\r
 \r
     /**\r
      * Constructor of class\r
      */\r
-    public OF13Codec() {\r
+    public Of13Codec() {\r
         LOGGER.info("Creating OF 1.3 Codec");\r
         \r
     }\r
@@ -37,11 +38,12 @@ public class OF13Codec extends ChannelInboundHandlerAdapter {
         if (LOGGER.isDebugEnabled()) {\r
             LOGGER.debug(ByteBufUtils.byteBufToHexString(bb));\r
         }\r
-\r
+        \r
+        bb.markReaderIndex();\r
         short type = bb.readUnsignedByte();\r
         int length = bb.readUnsignedShort();\r
         long xid = bb.readUnsignedInt();\r
-\r
+        bb.resetReaderIndex();\r
 \r
         if (!checkOFHeader(type, length)) {\r
             bb.discardReadBytes();\r
@@ -49,6 +51,10 @@ public class OF13Codec extends ChannelInboundHandlerAdapter {
             return;\r
         }\r
 \r
+        // TODO - change hardcoded version to constant, enum, ...\r
+        DeserializationFactory.bufferToMessage(bb, (short) 0x04);\r
+        \r
+        // TODO - delete this switch case after completing deserialization factory\r
         ByteBuf out = ctx.alloc().buffer();\r
         switch (type) {\r
             case 0: {\r
@@ -98,6 +104,6 @@ public class OF13Codec extends ChannelInboundHandlerAdapter {
     }\r
 \r
     private static boolean checkOFHeader(short type, int length) {\r
-        return !((type > MESSAGE_TYPES) || (length < OFFrameDecoder.LENGTH_OF_HEADER));\r
+        return !((type > MESSAGE_TYPES) || (length < OfFrameDecoder.LENGTH_OF_HEADER));\r
     }\r
 }\r
similarity index 90%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/OFFrameDecoder.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/OfFrameDecoder.java
index 2fae06186e8d363564109bc4d619185bc3f9c858..668925bb041606a12888c60985970f1f41865bf8 100644 (file)
@@ -1,31 +1,33 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
 
-package org.openflow.core;
+package org.openflow.lib;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ByteToMessageDecoder;
+
 import java.util.List;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;
 
 /**
  * Class for decoding incoming messages into message frames.
  *
  * @author michal.polkorab
  */
-public class OFFrameDecoder extends ByteToMessageDecoder {
+public class OfFrameDecoder extends ByteToMessageDecoder {
 
     /** Length of OpenFlow 1.3 header */
     public static final byte LENGTH_OF_HEADER = 8;
     private static final byte LENGTH_INDEX_IN_HEADER = 2;
-    private static final Logger LOGGER = LoggerFactory.getLogger(OFFrameDecoder.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(OfFrameDecoder.class);
 
     /**
      * Constructor of class.
      */
-    public OFFrameDecoder() {
+    public OfFrameDecoder() {
         LOGGER.info("Creating OFFrameDecoder");
     }
 
@@ -64,7 +66,7 @@ public class OFFrameDecoder extends ByteToMessageDecoder {
     private static void enableOFVersionDetector(ChannelHandlerContext ctx) {
         if (ctx.pipeline().get(COMPONENT_NAMES.OF_VERSION_DETECTOR.name()) == null) {
             LOGGER.info("Adding OFVD");
-            ctx.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OFVersionDetector());
+            ctx.pipeline().addLast(COMPONENT_NAMES.OF_VERSION_DETECTOR.name(), new OfVersionDetector());
         } else {
             LOGGER.debug("OFVD already in pipeline");
         }
similarity index 84%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/OFVersionDetector.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/OfVersionDetector.java
index 3e5e964c3d11f0cda45144a3adc638947c7189f1..fd126f6bf9b0bbe017be1be7a98eb6715a1cead3 100644 (file)
@@ -1,13 +1,15 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.handler.codec.ByteToMessageDecoder;
+
 import java.util.List;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;
 
 /**
  * Class that detects version of used OpenFlow Protocol and engages right OFCodec into
@@ -15,15 +17,16 @@ import org.openflow.core.TCPHandler.COMPONENT_NAMES;
  *
  * @author michal.polkorab
  */
-public class OFVersionDetector extends ByteToMessageDecoder {
+public class OfVersionDetector extends ByteToMessageDecoder {
 
-    private static final byte OF13_VERSION_ID = 0x04;
-    private static final Logger LOGGER = LoggerFactory.getLogger(OFVersionDetector.class);
+    /** Version number of OpenFlow 1.3 protocol */
+    public static final byte OF13_VERSION_ID = 0x04;
+    private static final Logger LOGGER = LoggerFactory.getLogger(OfVersionDetector.class);
 
     /**
      * Constructor of class.
      */
-    public OFVersionDetector() {
+    public OfVersionDetector() {
         LOGGER.info("Creating OFVersionDetector");
     }
 
@@ -56,7 +59,7 @@ public class OFVersionDetector extends ByteToMessageDecoder {
     private static void enableOF13Codec(ChannelHandlerContext chc) {
         if (chc.pipeline().get(COMPONENT_NAMES.OF_CODEC.name()) == null) {
             LOGGER.info("Engaging OF13Codec");
-            chc.pipeline().addLast(COMPONENT_NAMES.OF_CODEC.name(), new OF13Codec());
+            chc.pipeline().addLast(COMPONENT_NAMES.OF_CODEC.name(), new Of13Codec());
         } else {
             LOGGER.debug("OF13Codec already in pipeline");
         }
similarity index 75%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/PublishingChannelInitializer.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/PublishingChannelInitializer.java
index 8e36fae0c3e543ac607baf6cca5b2bf68ce9598e..9f166054a526bee90c5dadc85c7efc4e71bf34fb 100644 (file)
@@ -1,19 +1,18 @@
-package org.openflow.core;\r
-\r
-import java.util.Iterator;\r
-\r
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;\r
+package org.openflow.lib;\r
 \r
 import io.netty.channel.Channel;\r
 import io.netty.channel.ChannelInitializer;\r
 import io.netty.channel.group.DefaultChannelGroup;\r
-import io.netty.channel.socket.SocketChannel;\r
+\r
+import java.util.Iterator;\r
+\r
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;\r
 \r
 /**\r
  * @author michal.polkorab\r
  *\r
  */\r
-public class PublishingChannelInitializer extends ChannelInitializer<SocketChannel> {\r
+public class PublishingChannelInitializer extends ChannelInitializer<Channel> {\r
 \r
     private DefaultChannelGroup allChannels;\r
     \r
@@ -25,9 +24,9 @@ public class PublishingChannelInitializer extends ChannelInitializer<SocketChann
     }\r
     \r
     @Override\r
-    protected void initChannel(SocketChannel ch) throws Exception {\r
+    protected void initChannel(Channel ch) throws Exception {\r
         allChannels.add(ch);\r
-        ch.pipeline().addLast(COMPONENT_NAMES.TLS_DETECTOR.name(), new TLSDetector());\r
+        ch.pipeline().addLast(COMPONENT_NAMES.TLS_DETECTOR.name(), new TlsDetector());\r
     }\r
     \r
     /**\r
similarity index 98%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/SslContextFactory.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/SslContextFactory.java
index e6fed15d74bb07f53e235a4efc7abcf524c83e56..cc61c3828873c113c6c5a896daf42a92122a7aca 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import java.security.KeyStore;
 import java.security.Security;
similarity index 79%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/SslKeyStore.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/SslKeyStore.java
index 1acc7a6867eee29931417e234d88c220ef7ed7c9..460921c05f421764473e88b9b1def1a04942f3e2 100644 (file)
@@ -1,7 +1,6 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
-import java.io.FileNotFoundException;
 import java.io.InputStream;
 
 /**
@@ -17,10 +16,12 @@ public final class SslKeyStore {
      * InputStream instance of key
      *
      * @return key as InputStream
-     * @throws FileNotFoundException
      */
-    public static InputStream asInputStream() throws FileNotFoundException {
+    public static InputStream asInputStream() {
         InputStream in = SslKeyStore.class.getResourceAsStream(filename);
+        if (in == null) {
+            throw new IllegalStateException("KeyStore file not found: " + filename);
+        }
         return in;
     }
 
similarity index 98%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/SslTrustManagerFactory.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/SslTrustManagerFactory.java
index e656737f4c331e082b5fe46409eef6f19a510010..e37c8edfce5e261590baca5a0cc0fcd68d47f0fd 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import javax.net.ssl.ManagerFactoryParameters;
 import javax.net.ssl.TrustManager;
similarity index 85%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/TCPHandler.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/TcpHandler.java
index cef63bdb0723179e3ae30091e8056a5d3e0dfa6e..bc7d985b0f41d758d68e4687df91b080c23d9682 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import io.netty.bootstrap.ServerBootstrap;
 import io.netty.channel.ChannelFuture;
@@ -9,6 +9,8 @@ import io.netty.channel.socket.nio.NioServerSocketChannel;
 import io.netty.handler.logging.LogLevel;
 import io.netty.handler.logging.LoggingHandler;
 
+import java.net.InetSocketAddress;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -19,12 +21,13 @@ import com.google.common.util.concurrent.SettableFuture;
  *
  * @author michal.polkorab
  */
-public class TCPHandler extends Thread {
+public class TcpHandler extends Thread {
 
     private int port;
+    private String address;
     private NioEventLoopGroup workerGroup;
     private NioEventLoopGroup bossGroup;
-    private static final Logger LOGGER = LoggerFactory.getLogger(TCPHandler.class);
+    private static final Logger LOGGER = LoggerFactory.getLogger(TcpHandler.class);
     private SettableFuture<Boolean> isOnlineFuture;
     
     
@@ -67,7 +70,7 @@ public class TCPHandler extends Thread {
      *
      * @param port listening port of TCPHandler server
      */
-    public TCPHandler(int port) {
+    public TcpHandler(int port) {
         this.port = port;
         channelInitializer = new PublishingChannelInitializer();
         isOnlineFuture = SettableFuture.create();
@@ -91,6 +94,10 @@ public class TCPHandler extends Thread {
                     .childOption(ChannelOption.SO_KEEPALIVE, true);
 
             ChannelFuture f = b.bind(port).sync();
+            
+            InetSocketAddress isa = (InetSocketAddress) f.channel().localAddress();
+            address = isa.getHostName().toString();
+            port = isa.getPort();
             isOnlineFuture.set(true);
             LOGGER.info("Switch listener started and ready to accept incoming connections on port: " + port);
             f.channel().closeFuture().sync();
@@ -102,7 +109,7 @@ public class TCPHandler extends Thread {
     }
 
     /**
-     * Shuts down {@link TCPHandler}}
+     * Shuts down {@link TcpHandler}}
      */
     public void shutdown() {
         workerGroup.shutdownGracefully();
@@ -137,7 +144,7 @@ public class TCPHandler extends Thread {
         } else {
             port = 6633;
         }
-        new TCPHandler(port).start();
+        new TcpHandler(port).start();
     }
     
     /**
@@ -147,4 +154,18 @@ public class TCPHandler extends Thread {
         return isOnlineFuture;
     }
     
+    /**
+     * @return the port
+     */
+    public int getPort() {
+        return port;
+    }
+    
+    /**
+     * @return the address
+     */
+    public String getAddress() {
+        return address;
+    }
+    
 }
similarity index 92%
rename from openflow-protocol-impl/src/main/java/org/openflow/core/TLSDetector.java
rename to openflow-protocol-impl/src/main/java/org/openflow/lib/TlsDetector.java
index 0dbf17168d381a25810289da9520f7d58a42e709..cfd5025cdff928b5d3b1b51345a7994d3fbea3ae 100644 (file)
@@ -1,16 +1,19 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
 import io.netty.channel.ChannelPipeline;
 import io.netty.handler.codec.ByteToMessageDecoder;
 import io.netty.handler.ssl.SslHandler;
+
 import java.util.List;
+
 import javax.net.ssl.SSLEngine;
+
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;
 import org.openflow.util.ByteBufUtils;
 
 /**
@@ -20,16 +23,16 @@ import org.openflow.util.ByteBufUtils;
  *
  * @author michal.polkorab
  */
-public class TLSDetector extends ByteToMessageDecoder {
+public class TlsDetector extends ByteToMessageDecoder {
 
     private boolean detectSsl;
     private static final Logger LOGGER = LoggerFactory
-            .getLogger(TLSDetector.class);
+            .getLogger(TlsDetector.class);
 
     /**
      * Constructor of class
      */
-    public TLSDetector() {
+    public TlsDetector() {
         LOGGER.info("Creating TLS Detector");
         detectSsl = true;
     }
@@ -65,7 +68,7 @@ public class TLSDetector extends ByteToMessageDecoder {
         ChannelPipeline p = ctx.channel().pipeline();
         if (p.get(COMPONENT_NAMES.OF_FRAME_DECODER.name()) == null) {
             LOGGER.debug("Engaging OFFrameDecoder");
-            p.addLast(COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OFFrameDecoder());
+            p.addLast(COMPONENT_NAMES.OF_FRAME_DECODER.name(), new OfFrameDecoder());
         } else {
             LOGGER.debug("OFFD already in pipeline");
         }
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DecoderTable.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DecoderTable.java
new file mode 100644 (file)
index 0000000..4f5fd07
--- /dev/null
@@ -0,0 +1,60 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.openflow.deserialization.factories.EchoReplyMessageFactory;\r
+import org.openflow.deserialization.factories.EchoRequestMessageFactory;\r
+import org.openflow.deserialization.factories.FeaturesReplyMessageFactory;\r
+import org.openflow.deserialization.factories.HelloMessageFactory;\r
+import org.openflow.lib.OfVersionDetector;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class DecoderTable {\r
+    \r
+    private static final short OF13 = OfVersionDetector.OF13_VERSION_ID;\r
+    private Map<MessageTypeCodeKey, OfDeserializer<?>> table;\r
+    private static DecoderTable instance;\r
+    \r
+    \r
+    private DecoderTable() {\r
+        // do nothing\r
+    }\r
+    \r
+    /**\r
+     * @return singleton instance\r
+     */\r
+    public static DecoderTable getInstance() {\r
+        if (instance == null) {\r
+            synchronized (DecoderTable.class) {\r
+                instance = new DecoderTable();\r
+                instance.init();\r
+            }\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    /**\r
+     * Decoder table provisioning\r
+     */\r
+    public void init() {\r
+        table = new HashMap<>();\r
+        table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance());\r
+        table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance());\r
+        table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance());\r
+        table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance());\r
+    }\r
+    \r
+    /**\r
+     * @param msgTypeKey\r
+     * @return decoder for given message types\r
+     */\r
+    public OfDeserializer<?> getDecoder(MessageTypeCodeKey msgTypeKey) {\r
+        return table.get(msgTypeKey);\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DeserializationFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/DeserializationFactory.java
new file mode 100644 (file)
index 0000000..8ffc08b
--- /dev/null
@@ -0,0 +1,65 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ *\r
+ * @author michal.polkorab\r
+ */\r
+public abstract class DeserializationFactory {\r
+\r
+    /**\r
+     * Transforms ByteBuf into correct POJO message\r
+     * @param rawMessage \r
+     * @param version version decoded from OpenFlow protocol message\r
+     * @return correct POJO as DataObject\r
+     */\r
+    public static DataObject bufferToMessage(ByteBuf rawMessage, short version) {\r
+        DataObject dataObject = null;\r
+        short type = rawMessage.readUnsignedByte();\r
+        \r
+        // TODO - check if no change happened, so that skipping length would cause problems\r
+        rawMessage.skipBytes(Short.SIZE / Byte.SIZE);\r
+\r
+        MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type);\r
+        OfDeserializer<?> decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey);\r
+        dataObject = decoder.bufferToMessage(rawMessage, version);\r
+        /* \r
+           Type   Message\r
+            0: HELLO\r
+            1: ERROR\r
+            2: ECHO_REQUEST\r
+            3: ECHO_REPLY\r
+            4: EXPERIMENTER\r
+            5: FEATURES_REQUEST\r
+            6: FEATURES_REPLY\r
+            7: GET_CONFIG_REQUEST\r
+            8: GET_CONFIG_REPLY\r
+            9: SET_CONFIG\r
+            10: PACKET_IN\r
+            11: FLOW_REMOVED\r
+            12: PORT_STATUS\r
+            13: PACKET_OUT\r
+            14: FLOW_MOD\r
+            15: GROUP_MOD\r
+            16: PORT_MOD\r
+            17: TABLE_MOD\r
+            18: MULTIPART_REQUEST\r
+            19: MULTIPART_REPLY\r
+            20: BARRIER_REQUEST\r
+            21: BARRIER_REPLY\r
+            22: QUEUE_GET_CONFIG_REQUEST\r
+            23: QUEUE_GET_CONFIG_REPLY\r
+            24: ROLE_REQUEST\r
+            25: ROLE_REPLY    \r
+            26: GET_ASYNC_REQUEST\r
+            27: GET_ASYNC_REPLY\r
+            28: SET_ASYNC\r
+            29: METER_MOD\r
+        */\r
+        return dataObject;\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/MessageTypeCodeKey.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/MessageTypeCodeKey.java
new file mode 100644 (file)
index 0000000..843265d
--- /dev/null
@@ -0,0 +1,61 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class MessageTypeCodeKey {\r
+\r
+    private final short msgType;\r
+    private final short msgVersion;\r
+\r
+    /**\r
+     * @param msgVersion protocol version\r
+     * @param msgType type code of message\r
+     */\r
+    public MessageTypeCodeKey(short msgVersion, short msgType) {\r
+        this.msgType = msgType;\r
+        this.msgVersion = msgVersion;\r
+    }\r
+\r
+    /**\r
+     * @return the msgType\r
+     */\r
+    public short getMsgType() {\r
+        return msgType;\r
+    }\r
+\r
+    /**\r
+     * @return the msgVersion\r
+     */\r
+    public short getMsgVersion() {\r
+        return msgVersion;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        final int prime = 31;\r
+        int result = 1;\r
+        result = prime * result + msgType;\r
+        result = prime * result + msgVersion;\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (obj == null)\r
+            return false;\r
+        if (getClass() != obj.getClass())\r
+            return false;\r
+        MessageTypeCodeKey other = (MessageTypeCodeKey) obj;\r
+        if (msgType != other.msgType)\r
+            return false;\r
+        if (msgVersion != other.msgVersion)\r
+            return false;\r
+        return true;\r
+    }\r
+    \r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/OfDeserializer.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/deserialization/OfDeserializer.java
new file mode 100644 (file)
index 0000000..4eed289
--- /dev/null
@@ -0,0 +1,25 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ * @param <E> message code type\r
+ */\r
+public interface OfDeserializer<E extends DataObject> {\r
+\r
+    /**\r
+     * Transforms byte message into POJO/DTO (of type E).\r
+     * Assumes that input ByteBuf's readerIndex is pointing on length in OpenFlow header\r
+     * \r
+     * @param rawMessage message as bytes in ByteBuf\r
+     * @param version version of used OF Protocol\r
+     * @return HelloMessage as DataObject\r
+     */\r
+    public abstract E bufferToMessage(ByteBuf rawMessage, short version);\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/EncoderTable.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/EncoderTable.java
new file mode 100644 (file)
index 0000000..a29e51e
--- /dev/null
@@ -0,0 +1,57 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.serialization;\r
+\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+import org.openflow.lib.OfVersionDetector;\r
+import org.openflow.lib.serialization.factories.HelloInputMessageFactory;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EncoderTable {\r
+    \r
+    private static final short OF13 = OfVersionDetector.OF13_VERSION_ID;\r
+    private static EncoderTable instance;\r
+    private Map<MessageTypeKey<?>, OfSerializer<?>> table;\r
+    \r
+\r
+    private EncoderTable() {\r
+        // do nothing\r
+    }\r
+    \r
+    /**\r
+     * @return singleton instance\r
+     */\r
+    public static EncoderTable getInstance() {\r
+        if (instance == null) {\r
+            synchronized (EncoderTable.class) {\r
+                instance = new EncoderTable();\r
+                instance.init();\r
+            }\r
+        }\r
+        return instance;\r
+    }\r
+    \r
+    /**\r
+     * Encoder table provisioning\r
+     */\r
+    public void init() {\r
+        table = new HashMap<>();\r
+        table.put(new MessageTypeKey<>(OF13, HelloInput.class), HelloInputMessageFactory.getInstance());\r
+    }\r
+    \r
+    /**\r
+     * @param msgTypeKey\r
+     * @return encoder for current type of message (msgTypeKey)\r
+     */\r
+    @SuppressWarnings("unchecked")\r
+    public <E extends DataObject> OfSerializer<E> getEncoder(MessageTypeKey<E> msgTypeKey) {\r
+        return (OfSerializer<E>) table.get(msgTypeKey);\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/MessageTypeKey.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/MessageTypeKey.java
new file mode 100644 (file)
index 0000000..d8000ef
--- /dev/null
@@ -0,0 +1,68 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.serialization;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ * @param <E> message type (class)\r
+ *\r
+ */\r
+public class MessageTypeKey<E extends DataObject> {\r
+\r
+    private final Class<E> msgType;\r
+    private final short msgVersion;\r
+    \r
+    /**\r
+     * @param msgVersion protocol version\r
+     * @param msgType type of message\r
+     */\r
+    public MessageTypeKey(short msgVersion, Class<E> msgType) {\r
+        super();\r
+        this.msgType = msgType;\r
+        this.msgVersion = msgVersion;\r
+    }\r
+    \r
+    /**\r
+     * @return msgVersion\r
+     */\r
+    public short getMsgVersion() {\r
+        return msgVersion;\r
+    }\r
+\r
+    /**\r
+     * @return the msgType\r
+     */\r
+    public Class<E> getMsgType() {\r
+        return msgType;\r
+    }\r
+\r
+    @Override\r
+    public int hashCode() {\r
+        final int prime = 31;\r
+        int result = 1;\r
+        result = prime * result + ((msgType == null) ? 0 : msgType.hashCode());\r
+        result = prime * result + msgVersion;\r
+        return result;\r
+    }\r
+\r
+    @Override\r
+    public boolean equals(Object obj) {\r
+        if (this == obj)\r
+            return true;\r
+        if (obj == null)\r
+            return false;\r
+        if (getClass() != obj.getClass())\r
+            return false;\r
+        MessageTypeKey<?> other = (MessageTypeKey<?>) obj;\r
+        if (msgType == null) {\r
+            if (other.msgType != null)\r
+                return false;\r
+        } else if (!msgType.equals(other.msgType))\r
+            return false;\r
+        if (msgVersion != other.msgVersion)\r
+            return false;\r
+        return true;\r
+    }\r
\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/OfSerializer.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/OfSerializer.java
new file mode 100644 (file)
index 0000000..434c663
--- /dev/null
@@ -0,0 +1,22 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.serialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ * @param <E> message type\r
+ */\r
+public interface OfSerializer <E extends DataObject> {\r
+\r
+    /**\r
+     * Transforms POJO/DTO into byte message (ByteBuf).\r
+     * @param version version of used OF Protocol\r
+     * @param out ByteBuf used for output\r
+     * @param message message that will be transformed into ByteBuf\r
+     */\r
+    public abstract void messageToBuffer(short version, ByteBuf out, E message);\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/SerializationFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/SerializationFactory.java
new file mode 100644 (file)
index 0000000..d7214a2
--- /dev/null
@@ -0,0 +1,59 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.serialization;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yangtools.yang.binding.DataObject;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class SerializationFactory {\r
+\r
+    /**\r
+     * Transforms POJO message into ByteBuf\r
+     * @param version version used for encoding received message\r
+     * @param out ByteBuf for storing and sending transformed message\r
+     * @param message POJO message\r
+     */\r
+    public static <E extends DataObject> void messageToBuffer(short version, ByteBuf out, E message) {\r
+        @SuppressWarnings("unchecked")\r
+        MessageTypeKey<E> msgTypeKey = new MessageTypeKey<E>(version, (Class<E>) message.getClass());\r
+        OfSerializer<E> encoder = EncoderTable.getInstance().getEncoder(msgTypeKey);\r
+        encoder.messageToBuffer(version, out, message);\r
+        /* \r
+           Type   Message\r
+            0: HELLO\r
+            1: ERROR\r
+            2: ECHO_REQUEST\r
+            3: ECHO_REPLY\r
+            4: EXPERIMENTER\r
+            5: FEATURES_REQUEST\r
+            6: FEATURES_REPLY\r
+            7: GET_CONFIG_REQUEST\r
+            8: GET_CONFIG_REPLY\r
+            9: SET_CONFIG\r
+            10: PACKET_IN\r
+            11: FLOW_REMOVED\r
+            12: PORT_STATUS\r
+            13: PACKET_OUT\r
+            14: FLOW_MOD\r
+            15: GROUP_MOD\r
+            16: PORT_MOD\r
+            17: TABLE_MOD\r
+            18: MULTIPART_REQUEST\r
+            19: MULTIPART_REPLY\r
+            20: BARRIER_REQUEST\r
+            21: BARRIER_REPLY\r
+            22: QUEUE_GET_CONFIG_REQUEST\r
+            23: QUEUE_GET_CONFIG_REPLY\r
+            24: ROLE_REQUEST\r
+            25: ROLE_REPLY    \r
+            26: GET_ASYNC_REQUEST\r
+            27: GET_ASYNC_REPLY\r
+            28: SET_ASYNC\r
+            29: METER_MOD\r
+        */\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/factories/HelloInputMessageFactory.java b/openflow-protocol-impl/src/main/java/org/openflow/lib/serialization/factories/HelloInputMessageFactory.java
new file mode 100644 (file)
index 0000000..2a7169e
--- /dev/null
@@ -0,0 +1,47 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.serialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;\r
+import org.openflow.lib.OfFrameDecoder;\r
+import org.openflow.lib.serialization.OfSerializer;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class HelloInputMessageFactory implements OfSerializer<HelloInput>{\r
+\r
+    /** Code type of HelloMessage */\r
+    public static final byte MESSAGE_TYPE = 0;\r
+    private static HelloInputMessageFactory instance;\r
+    \r
+    private HelloInputMessageFactory() {\r
+        // do nothing, just singleton\r
+    }\r
+    \r
+    /**\r
+     * @return singleton factory\r
+     */\r
+    public static HelloInputMessageFactory getInstance() {\r
+        if (instance == null) {\r
+            instance = new HelloInputMessageFactory();\r
+        }\r
+        return instance;\r
+    }\r
+\r
+    @Override\r
+    public void messageToBuffer(short version, ByteBuf out, HelloInput 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 - fill list of elements into ByteBuf, check length too\r
+    }\r
+    \r
+    \r
+\r
+    \r
+    \r
+}\r
similarity index 92%
rename from openflow-protocol-impl/src/test/java/org/openflow/core/DummyDecoder.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/DummyDecoder.java
index da231dad028c0b690b31d44eb8ee43a402d6b44b..1e3dcef37e6a161883ab1f3a4d5086a2a5219e7c 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
+package org.openflow.lib;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.ChannelHandlerContext;\r
similarity index 83%
rename from openflow-protocol-impl/src/test/java/org/openflow/core/OFFrameDecoderTest.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/OFFrameDecoderTest.java
index d4eef3cc80108c74fa9adf43639c379b0ce22d9f..9b82c6cd7d052ad7c0d4c0aec19f5514a054f55e 100644 (file)
@@ -1,14 +1,16 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
+package org.openflow.lib;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.embedded.EmbeddedChannel;\r
+\r
 import org.junit.Assert;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
+import org.openflow.lib.OfFrameDecoder;\r
 \r
 /**\r
- * Testing class of {@link OFFrameDecoder}\r
+ * Testing class of {@link OfFrameDecoder}\r
  * @author michal.polkorab\r
  */\r
 public class OFFrameDecoderTest {\r
@@ -20,11 +22,11 @@ public class OFFrameDecoderTest {
      */\r
     @Before\r
     public void setUp() {\r
-        embch = new EmbeddedChannel(new OFFrameDecoder());\r
+        embch = new EmbeddedChannel(new OfFrameDecoder());\r
     }\r
 \r
     /**\r
-     * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
+     * Test of decoding {@link OfFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
      * @throws Exception \r
      */\r
     @Test\r
@@ -39,7 +41,7 @@ public class OFFrameDecoderTest {
     }\r
 \r
     /**\r
-     * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
+     * Test of decoding {@link OfFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
      * @throws Exception \r
      */\r
     @Test\r
@@ -55,7 +57,7 @@ public class OFFrameDecoderTest {
     }\r
 \r
     /**\r
-     * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
+     * Test of decoding {@link OfFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
      * @throws Exception \r
      */\r
     @Test\r
@@ -70,7 +72,7 @@ public class OFFrameDecoderTest {
     }\r
 \r
     /**\r
-     * Test of decoding {@link OFFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
+     * Test of decoding {@link OfFrameDecoder#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)}\r
      * @throws Exception \r
      */\r
     @Test\r
similarity index 81%
rename from openflow-protocol-impl/src/test/java/org/openflow/core/OFVersionDetectorTest.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/OFVersionDetectorTest.java
index 8f4065ad9871be8c74127e88d8196122ee2ac118..dcd822d4d8e7377088c932653d60553a2b99d3a8 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
+package org.openflow.lib;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.embedded.EmbeddedChannel;\r
@@ -7,7 +7,8 @@ import io.netty.channel.embedded.EmbeddedChannel;
 import org.junit.Assert;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;\r
+import org.openflow.lib.OfVersionDetector;\r
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;\r
 \r
 /**\r
  *\r
@@ -22,11 +23,11 @@ public class OFVersionDetectorTest {
      */\r
     @Before\r
     public void setUp() {\r
-        embch = new EmbeddedChannel(new OFVersionDetector());\r
+        embch = new EmbeddedChannel(new OfVersionDetector());\r
     }\r
 \r
     /**\r
-     * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
+     * Test of decode {@link OfVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
      * }\r
      * @throws Exception \r
      */\r
@@ -43,7 +44,7 @@ public class OFVersionDetectorTest {
     }\r
     \r
     /**\r
-     * Test of decode {@link OFVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
+     * Test of decode {@link OfVersionDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List)\r
      * }\r
      * @throws Exception \r
      */\r
similarity index 83%
rename from openflow-protocol-impl/src/test/java/org/openflow/core/TCPHandlerTest.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/TCPHandlerTest.java
index a4a74402ec7485dd40452c2d26d6502d85b3ae40..03bc591536adb604e62a69b044d8e1b3c3ae0af8 100644 (file)
@@ -1,22 +1,20 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.core;
+package org.openflow.lib;
 
 import io.netty.channel.Channel;
 import io.netty.util.concurrent.Future;
 
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.ServerSocket;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.TimeUnit;
 
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
-import org.openflow.clients.SimpleClient;
+import org.openflow.lib.clients.SimpleClient;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -26,17 +24,17 @@ import org.slf4j.LoggerFactory;
  */
 public class TCPHandlerTest {
 
-    /**
-     * 
-     */
+    /** Name of file in which OpenFLow protocol messages are stored in binary format */
     private static final String OF_BINARY_MESSAGE_INPUT_TXT = "OFBinaryMessageInput.txt";
 
     protected static final Logger LOGGER = LoggerFactory
             .getLogger(TCPHandlerTest.class);
 
+    private static final long CONNECTION_TIMEOUT = 2000;
+
     protected int port;
     protected String address;
-    protected TCPHandler tcphandler;
+    protected TcpHandler tcphandler;
 
     /**
      * @throws InterruptedException
@@ -44,14 +42,15 @@ public class TCPHandlerTest {
      */
     @Before
     public void setUp() throws InterruptedException, ExecutionException {
-        getFreePortAndAddress();
-        tcphandler = new TCPHandler(port);
+        tcphandler = new TcpHandler(0);
         tcphandler.start();
         tcphandler.getIsOnlineFuture().get();
+        port = tcphandler.getPort();
+        address = tcphandler.getAddress();
     }
     
     /**
-     * stop {@link TCPHandler}
+     * stop {@link TcpHandler}
      */
     @After
     public void tearDown() {
@@ -59,7 +58,7 @@ public class TCPHandlerTest {
     }
 
     /**
-     * Test of connections in {@link TCPHandler} - accepting connection of 1
+     * Test of connections in {@link TcpHandler} - accepting connection of 1
      * client
      * @throws InterruptedException 
      * @throws ExecutionException 
@@ -84,7 +83,7 @@ public class TCPHandlerTest {
     }
     
     /**
-     * Test of connections in {@link TCPHandler} - accepting connection of 10
+     * Test of connections in {@link TcpHandler} - accepting connection of 10
      * clients
      * @throws InterruptedException 
      * @throws ExecutionException 
@@ -109,7 +108,7 @@ public class TCPHandlerTest {
     }
     
     /**
-     * Test of disconnecting in {@link TCPHandler} - shutting down connection of 10
+     * Test of disconnecting in {@link TcpHandler} - shutting down connection of 10
      * clients
      * @throws InterruptedException 
      * @throws ExecutionException 
@@ -144,13 +143,18 @@ public class TCPHandlerTest {
             sc.start();
         }
         for (SimpleClient sc : clientsHorde) {
-            sc.getIsOnlineFuture().get();
+            try {
+                sc.getIsOnlineFuture().get(CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
+            } catch (Exception e) {
+                LOGGER.error(e.getMessage(), e);
+                throw new ExecutionException(e);
+            }
         }
         return clientsHorde;
     }
     
     /**
-     * Test of disconnecting in {@link TCPHandler} - shutting down connection of 1
+     * Test of disconnecting in {@link TcpHandler} - shutting down connection of 1
      * client
      * @throws InterruptedException 
      * @throws ExecutionException 
@@ -179,20 +183,4 @@ public class TCPHandlerTest {
             toBeDisconnected.sync();
         }
     }
-
-    /**
-     * Finds free port and determines host ip address
-     */
-    private void getFreePortAndAddress() {
-        try {
-            ServerSocket ss = new ServerSocket(0);
-            port = ss.getLocalPort();
-            InetAddress ia = InetAddress.getLocalHost();
-            InetAddress[] all = InetAddress.getAllByName(ia.getHostName());
-            address = all[0].getHostAddress();
-            ss.close();
-        } catch (IOException ex) {
-            LOGGER.error(ex.toString());
-        }
-    }
 }
similarity index 74%
rename from openflow-protocol-impl/src/test/java/org/openflow/core/TLSDetectorTest.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/TLSDetectorTest.java
index 23443bf5ba56d755d0fa8222bd8e7b1e312a751a..c473aa84c6ed537e442b040f00a18a45a5f58e5b 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.openflow.core;\r
+package org.openflow.lib;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.embedded.EmbeddedChannel;\r
@@ -7,7 +7,9 @@ import io.netty.channel.embedded.EmbeddedChannel;
 import org.junit.Assert;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
-import org.openflow.core.TCPHandler.COMPONENT_NAMES;\r
+import org.openflow.lib.TcpHandler;\r
+import org.openflow.lib.TlsDetector;\r
+import org.openflow.lib.TcpHandler.COMPONENT_NAMES;\r
 \r
 /**\r
  *\r
@@ -22,13 +24,13 @@ public class TLSDetectorTest {
      */\r
     @Before\r
     public void setUp() {\r
-        TLSDetector tlsDetector = new TLSDetector();\r
+        TlsDetector tlsDetector = new TlsDetector();\r
         embch = new EmbeddedChannel(new DummyDecoder());\r
-        embch.pipeline().addFirst(TCPHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector);\r
+        embch.pipeline().addFirst(TcpHandler.COMPONENT_NAMES.TLS_DETECTOR.name(), tlsDetector);\r
     }\r
 \r
     /**\r
-     * Test of decode {@link TLSDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) }\r
+     * Test of decode {@link TlsDetector#decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List) }\r
      * @throws Exception \r
      */\r
     @Test\r
similarity index 99%
rename from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClient.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClient.java
index 55048baa61e6cf422fed73c4dd897856316d3804..ca2c680c8fe0013c7cc1f4d56380e244bf06238b 100644 (file)
@@ -1,5 +1,5 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
-package org.openflow.clients;
+package org.openflow.lib.clients;
 
 import io.netty.bootstrap.Bootstrap;
 import io.netty.buffer.ByteBuf;
@@ -73,6 +73,7 @@ public class SimpleClient extends Thread {
     private void init() {
         isOnlineFuture = SettableFuture.create();
     }
+    
     /**
      * Starting class of {@link SimpleClient}
      */
similarity index 75%
rename from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClientHandler.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClientHandler.java
index f2086dc69b28f7b940925abf4c4a38c65739f280..69d5275dedaf509b29df0f7f3b2522c34e5f80f9 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
 \r
-package org.openflow.clients;\r
+package org.openflow.lib.clients;\r
 \r
 import io.netty.buffer.ByteBuf;\r
 import io.netty.channel.ChannelHandlerContext;\r
@@ -43,4 +43,14 @@ public class SimpleClientHandler extends ChannelInboundHandlerAdapter {
         LOGGER.info("SimpleClientHandler - end of read");\r
     }\r
     \r
+/* (non-Javadoc)\r
+     * @see io.netty.channel.ChannelInboundHandlerAdapter#channelActive(io.netty.channel.ChannelHandlerContext)\r
+     */\r
+    @Override\r
+    public void channelActive(ChannelHandlerContext ctx) throws Exception {\r
+        System.out.println("CLIENT IS ACTIVE");\r
+        //super.channelActive(ctx);\r
+    }\r
+    \r
+    \r
 }\r
similarity index 93%
rename from openflow-protocol-impl/src/test/java/org/openflow/clients/SimpleClientInitializer.java
rename to openflow-protocol-impl/src/test/java/org/openflow/lib/clients/SimpleClientInitializer.java
index dc3275215e01ab63b2539e619011193b4650830c..9d121e584fe909e5a46d15d82f07143679e2febe 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */
 
-package org.openflow.clients;
+package org.openflow.lib.clients;
 
 import io.netty.channel.ChannelInitializer;
 import io.netty.channel.ChannelPipeline;
@@ -9,7 +9,7 @@ import io.netty.handler.ssl.SslHandler;
 
 import javax.net.ssl.SSLEngine;
 
-import org.openflow.core.SslContextFactory;
+import org.openflow.lib.SslContextFactory;
 
 import com.google.common.util.concurrent.SettableFuture;
 
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoReplyMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..242f08f
--- /dev/null
@@ -0,0 +1,44 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoOutput;\r
+import org.openflow.deserialization.factories.EchoReplyMessageFactory;\r
+import org.openflow.lib.util.BufferHelper;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoReplyMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO\r
+     */\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
+\r
+        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+    }\r
+    \r
+    /**\r
+     * Testing {@link EchoReplyMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    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
+        Assert.assertArrayEquals(builtByFactory.getData(), data);\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoRequestMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/EchoRequestMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..76baf6e
--- /dev/null
@@ -0,0 +1,43 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.EchoRequestMessage;\r
+import org.openflow.deserialization.factories.EchoRequestMessageFactory;\r
+import org.openflow.lib.util.BufferHelper;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class EchoRequestMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link EchoRequestMessageFactory} for correct translation into POJO\r
+     */\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
+\r
+        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+    }\r
+    \r
+    /**\r
+     * Testing {@link EchoRequestMessageFactory} for correct translation into POJO\r
+     */\r
+    @Test\r
+    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
+\r
+        Assert.assertTrue(builtByFactory.getVersion() == HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/FeaturesReplyMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/FeaturesReplyMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..22968a2
--- /dev/null
@@ -0,0 +1,39 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
+import org.openflow.deserialization.factories.FeaturesReplyMessageFactory;\r
+import org.openflow.lib.util.BufferHelper;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class FeaturesReplyMessageFactoryTest {\r
+\r
+    /**\r
+     * Testing {@link FeaturesReplyMessageFactory} for correct translation into POJO\r
+     */\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
+\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
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/HelloMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/deserialization/factories/HelloMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..c3c8058
--- /dev/null
@@ -0,0 +1,34 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.deserialization.factories;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;\r
+import org.openflow.deserialization.factories.HelloMessageFactory;\r
+import org.openflow.lib.util.BufferHelper;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class HelloMessageFactoryTest {\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
+\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
+\r
+        Assert.assertTrue(builtByFactory.getVersion() == VERSION_YET_SUPPORTED);\r
+        Assert.assertEquals(builtByFactory.getXid().longValue(), 16909060L);\r
+    }\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/serialization/factories/HelloInputMessageFactoryTest.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/serialization/factories/HelloInputMessageFactoryTest.java
new file mode 100644 (file)
index 0000000..5b0f730
--- /dev/null
@@ -0,0 +1,41 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.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.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.openflow.lib.OfFrameDecoder;\r
+import org.openflow.lib.deserialization.factories.HelloMessageFactoryTest;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public class HelloInputMessageFactoryTest {\r
+\r
+    private static final byte HELLO_MESSAGE_CODE_TYPE = 0;\r
+    /**\r
+     * Testing of {@link HelloInputMessageFactory} for correct translation from POJO\r
+     */\r
+    @Test\r
+    public void testWithoutElementsSet() {\r
+        HelloInputBuilder hib = new HelloInputBuilder();\r
+        hib.setVersion(HelloMessageFactoryTest.VERSION_YET_SUPPORTED);\r
+        hib.setXid(16909060L);\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
+    }\r
+\r
+}\r
diff --git a/openflow-protocol-impl/src/test/java/org/openflow/lib/util/BufferHelper.java b/openflow-protocol-impl/src/test/java/org/openflow/lib/util/BufferHelper.java
new file mode 100644 (file)
index 0000000..2471d86
--- /dev/null
@@ -0,0 +1,29 @@
+/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
+package org.openflow.lib.util;\r
+\r
+import io.netty.buffer.ByteBuf;\r
+import io.netty.buffer.UnpooledByteBufAllocator;\r
+\r
+/**\r
+ * @author michal.polkorab\r
+ *\r
+ */\r
+public abstract class BufferHelper {\r
+\r
+    /**\r
+     * \r
+     */\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
+     */\r
+    public static ByteBuf buildBuffer(byte[] payload) {\r
+        ByteBuf bb = UnpooledByteBufAllocator.DEFAULT.buffer();\r
+        bb.writeBytes(XID);\r
+        bb.writeBytes(payload);\r
+        return bb;\r
+    }\r
+\r
+}\r