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