Copyright update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / DecoderTable.java
index 0013b433984bcc1338f57195c17b8497878ca87c..e1734405208e5a9ce4ee3d67cbfd5259599d263d 100644 (file)
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
-\r
-import java.util.HashMap;\r
-import java.util.Map;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10VendorMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory;\r
-import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;\r
-\r
-/**\r
- * Stores and provides correct decoders for received messages\r
- * @author michal.polkorab\r
- * \r
- *  <pre>         \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
- *   </pre>\r
- */\r
-public class DecoderTable {\r
-    \r
-    private static final short OF10 = EncodeConstants.OF10_VERSION_ID;\r
-    private static final short OF13 = EncodeConstants.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 synchronized DecoderTable getInstance() {\r
-        if (instance == null) {\r
-            instance = new DecoderTable();\r
-            instance.init();\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(OF10, (short) 0), OF10HelloMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 2), EchoRequestMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 3), EchoReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 8), GetConfigReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 16), OF10StatsReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 18), BarrierReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF10, (short) 20), OF10QueueGetConfigReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.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) 4), ExperimenterMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance());\r
-        table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.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
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.deserialization;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ErrorMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10VendorMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory;
+import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
+
+/**
+ * Stores and provides correct decoders for received messages
+ * @author michal.polkorab
+ * 
+ *  <pre>         
+ *  Type   Message
+ *   0: HELLO
+ *   1: ERROR
+ *   2: ECHO_REQUEST
+ *   3: ECHO_REPLY
+ *   4: EXPERIMENTER
+ *   5: FEATURES_REQUEST
+ *   6: FEATURES_REPLY
+ *   7: GET_CONFIG_REQUEST
+ *   8: GET_CONFIG_REPLY
+ *   9: SET_CONFIG
+ *   10: PACKET_IN
+ *   11: FLOW_REMOVED
+ *   12: PORT_STATUS
+ *   13: PACKET_OUT
+ *   14: FLOW_MOD
+ *   15: GROUP_MOD
+ *   16: PORT_MOD
+ *   17: TABLE_MOD
+ *   18: MULTIPART_REQUEST
+ *   19: MULTIPART_REPLY
+ *   20: BARRIER_REQUEST
+ *   21: BARRIER_REPLY
+ *   22: QUEUE_GET_CONFIG_REQUEST
+ *   23: QUEUE_GET_CONFIG_REPLY
+ *   24: ROLE_REQUEST
+ *   25: ROLE_REPLY    
+ *   26: GET_ASYNC_REQUEST
+ *   27: GET_ASYNC_REPLY
+ *   28: SET_ASYNC
+ *   29: METER_MOD
+ *   </pre>
+ */
+public class DecoderTable {
+    
+    private static final short OF10 = EncodeConstants.OF10_VERSION_ID;
+    private static final short OF13 = EncodeConstants.OF13_VERSION_ID;
+    private Map<MessageTypeCodeKey, OFDeserializer<?>> table;
+    private static DecoderTable instance;
+    
+    
+    private DecoderTable() {
+        // do nothing
+    }
+    
+    /**
+     * @return singleton instance
+     */
+    public static synchronized DecoderTable getInstance() {
+        if (instance == null) {
+            instance = new DecoderTable();
+            instance.init();
+        }
+        return instance;
+    }
+    
+    /**
+     * Decoder table provisioning
+     */
+    public void init() {
+        table = new HashMap<>();
+        table.put(new MessageTypeCodeKey(OF10, (short) 0), OF10HelloMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 2), EchoRequestMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 3), EchoReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 8), GetConfigReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 16), OF10StatsReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 18), BarrierReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF10, (short) 20), OF10QueueGetConfigReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance());
+        table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance());
+    }
+    
+    /**
+     * @param msgTypeKey
+     * @return decoder for given message types
+     */
+    public OFDeserializer<?> getDecoder(MessageTypeCodeKey msgTypeKey) {
+        return table.get(msgTypeKey);
+    }
+
+}