Remove trailing whitespace
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactory.java
index 9422b3b7a22d0d77ec73e5d5bb8c37e4f2c82242..d6090a3254b0fede2a591eb79f8775be70409d42 100644 (file)
-/* 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.util.ArrayList;\r
-import java.util.List;\r
-\r
-import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterQueuePropertyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;\r
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;\r
-\r
-/**\r
- * Translates QueueGetConfigReply messages\r
- * @author timotej.kubas\r
- * @author michal.polkorab\r
- */\r
-public class QueueGetConfigReplyMessageFactory implements OFDeserializer<GetQueueConfigOutput> {\r
-\r
-    private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4;\r
-    private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6;\r
-    private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4;\r
-    private static final int PADDING_IN_RATE_QUEUE_PROPERTY = 6;\r
-    private static final int PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY = 4;\r
-    private static final byte PACKET_QUEUE_LENGTH = 16;\r
-\r
-    private static QueueGetConfigReplyMessageFactory instance;\r
-    \r
-    private QueueGetConfigReplyMessageFactory() {\r
-        // singleton\r
-    }\r
-    \r
-    /**\r
-     * \r
-     * @return singleton factory\r
-     */\r
-    public static synchronized QueueGetConfigReplyMessageFactory getInstance(){\r
-        \r
-        if(instance == null){\r
-            instance = new QueueGetConfigReplyMessageFactory();\r
-        }\r
-        return instance;\r
-    }\r
-    \r
-    @Override\r
-    public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) {\r
-        GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder();\r
-        builder.setVersion(version);\r
-        builder.setXid((rawMessage.readUnsignedInt()));\r
-        builder.setPort(new PortNumber(rawMessage.readUnsignedInt()));\r
-        rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER);\r
-        builder.setQueues(createQueuesList(rawMessage));\r
-        return builder.build();\r
-    }\r
-    \r
-    private static List<Queues> createQueuesList(ByteBuf input){\r
-        List<Queues> queuesList = new ArrayList<>();\r
-        while (input.readableBytes() > 0) {\r
-            QueuesBuilder queueBuilder = new QueuesBuilder();\r
-            queueBuilder.setQueueId(new QueueId(input.readUnsignedInt()));\r
-            queueBuilder.setPort(new PortNumber(input.readUnsignedInt()));\r
-            int length = input.readUnsignedShort();\r
-            input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER);\r
-            queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH));\r
-            queuesList.add(queueBuilder.build());\r
-        } \r
-        return queuesList;\r
-    }\r
-    \r
-    private static List<QueueProperty> createPropertiesList(ByteBuf input, int length){\r
-        int propertiesLength = length;\r
-        List<QueueProperty> propertiesList = new ArrayList<>();\r
-        while (propertiesLength > 0) {\r
-            QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder();\r
-            QueueProperties property = QueueProperties.forValue(input.readUnsignedShort());\r
-            propertiesBuilder.setProperty(property);\r
-            int currentPropertyLength = input.readUnsignedShort();\r
-            propertiesLength -= currentPropertyLength;\r
-            input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER);\r
-            if (property.equals(QueueProperties.OFPQTMINRATE) || property.equals(QueueProperties.OFPQTMAXRATE)) {\r
-                RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();\r
-                rateBuilder.setRate(input.readUnsignedShort());\r
-                propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build());\r
-                input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY);\r
-            } else if (property.equals(QueueProperties.OFPQTEXPERIMENTER)) {\r
-                ExperimenterQueuePropertyBuilder expBuilder = new ExperimenterQueuePropertyBuilder();\r
-                expBuilder.setExperimenter(input.readUnsignedInt());\r
-                input.skipBytes(PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY);\r
-                expBuilder.setData(input.readBytes(currentPropertyLength\r
-                        - Integer.SIZE / Byte.SIZE - PADDING_IN_EXPERIMENTER_QUEUE_PROPERTY).array());\r
-                propertiesBuilder.addAugmentation(RateQueueProperty.class, expBuilder.build());\r
-            }\r
-            propertiesList.add(propertiesBuilder.build());\r
-        }\r
-        return propertiesList;\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.util.ArrayList;
+import java.util.List;
+
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
+import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistryInjector;
+import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
+import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
+import org.opendaylight.openflowjava.util.ExperimenterDeserializerKeyFactory;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
+
+/**
+ * Translates QueueGetConfigReply messages
+ * @author timotej.kubas
+ * @author michal.polkorab
+ */
+public class QueueGetConfigReplyMessageFactory implements OFDeserializer<GetQueueConfigOutput>,
+        DeserializerRegistryInjector {
+
+    private static final byte PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER = 4;
+    private static final byte PADDING_IN_PACKET_QUEUE_HEADER = 6;
+    private static final byte PADDING_IN_QUEUE_PROPERTY_HEADER = 4;
+    private static final int PADDING_IN_RATE_QUEUE_PROPERTY = 6;
+    private static final byte PACKET_QUEUE_LENGTH = 16;
+    private DeserializerRegistry registry;
+
+    @Override
+    public GetQueueConfigOutput deserialize(ByteBuf rawMessage) {
+        GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder();
+        builder.setVersion((short) EncodeConstants.OF13_VERSION_ID);
+        builder.setXid((rawMessage.readUnsignedInt()));
+        builder.setPort(new PortNumber(rawMessage.readUnsignedInt()));
+        rawMessage.skipBytes(PADDING_IN_QUEUE_GET_CONFIG_REPLY_HEADER);
+        builder.setQueues(createQueuesList(rawMessage));
+        return builder.build();
+    }
+
+    private List<Queues> createQueuesList(ByteBuf input){
+        List<Queues> queuesList = new ArrayList<>();
+        while (input.readableBytes() > 0) {
+            QueuesBuilder queueBuilder = new QueuesBuilder();
+            queueBuilder.setQueueId(new QueueId(input.readUnsignedInt()));
+            queueBuilder.setPort(new PortNumber(input.readUnsignedInt()));
+            int length = input.readUnsignedShort();
+            input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER);
+            queueBuilder.setQueueProperty(createPropertiesList(input, length - PACKET_QUEUE_LENGTH));
+            queuesList.add(queueBuilder.build());
+        }
+        return queuesList;
+    }
+
+    private List<QueueProperty> createPropertiesList(ByteBuf input, int length){
+        int propertiesLength = length;
+        List<QueueProperty> propertiesList = new ArrayList<>();
+        while (propertiesLength > 0) {
+            int propertyStartIndex = input.readerIndex();
+            QueuePropertyBuilder propertiesBuilder = new QueuePropertyBuilder();
+            QueueProperties property = QueueProperties.forValue(input.readUnsignedShort());
+            propertiesBuilder.setProperty(property);
+            int currentPropertyLength = input.readUnsignedShort();
+            propertiesLength -= currentPropertyLength;
+            input.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER);
+            if (property.equals(QueueProperties.OFPQTMINRATE) || property.equals(QueueProperties.OFPQTMAXRATE)) {
+                RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
+                rateBuilder.setRate(input.readUnsignedShort());
+                propertiesBuilder.addAugmentation(RateQueueProperty.class, rateBuilder.build());
+                input.skipBytes(PADDING_IN_RATE_QUEUE_PROPERTY);
+            } else if (property.equals(QueueProperties.OFPQTEXPERIMENTER)) {
+                long expId = input.readUnsignedInt();
+                input.readerIndex(propertyStartIndex);
+                OFDeserializer<QueueProperty> deserializer = registry.getDeserializer(
+                        ExperimenterDeserializerKeyFactory.createQueuePropertyDeserializerKey(
+                                EncodeConstants.OF13_VERSION_ID, expId));
+                propertiesList.add(deserializer.deserialize(input));
+                continue;
+            }
+            propertiesList.add(propertiesBuilder.build());
+        }
+        return propertiesList;
+    }
+
+    @Override
+    public void injectDeserializerRegistry(DeserializerRegistry deserializerRegistry) {
+        this.registry = deserializerRegistry;
+    }
+}