Renamed packages to org.opendaylight.openflowjava.protocol.impl.*
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / DecoderTable.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.deserialization;\r
3 \r
4 import java.util.HashMap;\r
5 import java.util.Map;\r
6 \r
7 import org.opendaylight.openflowjava.protocol.impl.core.OFVersionDetector;\r
8 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.BarrierReplyMessageFactory;\r
9 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoReplyMessageFactory;\r
10 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.EchoRequestMessageFactory;\r
11 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;\r
12 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;\r
13 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;\r
14 \r
15 /**\r
16  * @author michal.polkorab\r
17  * \r
18  *  <pre>         \r
19  *  Type   Message\r
20  *   0: HELLO\r
21  *   1: ERROR\r
22  *   2: ECHO_REQUEST\r
23  *   3: ECHO_REPLY\r
24  *   4: EXPERIMENTER\r
25  *   5: FEATURES_REQUEST\r
26  *   6: FEATURES_REPLY\r
27  *   7: GET_CONFIG_REQUEST\r
28  *   8: GET_CONFIG_REPLY\r
29  *   9: SET_CONFIG\r
30  *   10: PACKET_IN\r
31  *   11: FLOW_REMOVED\r
32  *   12: PORT_STATUS\r
33  *   13: PACKET_OUT\r
34  *   14: FLOW_MOD\r
35  *   15: GROUP_MOD\r
36  *   16: PORT_MOD\r
37  *   17: TABLE_MOD\r
38  *   18: MULTIPART_REQUEST\r
39  *   19: MULTIPART_REPLY\r
40  *   20: BARRIER_REQUEST\r
41  *   21: BARRIER_REPLY\r
42  *   22: QUEUE_GET_CONFIG_REQUEST\r
43  *   23: QUEUE_GET_CONFIG_REPLY\r
44  *   24: ROLE_REQUEST\r
45  *   25: ROLE_REPLY    \r
46  *   26: GET_ASYNC_REQUEST\r
47  *   27: GET_ASYNC_REPLY\r
48  *   28: SET_ASYNC\r
49  *   29: METER_MOD\r
50  *   </pre>\r
51  */\r
52 public class DecoderTable {\r
53     \r
54     private static final short OF13 = OFVersionDetector.OF13_VERSION_ID;\r
55     private Map<MessageTypeCodeKey, OFDeserializer<?>> table;\r
56     private static DecoderTable instance;\r
57     \r
58     \r
59     private DecoderTable() {\r
60         // do nothing\r
61     }\r
62     \r
63     /**\r
64      * @return singleton instance\r
65      */\r
66     public static DecoderTable getInstance() {\r
67         if (instance == null) {\r
68             synchronized (DecoderTable.class) {\r
69                 instance = new DecoderTable();\r
70                 instance.init();\r
71             }\r
72         }\r
73         return instance;\r
74     }\r
75     \r
76     /**\r
77      * Decoder table provisioning\r
78      */\r
79     public void init() {\r
80         table = new HashMap<>();\r
81         table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance());\r
82         table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance());\r
83         table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance());\r
84         table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance());\r
85         table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance());\r
86         table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance());\r
87     }\r
88     \r
89     /**\r
90      * @param msgTypeKey\r
91      * @return decoder for given message types\r
92      */\r
93     public OFDeserializer<?> getDecoder(MessageTypeCodeKey msgTypeKey) {\r
94         return table.get(msgTypeKey);\r
95     }\r
96 \r
97 }\r