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.api.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 QueueGetConfigReplyMessageFactoryTest {
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 {@link QueueGetConfigReplyMessageFactory} for correct translation into POJO
60 ByteBuf bb = BufferHelper.buildBuffer("00 00 00 03 00 00 00 00 00 00 00 01 00 00 00 03 00 20 00 00 00 00 00 00 00 02 00 10 00 00 00 00 00 05 00 00 00 00 00 00");
61 GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(queueFactory, bb);
62 BufferHelper.checkHeaderV13(builtByFactory);
63 Assert.assertEquals("Wrong port", 3L, builtByFactory.getPort().getValue().longValue());
64 Assert.assertEquals("Wrong queues", builtByFactory.getQueues(), createQueuesList());
67 private static List<Queues> createQueuesList(){
68 List<Queues> queuesList = new ArrayList<>();
69 QueuesBuilder qb = new QueuesBuilder();
70 qb.setQueueId(new QueueId(1L));
71 qb.setPort(new PortNumber(3L));
72 qb.setQueueProperty(createPropertiesList());
73 queuesList.add(qb.build());
78 private static List<QueueProperty> createPropertiesList(){
79 List<QueueProperty> propertiesList = new ArrayList<>();
80 QueuePropertyBuilder pb = new QueuePropertyBuilder();
81 pb.setProperty(QueueProperties.forValue(2));
82 RateQueuePropertyBuilder rateBuilder = new RateQueuePropertyBuilder();
83 rateBuilder.setRate(5);
84 pb.addAugmentation(RateQueueProperty.class, rateBuilder.build());
85 propertiesList.add(pb.build());
86 return propertiesList;