2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowplugin.openflow.md.core.sal.convertor;
\r
11 import java.math.BigInteger;
\r
12 import java.util.ArrayList;
\r
13 import java.util.List;
\r
15 import org.junit.Assert;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.buckets.BucketCounter;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStats;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.GroupStatsBuilder;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStats;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group._case.multipart.reply.group.group.stats.BucketStatsBuilder;
\r
25 * @author michal.polkorab
\r
28 public class GroupStatsResponseConvertorTest {
\r
30 GroupStatsResponseConvertor convertor = new GroupStatsResponseConvertor();
\r
33 * Test empty GroupStats conversion
\r
36 public void testEmptyGroupStats() {
\r
37 List<GroupStats> groupStats = new ArrayList<>();
\r
39 List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
40 .GroupStats> salGroupStats = convertor.toSALGroupStatsList(groupStats);
\r
42 Assert.assertEquals("Wrong group stats size", 0, salGroupStats.size());
\r
46 * Test single GroupStat conversion
\r
49 public void testSingleGroupStat() {
\r
50 List<GroupStats> groupStats = new ArrayList<>();
\r
51 GroupStatsBuilder statsBuilder = new GroupStatsBuilder();
\r
52 statsBuilder.setByteCount(new BigInteger("12345"));
\r
53 statsBuilder.setDurationNsec(1000000L);
\r
54 statsBuilder.setDurationSec(5000L);
\r
55 statsBuilder.setGroupId(new GroupId(42L));
\r
56 statsBuilder.setPacketCount(new BigInteger("54321"));
\r
57 statsBuilder.setRefCount(24L);
\r
58 statsBuilder.setBucketStats(new ArrayList<BucketStats>());
\r
59 groupStats.add(statsBuilder.build());
\r
61 List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
62 .GroupStats> salGroupStats = convertor.toSALGroupStatsList(groupStats);
\r
64 Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size());
\r
65 org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
66 .GroupStats stat = salGroupStats.get(0);
\r
67 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
68 Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue());
\r
69 Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue());
\r
70 Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue());
\r
71 Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue());
\r
72 Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue());
\r
73 Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size());
\r
77 * Test two GroupStats conversion
\r
80 public void testTwoGroupStats() {
\r
81 List<GroupStats> groupStats = new ArrayList<>();
\r
82 GroupStatsBuilder statsBuilder = new GroupStatsBuilder();
\r
83 statsBuilder.setByteCount(new BigInteger("12345"));
\r
84 statsBuilder.setDurationNsec(1000000L);
\r
85 statsBuilder.setDurationSec(5000L);
\r
86 statsBuilder.setGroupId(new GroupId(42L));
\r
87 statsBuilder.setPacketCount(new BigInteger("54321"));
\r
88 statsBuilder.setRefCount(24L);
\r
89 statsBuilder.setBucketStats(new ArrayList<BucketStats>());
\r
90 groupStats.add(statsBuilder.build());
\r
91 statsBuilder = new GroupStatsBuilder();
\r
92 statsBuilder.setByteCount(new BigInteger("1"));
\r
93 statsBuilder.setDurationNsec(2L);
\r
94 statsBuilder.setDurationSec(3L);
\r
95 statsBuilder.setGroupId(new GroupId(4L));
\r
96 statsBuilder.setPacketCount(new BigInteger("5"));
\r
97 statsBuilder.setRefCount(6L);
\r
98 statsBuilder.setBucketStats(new ArrayList<BucketStats>());
\r
99 groupStats.add(statsBuilder.build());
\r
101 List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
102 .GroupStats> salGroupStats = convertor.toSALGroupStatsList(groupStats);
\r
104 Assert.assertEquals("Wrong group stats size", 2, salGroupStats.size());
\r
105 org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
106 .GroupStats stat = salGroupStats.get(0);
\r
107 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
108 Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
\r
109 Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue());
\r
110 Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue());
\r
111 Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue());
\r
112 Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue());
\r
113 Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue());
\r
114 Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size());
\r
115 stat = salGroupStats.get(1);
\r
116 Assert.assertEquals("Wrong group-id", 4, stat.getGroupId().getValue().intValue());
\r
117 Assert.assertEquals("Wrong key", 4, stat.getKey().getGroupId().getValue().intValue());
\r
118 Assert.assertEquals("Wrong ref-count", 6, stat.getRefCount().getValue().intValue());
\r
119 Assert.assertEquals("Wrong packet count", 5, stat.getPacketCount().getValue().intValue());
\r
120 Assert.assertEquals("Wrong byte count", 1, stat.getByteCount().getValue().intValue());
\r
121 Assert.assertEquals("Wrong duration sec", 3, stat.getDuration().getSecond().getValue().intValue());
\r
122 Assert.assertEquals("Wrong duration n sec", 2, stat.getDuration().getNanosecond().getValue().intValue());
\r
123 Assert.assertEquals("Wrong bucket stats", 0, stat.getBuckets().getBucketCounter().size());
\r
127 * Test GroupStats with buckets conversion
\r
130 public void testGroupStatsWithBuckets() {
\r
131 List<GroupStats> groupStats = new ArrayList<>();
\r
132 GroupStatsBuilder statsBuilder = new GroupStatsBuilder();
\r
133 statsBuilder.setByteCount(new BigInteger("12345"));
\r
134 statsBuilder.setDurationNsec(1000000L);
\r
135 statsBuilder.setDurationSec(5000L);
\r
136 statsBuilder.setGroupId(new GroupId(42L));
\r
137 statsBuilder.setPacketCount(new BigInteger("54321"));
\r
138 statsBuilder.setRefCount(24L);
\r
139 List<BucketStats> bucketStats = new ArrayList<>();
\r
140 BucketStatsBuilder bucketStatsBuilder = new BucketStatsBuilder();
\r
141 bucketStatsBuilder.setByteCount(new BigInteger("987"));
\r
142 bucketStatsBuilder.setPacketCount(new BigInteger("654"));
\r
143 bucketStats.add(bucketStatsBuilder.build());
\r
144 bucketStatsBuilder = new BucketStatsBuilder();
\r
145 bucketStatsBuilder.setByteCount(new BigInteger("123"));
\r
146 bucketStatsBuilder.setPacketCount(new BigInteger("456"));
\r
147 bucketStats.add(bucketStatsBuilder.build());
\r
148 statsBuilder.setBucketStats(bucketStats);
\r
149 groupStats.add(statsBuilder.build());
\r
151 List<org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
152 .GroupStats> salGroupStats = convertor.toSALGroupStatsList(groupStats);
\r
154 Assert.assertEquals("Wrong group stats size", 1, salGroupStats.size());
\r
155 org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply
\r
156 .GroupStats stat = salGroupStats.get(0);
\r
157 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
158 Assert.assertEquals("Wrong ref-count", 24, stat.getRefCount().getValue().intValue());
\r
159 Assert.assertEquals("Wrong packet count", 54321, stat.getPacketCount().getValue().intValue());
\r
160 Assert.assertEquals("Wrong byte count", 12345, stat.getByteCount().getValue().intValue());
\r
161 Assert.assertEquals("Wrong duration sec", 5000, stat.getDuration().getSecond().getValue().intValue());
\r
162 Assert.assertEquals("Wrong duration n sec", 1000000, stat.getDuration().getNanosecond().getValue().intValue());
\r
163 Assert.assertEquals("Wrong bucket stats", 2, stat.getBuckets().getBucketCounter().size());
\r
164 List<BucketCounter> list = stat.getBuckets().getBucketCounter();
\r
165 Assert.assertEquals("Wrong bucket-id", 0, list.get(0).getBucketId().getValue().intValue());
\r
166 Assert.assertEquals("Wrong bucket packet count", 654, list.get(0).getPacketCount().getValue().intValue());
\r
167 Assert.assertEquals("Wrong bucket byte count", 987, list.get(0).getByteCount().getValue().intValue());
\r
168 Assert.assertEquals("Wrong bucket-id", 1, list.get(1).getBucketId().getValue().intValue());
\r
169 Assert.assertEquals("Wrong bucket packet count", 456, list.get(1).getPacketCount().getValue().intValue());
\r
170 Assert.assertEquals("Wrong bucket byte count", 123, list.get(1).getByteCount().getValue().intValue());
\r