X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflow-protocol-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowjava%2Fprotocol%2Fimpl%2Fdeserialization%2Ffactories%2FQueueGetConfigReplyMessageFactory.java;h=6d6f77477598154da47636aec5d3fb5ed2316a74;hb=29a2a074c78708f6d18583779ece96bb6573f0c6;hp=edcf8883907203b467f1cc2a62a30112469f658b;hpb=ff2f581fe0e7a7138dc765cfe713bc2d0791297e;p=openflowjava.git diff --git a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java index edcf8883..6d6f7747 100644 --- a/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java +++ b/openflow-protocol-impl/src/main/java/org/opendaylight/openflowjava/protocol/impl/deserialization/factories/QueueGetConfigReplyMessageFactory.java @@ -1,82 +1,107 @@ -/* Copyright (C)2013 Pantheon Technologies, s.r.o. All rights reserved. */ -package org.opendaylight.openflowjava.protocol.impl.deserialization.factories; - -import java.util.ArrayList; -import java.util.List; - -import io.netty.buffer.ByteBuf; - -import org.opendaylight.openflowjava.protocol.impl.deserialization.OFDeserializer; -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.QueueProperty; -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.packet.queue.Properties; -import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.packet.queue.PropertiesBuilder; -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; - -/** - * @author timotej.kubas - * @author michal.polkorab - */ -public class QueueGetConfigReplyMessageFactory implements OFDeserializer { - - private static QueueGetConfigReplyMessageFactory instance; - 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 QueueGetConfigReplyMessageFactory() { - // singleton - } - - /** - * - * @return singleton factory - */ - public static synchronized QueueGetConfigReplyMessageFactory getInstance(){ - - if(instance == null){ - instance = new QueueGetConfigReplyMessageFactory(); - } - return instance; - } - - @Override - public GetQueueConfigOutput bufferToMessage(ByteBuf rawMessage, short version) { - GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder(); - builder.setVersion(version); - 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 static List createQueuesList(ByteBuf input){ - List queuesList = new ArrayList<>(); - QueuesBuilder queueBuilder = new QueuesBuilder(); - while (input.readableBytes() > 0) { - queueBuilder.setQueueId(new QueueId(input.readUnsignedInt())); - queueBuilder.setPort(new PortNumber(input.readUnsignedInt())); - input.skipBytes(2); - input.skipBytes(PADDING_IN_PACKET_QUEUE_HEADER); - queueBuilder.setProperties(createPropertiesList(input)); - queuesList.add(queueBuilder.build()); - } - return queuesList; - } - - private static List createPropertiesList(ByteBuf propertiesInput){ - List propertiesList = new ArrayList<>(); - PropertiesBuilder propertiesBuilder = new PropertiesBuilder(); - propertiesBuilder.setProperty(QueueProperty.forValue(propertiesInput.readUnsignedShort())); - propertiesInput.skipBytes(2); - propertiesInput.skipBytes(PADDING_IN_QUEUE_PROPERTY_HEADER); - propertiesList.add(propertiesBuilder.build()); - return propertiesList; - } - -} +/* + * 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.rev150225.RateQueueProperty; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.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, + 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 createQueuesList(ByteBuf input){ + List 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 createPropertiesList(ByteBuf input, int length){ + int propertiesLength = length; + List 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 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; + } +}