Merge "add basic lib - plugin communication"
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / openflow / lib / deserialization / DeserializationFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.openflow.lib.deserialization;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import org.opendaylight.yangtools.yang.binding.DataObject;\r
7 \r
8 /**\r
9  *\r
10  * @author michal.polkorab\r
11  */\r
12 public abstract class DeserializationFactory {\r
13 \r
14     /**\r
15      * Transforms ByteBuf into correct POJO message\r
16      * @param rawMessage \r
17      * @param version version decoded from OpenFlow protocol message\r
18      * @return correct POJO as DataObject\r
19      */\r
20     public static DataObject bufferToMessage(ByteBuf rawMessage, short version) {\r
21         DataObject dataObject = null;\r
22         short type = rawMessage.readUnsignedByte();\r
23         \r
24         // TODO - check if no change happened, so that skipping length would cause problems\r
25         rawMessage.skipBytes(Short.SIZE / Byte.SIZE);\r
26 \r
27         MessageTypeCodeKey msgTypeCodeKey = new MessageTypeCodeKey(version, type);\r
28         OfDeserializer<?> decoder = DecoderTable.getInstance().getDecoder(msgTypeCodeKey);\r
29         dataObject = decoder.bufferToMessage(rawMessage, version);\r
30         /* \r
31            Type   Message\r
32             0: HELLO\r
33             1: ERROR\r
34             2: ECHO_REQUEST\r
35             3: ECHO_REPLY\r
36             4: EXPERIMENTER\r
37             5: FEATURES_REQUEST\r
38             6: FEATURES_REPLY\r
39             7: GET_CONFIG_REQUEST\r
40             8: GET_CONFIG_REPLY\r
41             9: SET_CONFIG\r
42             10: PACKET_IN\r
43             11: FLOW_REMOVED\r
44             12: PORT_STATUS\r
45             13: PACKET_OUT\r
46             14: FLOW_MOD\r
47             15: GROUP_MOD\r
48             16: PORT_MOD\r
49             17: TABLE_MOD\r
50             18: MULTIPART_REQUEST\r
51             19: MULTIPART_REPLY\r
52             20: BARRIER_REQUEST\r
53             21: BARRIER_REPLY\r
54             22: QUEUE_GET_CONFIG_REQUEST\r
55             23: QUEUE_GET_CONFIG_REPLY\r
56             24: ROLE_REQUEST\r
57             25: ROLE_REPLY    \r
58             26: GET_ASYNC_REQUEST\r
59             27: GET_ASYNC_REPLY\r
60             28: SET_ASYNC\r
61             29: METER_MOD\r
62         */\r
63         return dataObject;\r
64     }\r
65 }\r