2 * Copyright (c) 2015 NetIDE Consortium and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.openflowjava.util.ByteBufUtils;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.ExperimenterIdQueueProperty;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueueProperty;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
22 * Translates GetQueueConfig messages.
24 * @author giuseppex.petralia@intel.com
26 public class QueueGetConfigReplyMessageFactory implements OFSerializer<GetQueueConfigOutput> {
28 private static final byte MESSAGE_TYPE = 23;
29 private static final byte PADDING = 4;
30 public static final int QUEUE_LENGTH_INDEX = 8;
31 public static final int PROPERTY_LENGTH_INDEX = 2;
32 private static final byte QUEUE_PADDING = 6;
33 private static final byte PROPERTY_HEADER_PADDING = 4;
34 private static final byte PROPERTY_RATE_PADDING = 6;
35 private static final byte PROPERTY_EXPERIMENTER_PADDING = 4;
38 public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) {
39 ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
40 outBuffer.writeInt(message.getPort().getValue().intValue());
41 outBuffer.writeZero(PADDING);
42 for (Queues queue : message.getQueues()) {
43 ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
44 queueBuff.writeInt(queue.getQueueId().getValue().intValue());
45 queueBuff.writeInt(queue.getPort().getValue().intValue());
46 queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
47 queueBuff.writeZero(QUEUE_PADDING);
49 for (QueueProperty property : queue.getQueueProperty()) {
50 ByteBuf propertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
51 propertyBuff.writeShort(property.getProperty().getIntValue());
52 propertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
53 propertyBuff.writeZero(PROPERTY_HEADER_PADDING);
54 switch (property.getProperty()) {
57 serializeRateBody(property.augmentation(RateQueueProperty.class), propertyBuff);
59 case OFPQTEXPERIMENTER:
60 serializeExperimenterBody(property.augmentation(ExperimenterIdQueueProperty.class),
66 propertyBuff.setShort(PROPERTY_LENGTH_INDEX, propertyBuff.readableBytes());
67 queueBuff.writeBytes(propertyBuff);
70 queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes());
71 outBuffer.writeBytes(queueBuff);
73 ByteBufUtils.updateOFHeaderLength(outBuffer);
76 private void serializeRateBody(RateQueueProperty body, ByteBuf outBuffer) {
77 outBuffer.writeShort(body.getRate());
78 outBuffer.writeZero(PROPERTY_RATE_PADDING);
81 private void serializeExperimenterBody(ExperimenterIdQueueProperty body, ByteBuf outBuffer) {
82 // TODO: Experimenter Data is vendor specific that should implement its
84 outBuffer.writeInt(body.getExperimenter().getValue().intValue());
85 outBuffer.writeZero(PROPERTY_EXPERIMENTER_PADDING);