Merge "add basic lib - plugin communication"
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / openflow / deserialization / factories / FeaturesReplyMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.openflow.deserialization.factories;\r
3 \r
4 import io.netty.buffer.ByteBuf;\r
5 \r
6 import java.math.BigInteger;\r
7 \r
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;\r
10 import org.openflow.lib.deserialization.OfDeserializer;\r
11 \r
12 /**\r
13  * @author michal.polkorab\r
14  *\r
15  */\r
16 public class FeaturesReplyMessageFactory implements OfDeserializer<GetFeaturesOutput>{\r
17     \r
18     private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;\r
19     \r
20     private static FeaturesReplyMessageFactory instance;\r
21 \r
22     private FeaturesReplyMessageFactory() {\r
23         // do nothing, just singleton\r
24     }\r
25     \r
26     /**\r
27      * @return singleton factory\r
28      */\r
29     public static FeaturesReplyMessageFactory getInstance() {\r
30         if (instance == null) {\r
31             instance = new FeaturesReplyMessageFactory();\r
32         }\r
33         return instance;\r
34     }\r
35     \r
36     /* (non-Javadoc)\r
37      * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short)\r
38      */\r
39     @Override\r
40     public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
41         GetFeaturesOutputBuilder gfob = new GetFeaturesOutputBuilder();\r
42         gfob.setVersion(version);\r
43         gfob.setXid(rawMessage.readUnsignedInt());\r
44         \r
45         // TODO - unsigned long - check for appropriate process\r
46         byte[] datapathId = new byte[8];\r
47         rawMessage.readBytes(datapathId);\r
48         gfob.setDatapathId(new BigInteger(datapathId));\r
49         \r
50         gfob.setBuffers(rawMessage.readUnsignedInt());\r
51         gfob.setTables(rawMessage.readUnsignedByte());\r
52         gfob.setAuxiliaryId(rawMessage.readUnsignedByte());\r
53         rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
54         gfob.setCapabilities(rawMessage.readUnsignedInt());\r
55         gfob.setReserved(rawMessage.readUnsignedInt());\r
56         return gfob.build();\r
57     }\r
58 \r
59 }\r