9670461f33758fb9806585df342bee11a215666c
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / QueueGetConfigReplyMessageFactoryMultiTest.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.deserialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12
13 import java.util.ArrayList;
14 import java.util.List;
15
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.OFDeserializer;
21 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
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;
35
36 /**
37  * @author timotej.kubas
38  * @author michal.polkorab
39  */
40 public class QueueGetConfigReplyMessageFactoryMultiTest {
41
42     private OFDeserializer<GetQueueConfigOutput> queueFactory;
43
44     /**
45      * Initializes deserializer registry and lookups correct deserializer
46      */
47     @Before
48     public void startUp() {
49         DeserializerRegistry registry = new DeserializerRegistryImpl();
50         registry.init();
51         queueFactory = registry.getDeserializer(
52                 new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 23, GetQueueConfigOutput.class));
53     }
54
55     /**
56      * Testing of {@link QueueGetConfigReplyMessageFactory} for correct
57      * translation into POJO
58      */
59     @Test
60     public void test() {
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
65                 "00 20 " + // length
66                 "00 00 00 00 00 00 " + // pad
67                 "00 02 " + // property
68                 "00 10 " + // length
69                 "00 00 00 00 " + // pad
70                 "00 05 " + // rate
71                 "00 00 00 00 00 00 " + // pad
72                 "00 00 00 02 " + // queueId
73                 "00 00 00 02 " + // port
74                 "00 20 " + // length
75                 "00 00 00 00 00 00 " + // pad
76                 "00 02 " + // property
77                 "00 10 " + // length
78                 "00 00 00 00 " + // pad
79                 "00 05 " + // rate
80                 "00 00 00 00 00 00" // pad
81         );
82
83         GetQueueConfigOutput builtByFactory = BufferHelper.deserialize(
84                 queueFactory, bb);
85
86         BufferHelper.checkHeaderV13(builtByFactory);
87         Assert.assertEquals("Wrong port", 66051L, builtByFactory.getPort().getValue().longValue());
88         Assert.assertEquals("Wrong queues", createQueuesList(), builtByFactory.getQueues());
89     }
90
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());
99         }
100         return queuesList;
101     }
102
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;
112     }
113
114 }