Javadoc update
[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.ErrorMessageFactory;\r
12 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.ExperimenterMessageFactory;\r
13 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FeaturesReplyMessageFactory;\r
14 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.FlowRemovedMessageFactory;\r
15 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetAsyncReplyMessageFactory;\r
16 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.GetConfigReplyMessageFactory;\r
17 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.HelloMessageFactory;\r
18 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.MultipartReplyMessageFactory;\r
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10BarrierReplyMessageFactory;\r
20 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoReplyMessageFactory;\r
21 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10EchoRequestMessageFactory;\r
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10ErrorMessageFactory;\r
23 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FeaturesReplyMessageFactory;\r
24 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10FlowRemovedMessageFactory;\r
25 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10GetConfigReplyMessageFactory;\r
26 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10HelloMessageFactory;\r
27 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PacketInMessageFactory;\r
28 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10PortStatusMessageFactory;\r
29 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10QueueGetConfigReplyMessageFactory;\r
30 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10StatsReplyMessageFactory;\r
31 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.OF10VendorMessageFactory;\r
32 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PacketInMessageFactory;\r
33 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.PortStatusMessageFactory;\r
34 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.QueueGetConfigReplyMessageFactory;\r
35 import org.opendaylight.openflowjava.protocol.impl.deserialization.factories.RoleReplyMessageFactory;\r
36 \r
37 /**\r
38  * Stores and provides correct decoders for received messages\r
39  * @author michal.polkorab\r
40  * \r
41  *  <pre>         \r
42  *  Type   Message\r
43  *   0: HELLO\r
44  *   1: ERROR\r
45  *   2: ECHO_REQUEST\r
46  *   3: ECHO_REPLY\r
47  *   4: EXPERIMENTER\r
48  *   5: FEATURES_REQUEST\r
49  *   6: FEATURES_REPLY\r
50  *   7: GET_CONFIG_REQUEST\r
51  *   8: GET_CONFIG_REPLY\r
52  *   9: SET_CONFIG\r
53  *   10: PACKET_IN\r
54  *   11: FLOW_REMOVED\r
55  *   12: PORT_STATUS\r
56  *   13: PACKET_OUT\r
57  *   14: FLOW_MOD\r
58  *   15: GROUP_MOD\r
59  *   16: PORT_MOD\r
60  *   17: TABLE_MOD\r
61  *   18: MULTIPART_REQUEST\r
62  *   19: MULTIPART_REPLY\r
63  *   20: BARRIER_REQUEST\r
64  *   21: BARRIER_REPLY\r
65  *   22: QUEUE_GET_CONFIG_REQUEST\r
66  *   23: QUEUE_GET_CONFIG_REPLY\r
67  *   24: ROLE_REQUEST\r
68  *   25: ROLE_REPLY    \r
69  *   26: GET_ASYNC_REQUEST\r
70  *   27: GET_ASYNC_REPLY\r
71  *   28: SET_ASYNC\r
72  *   29: METER_MOD\r
73  *   </pre>\r
74  */\r
75 public class DecoderTable {\r
76     \r
77     private static final short OF10 = OFVersionDetector.OF10_VERSION_ID;\r
78     private static final short OF13 = OFVersionDetector.OF13_VERSION_ID;\r
79     private Map<MessageTypeCodeKey, OFDeserializer<?>> table;\r
80     private static DecoderTable instance;\r
81     \r
82     \r
83     private DecoderTable() {\r
84         // do nothing\r
85     }\r
86     \r
87     /**\r
88      * @return singleton instance\r
89      */\r
90     public static synchronized DecoderTable getInstance() {\r
91         if (instance == null) {\r
92             instance = new DecoderTable();\r
93             instance.init();\r
94         }\r
95         return instance;\r
96     }\r
97     \r
98     /**\r
99      * Decoder table provisioning\r
100      */\r
101     public void init() {\r
102         table = new HashMap<>();\r
103         table.put(new MessageTypeCodeKey(OF10, (short) 0), OF10HelloMessageFactory.getInstance());\r
104         table.put(new MessageTypeCodeKey(OF10, (short) 1), OF10ErrorMessageFactory.getInstance());\r
105         table.put(new MessageTypeCodeKey(OF10, (short) 2), OF10EchoRequestMessageFactory.getInstance());\r
106         table.put(new MessageTypeCodeKey(OF10, (short) 3), OF10EchoReplyMessageFactory.getInstance());\r
107         table.put(new MessageTypeCodeKey(OF10, (short) 4), OF10VendorMessageFactory.getInstance());\r
108         table.put(new MessageTypeCodeKey(OF10, (short) 6), OF10FeaturesReplyMessageFactory.getInstance());\r
109         table.put(new MessageTypeCodeKey(OF10, (short) 8), OF10GetConfigReplyMessageFactory.getInstance());\r
110         table.put(new MessageTypeCodeKey(OF10, (short) 10), OF10PacketInMessageFactory.getInstance());\r
111         table.put(new MessageTypeCodeKey(OF10, (short) 11), OF10FlowRemovedMessageFactory.getInstance());\r
112         table.put(new MessageTypeCodeKey(OF10, (short) 12), OF10PortStatusMessageFactory.getInstance());\r
113         table.put(new MessageTypeCodeKey(OF10, (short) 16), OF10StatsReplyMessageFactory.getInstance());\r
114         table.put(new MessageTypeCodeKey(OF10, (short) 18), OF10BarrierReplyMessageFactory.getInstance());\r
115         table.put(new MessageTypeCodeKey(OF10, (short) 20), OF10QueueGetConfigReplyMessageFactory.getInstance());\r
116         table.put(new MessageTypeCodeKey(OF13, (short) 0), HelloMessageFactory.getInstance());\r
117         table.put(new MessageTypeCodeKey(OF13, (short) 1), ErrorMessageFactory.getInstance());\r
118         table.put(new MessageTypeCodeKey(OF13, (short) 2), EchoRequestMessageFactory.getInstance());\r
119         table.put(new MessageTypeCodeKey(OF13, (short) 3), EchoReplyMessageFactory.getInstance());\r
120         table.put(new MessageTypeCodeKey(OF13, (short) 4), ExperimenterMessageFactory.getInstance());\r
121         table.put(new MessageTypeCodeKey(OF13, (short) 6), FeaturesReplyMessageFactory.getInstance());\r
122         table.put(new MessageTypeCodeKey(OF13, (short) 8), GetConfigReplyMessageFactory.getInstance());\r
123         table.put(new MessageTypeCodeKey(OF13, (short) 10), PacketInMessageFactory.getInstance());\r
124         table.put(new MessageTypeCodeKey(OF13, (short) 11), FlowRemovedMessageFactory.getInstance());\r
125         table.put(new MessageTypeCodeKey(OF13, (short) 12), PortStatusMessageFactory.getInstance());\r
126         table.put(new MessageTypeCodeKey(OF13, (short) 19), MultipartReplyMessageFactory.getInstance());\r
127         table.put(new MessageTypeCodeKey(OF13, (short) 21), BarrierReplyMessageFactory.getInstance());\r
128         table.put(new MessageTypeCodeKey(OF13, (short) 23), QueueGetConfigReplyMessageFactory.getInstance());\r
129         table.put(new MessageTypeCodeKey(OF13, (short) 25), RoleReplyMessageFactory.getInstance());\r
130         table.put(new MessageTypeCodeKey(OF13, (short) 27), GetAsyncReplyMessageFactory.getInstance());\r
131     }\r
132     \r
133     /**\r
134      * @param msgTypeKey\r
135      * @return decoder for given message types\r
136      */\r
137     public OFDeserializer<?> getDecoder(MessageTypeCodeKey msgTypeKey) {\r
138         return table.get(msgTypeKey);\r
139     }\r
140 \r
141 }\r