5936c90e3277486f80753bb1d54ec1ac4b24e71c
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FeaturesReplyMessageFactory.java
1 /* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
2 package org.opendaylight.openflowjava.protocol.impl.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.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;\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 synchronized FeaturesReplyMessageFactory getInstance() {\r
30         if (instance == null) {\r
31             instance = new FeaturesReplyMessageFactory();\r
32         }\r
33         return instance;\r
34     }\r
35     \r
36     @Override\r
37     public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
38         GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();\r
39         builder.setVersion(version);\r
40         builder.setXid(rawMessage.readUnsignedInt());\r
41         byte[] datapathId = new byte[Long.SIZE/Byte.SIZE];\r
42         rawMessage.readBytes(datapathId);\r
43         builder.setDatapathId(new BigInteger(datapathId));\r
44         builder.setBuffers(rawMessage.readUnsignedInt());\r
45         builder.setTables(rawMessage.readUnsignedByte());\r
46         builder.setAuxiliaryId(rawMessage.readUnsignedByte());\r
47         rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
48         builder.setCapabilities(rawMessage.readUnsignedInt());\r
49         builder.setReserved(rawMessage.readUnsignedInt());\r
50         return builder.build();\r
51     }\r
52 \r
53 }\r