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.util.ArrayList;
\r
12 import java.util.Collections;
\r
13 import java.util.List;
\r
14 import java.util.Optional;
\r
15 import org.junit.Assert;
\r
16 import org.junit.Test;
\r
17 import org.opendaylight.openflowplugin.api.OFConstants;
\r
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCaseBuilder;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCaseBuilder;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.DecNwTtlCaseBuilder;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.PopPbbCaseBuilder;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
\r
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
\r
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
\r
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
\r
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
\r
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDesc;
\r
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.group.desc._case.multipart.reply.group.desc.GroupDescBuilder;
\r
37 * @author michal.polkorab
\r
40 public class GroupDescStatsResponseConvertorTest {
\r
43 * Test empty GroupDescStats conversion
\r
46 public void test() {
\r
47 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
49 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
\r
50 List<GroupDescStats> statsList = convert(groupDescStats, data);
\r
51 Assert.assertEquals("Wrong groupDesc stats size", 0, statsList.size());
\r
55 * Test single GroupDescStat conversion without buckets
\r
58 public void testSingleGroupDescStat() {
\r
59 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
60 GroupDescBuilder builder = new GroupDescBuilder();
\r
61 builder.setType(GroupType.OFPGTALL);
\r
62 builder.setGroupId(new GroupId(42L));
\r
63 builder.setBucketsList(new ArrayList<>());
\r
64 groupDescStats.add(builder.build());
\r
66 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
\r
67 List<GroupDescStats> statsList = convert(groupDescStats, data);
\r
69 Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
\r
70 GroupDescStats stat = statsList.get(0);
\r
71 Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
\r
72 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
73 Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
\r
74 Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
\r
78 * Test single GroupDescStats conversion
\r
81 public void testGroupDescStats() {
\r
82 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
84 // **********************************************
\r
86 // **********************************************
\r
87 GroupDescBuilder builder = new GroupDescBuilder();
\r
88 builder.setType(GroupType.OFPGTFF);
\r
89 builder.setGroupId(new GroupId(42L));
\r
91 // Buckets for first group desc
\r
92 List<BucketsList> bucketsList = new ArrayList<>();
\r
93 BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
\r
94 bucketsBuilder.setWeight(16);
\r
95 bucketsBuilder.setWatchPort(new PortNumber(84L));
\r
96 bucketsBuilder.setWatchGroup(168L);
\r
98 // Actions for buckets for first group desc
\r
99 List<Action> actions = new ArrayList<>();
\r
100 ActionBuilder actionBuilder = new ActionBuilder();
\r
101 actionBuilder.setActionChoice(new CopyTtlInCaseBuilder().build());
\r
102 actions.add(actionBuilder.build());
\r
104 // Build bucket with actions
\r
105 bucketsBuilder.setAction(actions);
\r
106 bucketsList.add(bucketsBuilder.build());
\r
108 // Build first group desc
\r
109 builder.setBucketsList(bucketsList);
\r
110 groupDescStats.add(builder.build());
\r
112 // **********************************************
\r
113 // Second group desc
\r
114 // **********************************************
\r
115 builder = new GroupDescBuilder();
\r
116 builder.setType(GroupType.OFPGTINDIRECT);
\r
117 builder.setGroupId(new GroupId(50L));
\r
119 // First buckets for second group desc
\r
120 bucketsList = new ArrayList<>();
\r
121 bucketsBuilder = new BucketsListBuilder();
\r
122 bucketsBuilder.setWeight(100);
\r
123 bucketsBuilder.setWatchPort(new PortNumber(200L));
\r
124 bucketsBuilder.setWatchGroup(400L);
\r
126 // Actions for first buckets for second group desc
\r
127 actions = new ArrayList<>();
\r
129 actionBuilder = new ActionBuilder();
\r
130 actionBuilder.setActionChoice(new CopyTtlOutCaseBuilder().build());
\r
131 actions.add(actionBuilder.build());
\r
133 actionBuilder = new ActionBuilder();
\r
134 actionBuilder.setActionChoice(new DecNwTtlCaseBuilder().build());
\r
135 actions.add(actionBuilder.build());
\r
137 actionBuilder = new ActionBuilder();
\r
138 actionBuilder.setActionChoice(new PopPbbCaseBuilder().build());
\r
139 actions.add(actionBuilder.build());
\r
141 // Build first bucket with actions
\r
142 bucketsBuilder.setAction(actions);
\r
143 bucketsList.add(bucketsBuilder.build());
\r
145 // Second buckets for second group desc
\r
146 bucketsBuilder = new BucketsListBuilder();
\r
147 bucketsBuilder.setWeight(5);
\r
148 bucketsBuilder.setWatchPort(new PortNumber(10L));
\r
149 bucketsBuilder.setWatchGroup(15L);
\r
151 // Actions for second buckets for second group desc
\r
152 actions = new ArrayList<>();
\r
154 // Build second bucket with actions
\r
155 bucketsBuilder.setAction(actions);
\r
156 bucketsList.add(bucketsBuilder.build());
\r
158 // Build second group desc
\r
159 builder.setBucketsList(bucketsList);
\r
160 groupDescStats.add(builder.build());
\r
163 VersionConvertorData data = new VersionConvertorData(OFConstants.OFP_VERSION_1_3);
\r
164 List<GroupDescStats> statsList = convert(groupDescStats, data);
\r
165 Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size());
\r
167 // **********************************************
\r
168 // Test first group desc
\r
169 // **********************************************
\r
170 GroupDescStats stat = statsList.get(0);
\r
171 Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType());
\r
172 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
173 Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
\r
174 Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size());
\r
176 // Test first bucket for first group desc
\r
177 Bucket bucket = stat.getBuckets().getBucket().get(0);
\r
178 Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
\r
179 Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
\r
180 Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
\r
181 Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
\r
182 Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
\r
183 Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
\r
185 // Test first action for first bucket for first group desc
\r
186 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
\r
187 .Action action = bucket.getAction().get(0);
\r
188 Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
\r
189 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
190 + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
\r
192 // **********************************************
\r
193 // Test second group desc
\r
194 // **********************************************
\r
195 stat = statsList.get(1);
\r
196 Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
\r
197 Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
\r
198 Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
\r
199 Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
\r
201 // Test first bucket for second group desc
\r
202 bucket = stat.getBuckets().getBucket().get(0);
\r
203 Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
\r
204 Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
\r
205 Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
\r
206 Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
\r
207 Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
\r
208 Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
\r
210 // Test first action for first bucket of second group desc
\r
211 action = bucket.getAction().get(0);
\r
212 Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
\r
213 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
214 + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
\r
216 // Test second action for first bucket of second group desc
\r
217 action = bucket.getAction().get(1);
\r
218 Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
\r
219 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
220 + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
\r
222 // Test third action for first bucket of second group desc
\r
223 action = bucket.getAction().get(2);
\r
224 Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
\r
225 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
226 + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
\r
228 // Test second bucket for second group desc
\r
229 bucket = stat.getBuckets().getBucket().get(1);
\r
230 Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
\r
231 Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
\r
232 Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
\r
233 Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
\r
234 Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
\r
235 Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
\r
238 private List<GroupDescStats> convert(List<GroupDesc> groupDescStats,VersionConvertorData data) {
\r
239 Optional<List<GroupDescStats>> statsListOptional = ConvertorManager.getInstance().convert(groupDescStats, data);
\r
240 return statsListOptional.orElse(Collections.emptyList());
\r