Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / FeaturesReplyMessageFactory.java
index cb111cff0eb919867185d9f041c32804768fe10b..b599c208dfb0c21db5d471d059dfd504ebac6abd 100644 (file)
@@ -1,58 +1,59 @@
-/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */\r
-package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;\r
-\r
-import io.netty.buffer.ByteBuf;\r
-\r
-import java.math.BigInteger;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{\r
-    \r
-    private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;\r
-    \r
-    private static FeaturesReplyMessageFactory instance;\r
-\r
-    private FeaturesReplyMessageFactory() {\r
-        // do nothing, just singleton\r
-    }\r
-    \r
-    /**\r
-     * @return singleton factory\r
-     */\r
-    public static FeaturesReplyMessageFactory getInstance() {\r
-        if (instance == null) {\r
-            instance = new FeaturesReplyMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    /* (non-Javadoc)\r
-     * @see org.openflow.core.deserialization.OfDeserializer#createMessage(io.netty.buffer.ByteBuf, short)\r
-     */\r
-    @Override\r
-    public GetFeaturesOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
-        GetFeaturesOutputBuilder gfob = new GetFeaturesOutputBuilder();\r
-        gfob.setVersion(version);\r
-        gfob.setXid(rawMessage.readUnsignedInt());\r
-        \r
-        // TODO - unsigned long - check for appropriate process\r
-        byte[] datapathId = new byte[8];\r
-        rawMessage.readBytes(datapathId);\r
-        gfob.setDatapathId(new BigInteger(datapathId));\r
-        gfob.setBuffers(rawMessage.readUnsignedInt());\r
-        gfob.setTables(rawMessage.readUnsignedByte());\r
-        gfob.setAuxiliaryId(rawMessage.readUnsignedByte());\r
-        rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);\r
-        gfob.setCapabilities(rawMessage.readUnsignedInt());\r
-        gfob.setReserved(rawMessage.readUnsignedInt());\r
-        return gfob.build();\r
-    }\r
-\r
-}\r
+/*
+ * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
+
+import io.netty.buffer.ByteBuf;
+
+import java.math.BigInteger;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.Capabilities;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetFeaturesOutputBuilder;
+
+/**
+ * Translates FeaturesReply messages
+ * @author michal.polkorab
+ * @author timotej.kubas
+ */
+public class FeaturesReplyMessageFactory implements OFDeserializer<GetFeaturesOutput>{
+
+    private static final byte PADDING_IN_FEATURES_REPLY_HEADER = 2;
+
+    @Override
+    public GetFeaturesOutput deserialize(ByteBuf rawMessage) {
+        GetFeaturesOutputBuilder builder = new GetFeaturesOutputBuilder();
+        builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
+        builder.setXid(rawMessage.readUnsignedInt());
+        byte[] datapathId = new byte[EncodeConstants.SIZE_OF_LONG_IN_BYTES];
+        rawMessage.readBytes(datapathId);
+        builder.setDatapathId(new BigInteger(1, datapathId));
+        builder.setBuffers(rawMessage.readUnsignedInt());
+        builder.setTables(rawMessage.readUnsignedByte());
+        builder.setAuxiliaryId(rawMessage.readUnsignedByte());
+        rawMessage.skipBytes(PADDING_IN_FEATURES_REPLY_HEADER);
+        builder.setCapabilities(createCapabilities(rawMessage.readUnsignedInt()));
+        builder.setReserved(rawMessage.readUnsignedInt());
+        return builder.build();
+    }
+
+    private static Capabilities createCapabilities(long input) {
+        final Boolean flowStats = (input & (1 << 0)) != 0;
+        final Boolean tableStats = (input & (1 << 1)) != 0;
+        final Boolean portStats = (input & (1 << 2)) != 0;
+        final Boolean groupStats = (input & (1 << 3)) != 0;
+        final Boolean ipReasm = (input & (1 << 5)) != 0;
+        final Boolean queueStats = (input & (1 << 6)) != 0;
+        final Boolean portBlocked = (input & (1 << 8)) != 0;
+        return new Capabilities(flowStats, groupStats, ipReasm,
+                portBlocked, portStats, queueStats, tableStats);
+    }
+
+}