2 * Copyright (c) 2013 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
11 import io.netty.buffer.ByteBuf;
13 import java.util.ArrayList;
14 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
20 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageCodeKey;
21 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
22 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
23 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
24 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueueProperty;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.RateQueuePropertyBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueId;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.QueueProperties;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.GetQueueConfigOutput;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.Queues;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.get.config.reply.QueuesBuilder;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueueProperty;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.queue.property.header.QueuePropertyBuilder;
37 * @author timotej.kubas
38 * @author michal.polkorab
40 public class QueueGetConfigReplyMessageFactoryMultiTest {
42 private OFDeserializer<GetQueueConfigOutput> queueFactory;
45 * Initializes deserializer registry and lookups correct deserializer
48 public void startUp() {
49 DeserializerRegistry registry = new DeserializerRegistryImpl();
51 queueFactory = registry.getDeserializer(
52 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class));
56 * Testing of {@link QueueGetConfigReplyMessageFactory} for correct
57 * translation into POJO
61 ByteBuf bb = BufferHelper.buildBuffer("00 01 02 03 " + // port
62 "00 00 00 00 " + // padding
63 "00 00 00 01 " + // queueId
64 "00 00 00 01 " + // port
66 "00 00 00 00 00 00 " + // pad
67 "00 02 " + // property
69 "00 00 00 00 " + // pad
71 "00 00 00 00 00 00 " + // pad
72 "00 00 00 02 " + // queueId
73 "00 00 00 02 " + // port
75 "00 00 00 00 00 00 " + // pad
76 "00 02 " + // property
78 "00 00 00 00 " + // pad
80 "00 00 00 00 00 00" // pad
83 GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(
86 BufferHelper.checkHeaderV13(builtByFactory);
87 Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());
88 Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());
91 private static List<Queues> createQueuesList() {
92 List<Queues> queuesList = new ArrayList<>();
93 for (int i = 1; i < 3; i++) {
94 QueuesBuilder qb = new QueuesBuilder();
95 qb.setQueueId(new QueueId((long) i));
96 qb.setPort(new PortNumber((long) i));
97 qb.setQueueProperty(createPropertiesList());
98 queuesList.add(qb.build());
103 private static List<QueueProperty> createPropertiesList() {
104 List<QueueProperty> propertiesList = new ArrayList<>();
105 QueuePropertyBuilder pb = new QueuePropertyBuilder();
106 pb.setProperty(QueueProperties.forValue(2));
107 RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
108 rateBuilder.setRate(5);
109 pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
110 propertiesList.add(pb.build());
111 return propertiesList;