Fixup Augmentable and Identifiable methods changing
[openflowplugin.git] / openflowjava / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10QueueGetConfigReplyMessageFactory.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.openflowjava.protocol.impl.serialization.factories;
9
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.RateQueueProperty;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
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;
20
21 /**
22  * Translates QueueGetConfigReply messages.
23  *
24  * @author giuseppex.petralia@intel.com
25  */
26 public class OF10QueueGetConfigReplyMessageFactory implements OFSerializer<GetQueueConfigOutput> {
27
28     private static final byte MESSAGE_TYPE = 21;
29     private static final byte PADDING = 6;
30     private static final int QUEUE_LENGTH_INDEX = 4;
31     private static final byte QUEUE_PADDING = 2;
32     private static final byte QUEUE_PROPERTY_PADDING = 6;
33     private static final int QUEUE_PROPERTY_LENGTH_INDEX = 2;
34
35     @Override
36     public void serialize(GetQueueConfigOutput message, ByteBuf outBuffer) {
37         ByteBufUtils.writeOFHeader(MESSAGE_TYPE, message, outBuffer, EncodeConstants.EMPTY_LENGTH);
38         outBuffer.writeShort(message.getPort().getValue().intValue());
39         outBuffer.writeZero(PADDING);
40         for (Queues queue : message.getQueues()) {
41             ByteBuf queueBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
42             queueBuff.writeInt(queue.getQueueId().getValue().intValue());
43             queueBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
44             queueBuff.writeZero(QUEUE_PADDING);
45             for (QueueProperty queueProperty : queue.getQueueProperty()) {
46                 ByteBuf queuePropertyBuff = UnpooledByteBufAllocator.DEFAULT.buffer();
47                 queuePropertyBuff.writeShort(queueProperty.getProperty().getIntValue());
48                 queuePropertyBuff.writeShort(EncodeConstants.EMPTY_LENGTH);
49                 queuePropertyBuff.writeZero(4);
50                 if (queueProperty.getProperty() == QueueProperties.OFPQTMINRATE) {
51                     RateQueueProperty body = queueProperty.augmentation(RateQueueProperty.class);
52                     queuePropertyBuff.writeShort(body.getRate().intValue());
53                     queuePropertyBuff.writeZero(QUEUE_PROPERTY_PADDING);
54                 }
55                 queuePropertyBuff.setShort(QUEUE_PROPERTY_LENGTH_INDEX, queuePropertyBuff.readableBytes());
56                 queueBuff.writeBytes(queuePropertyBuff);
57             }
58             queueBuff.setShort(QUEUE_LENGTH_INDEX, queueBuff.readableBytes());
59             outBuffer.writeBytes(queueBuff);
60         }
61
62         ByteBufUtils.updateOFHeaderLength(outBuffer);
63     }
64 }