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 java.util.ArrayList;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
18 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
19 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
20 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
21 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
22 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueueProperty;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.RateQueuePropertyBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutputBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
36 * @author giuseppex.petralia@intel.com
39 public class QueueGetConfigReplyMessageFactoryTest {
40 private OFSerializer<GetQueueConfigOutput> factory;
41 private static final byte MESSAGE_TYPE = 23;
42 private static final byte PADDING = 4;
43 private static final byte QUEUE_PADDING = 6;
44 private static final byte PROPERTY_HEADER_PADDING = 4;
45 private static final byte PROPERTY_RATE_PADDING = 6;
48 public void startUp() {
49 SerializerRegistry registry = new SerializerRegistryImpl();
52 .getSerializer(new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, GetQueueConfigOutput.class));
56 public void testSerialize() throws Exception {
57 GetQueueConfigOutputBuilder builder = new GetQueueConfigOutputBuilder();
58 BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
59 builder.setPort(new PortNumber(0x00010203L));
60 builder.setQueues(createQueuesList());
61 GetQueueConfigOutput message = builder.build();
63 ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
64 factory.serialize(message, serializedBuffer);
65 BufferHelper.checkHeaderV13(serializedBuffer, MESSAGE_TYPE, 80);
66 Assert.assertEquals("Wrong port", message.getPort().getValue().longValue(), serializedBuffer.readInt());
67 serializedBuffer.skipBytes(PADDING);
69 Assert.assertEquals("Wrong queue Id", message.getQueues().get(0).getQueueId().getValue().longValue(),
70 serializedBuffer.readInt());
71 Assert.assertEquals("Wrong port", message.getQueues().get(0).getPort().getValue().longValue(),
72 serializedBuffer.readInt());
73 Assert.assertEquals("Wrong length", 32, serializedBuffer.readShort());
74 serializedBuffer.skipBytes(QUEUE_PADDING);
75 List<QueueProperty> properties = message.getQueues().get(0).getQueueProperty();
76 Assert.assertEquals("Wrong property", properties.get(0).getProperty().getIntValue(),
77 serializedBuffer.readShort());
78 Assert.assertEquals("Wrong property length", 16, serializedBuffer.readShort());
79 serializedBuffer.skipBytes(PROPERTY_HEADER_PADDING);
80 RateQueueProperty rateQueueProperty = properties.get(0).getAugmentation(RateQueueProperty.class);
81 Assert.assertEquals("Wrong rate", rateQueueProperty.getRate().intValue(), serializedBuffer.readShort());
82 serializedBuffer.skipBytes(PROPERTY_RATE_PADDING);
84 Assert.assertEquals("Wrong queue Id", message.getQueues().get(1).getQueueId().getValue().longValue(),
85 serializedBuffer.readInt());
86 Assert.assertEquals("Wrong queue Id", message.getQueues().get(1).getPort().getValue().longValue(),
87 serializedBuffer.readInt());
88 Assert.assertEquals("Wrong length", 32, serializedBuffer.readShort());
89 serializedBuffer.skipBytes(QUEUE_PADDING);
90 List<QueueProperty> propertiesTwo = message.getQueues().get(1).getQueueProperty();
91 Assert.assertEquals("Wrong property", propertiesTwo.get(0).getProperty().getIntValue(),
92 serializedBuffer.readShort());
93 Assert.assertEquals("Wrong property length", 16, serializedBuffer.readShort());
94 serializedBuffer.skipBytes(PROPERTY_HEADER_PADDING);
95 RateQueueProperty rateQueuePropertyTwo = propertiesTwo.get(0).getAugmentation(RateQueueProperty.class);
96 Assert.assertEquals("Wrong rate", rateQueuePropertyTwo.getRate().intValue(), serializedBuffer.readShort());
97 serializedBuffer.skipBytes(PROPERTY_RATE_PADDING);
101 private static List<Queues> createQueuesList() {
102 List<Queues> queuesList = new ArrayList<>();
103 for (int i = 1; i < 3; i++) {
104 QueuesBuilder qb = new QueuesBuilder();
105 qb.setQueueId(new QueueId((long) i));
106 qb.setPort(new PortNumber((long) i));
107 qb.setQueueProperty(createPropertiesList());
108 queuesList.add(qb.build());
113 private static List<QueueProperty> createPropertiesList() {
114 List<QueueProperty> propertiesList = new ArrayList<>();
115 QueuePropertyBuilder pb = new QueuePropertyBuilder();
116 pb.setProperty(QueueProperties.forValue(2));
117 RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
118 rateBuilder.setRate(5);
119 pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
120 propertiesList.add(pb.build());
121 return propertiesList;