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.List;
\r
14 import org.junit.Assert;
\r
15 import org.junit.Test;
\r
16 import org.opendaylight.openflowplugin.api.openflow.md.util.OpenflowVersion;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupTypes;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.buckets.Bucket;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.desc.stats.reply.GroupDescStats;
\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.Action;
\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.actions.grouping.ActionBuilder;
\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupId;
\r
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.GroupType;
\r
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.PortNumber;
\r
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsList;
\r
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.buckets.grouping.BucketsListBuilder;
\r
27 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
28 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
31 * @author michal.polkorab
\r
34 public class GroupStatsResponseConvertorTest2 {
\r
36 GroupStatsResponseConvertor convertor = new GroupStatsResponseConvertor();
\r
39 * Test empty GroupDescStats conversion
\r
42 public void test() {
\r
43 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
45 List<GroupDescStats> statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13);
\r
47 Assert.assertEquals("Wrong groupDesc stats size", 0, statsList.size());
\r
51 * Test single GroupDescStat conversion without buckets
\r
54 public void testSingleGroupDescStat() {
\r
55 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
56 GroupDescBuilder builder = new GroupDescBuilder();
\r
57 builder.setType(GroupType.OFPGTALL);
\r
58 builder.setGroupId(new GroupId(42L));
\r
59 builder.setBucketsList(new ArrayList<BucketsList>());
\r
60 groupDescStats.add(builder.build());
\r
62 List<GroupDescStats> statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13);
\r
64 Assert.assertEquals("Wrong groupDesc stats size", 1, statsList.size());
\r
65 GroupDescStats stat = statsList.get(0);
\r
66 Assert.assertEquals("Wrong type", GroupTypes.GroupAll, stat.getGroupType());
\r
67 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
68 Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
\r
69 Assert.assertEquals("Wrong buckets size", 0, stat.getBuckets().getBucket().size());
\r
73 * Test single GroupDescStats conversion
\r
76 public void testGroupDescStats() {
\r
77 List<GroupDesc> groupDescStats = new ArrayList<>();
\r
78 GroupDescBuilder builder = new GroupDescBuilder();
\r
79 builder.setType(GroupType.OFPGTFF);
\r
80 builder.setGroupId(new GroupId(42L));
\r
81 List<BucketsList> bucketsList = new ArrayList<>();
\r
82 BucketsListBuilder bucketsBuilder = new BucketsListBuilder();
\r
83 bucketsBuilder.setWeight(16);
\r
84 bucketsBuilder.setWatchPort(new PortNumber(84L));
\r
85 bucketsBuilder.setWatchGroup(168L);
\r
86 List<Action> actions = new ArrayList<>();
\r
87 ActionBuilder actionBuilder = new ActionBuilder();
\r
88 actions.add(actionBuilder.build());
\r
89 bucketsBuilder.setAction(actions);
\r
90 bucketsList.add(bucketsBuilder.build());
\r
91 builder.setBucketsList(bucketsList);
\r
92 groupDescStats.add(builder.build());
\r
93 builder = new GroupDescBuilder();
\r
94 builder.setType(GroupType.OFPGTINDIRECT);
\r
95 builder.setGroupId(new GroupId(50L));
\r
96 bucketsList = new ArrayList<>();
\r
97 bucketsBuilder = new BucketsListBuilder();
\r
98 bucketsBuilder.setWeight(100);
\r
99 bucketsBuilder.setWatchPort(new PortNumber(200L));
\r
100 bucketsBuilder.setWatchGroup(400L);
\r
101 actions = new ArrayList<>();
\r
102 actionBuilder = new ActionBuilder();
\r
103 actions.add(actionBuilder.build());
\r
104 actionBuilder = new ActionBuilder();
\r
105 actions.add(actionBuilder.build());
\r
106 actionBuilder = new ActionBuilder();
\r
107 actions.add(actionBuilder.build());
\r
108 bucketsBuilder.setAction(actions);
\r
109 bucketsList.add(bucketsBuilder.build());
\r
110 bucketsBuilder = new BucketsListBuilder();
\r
111 bucketsBuilder.setWeight(5);
\r
112 bucketsBuilder.setWatchPort(new PortNumber(10L));
\r
113 bucketsBuilder.setWatchGroup(15L);
\r
114 actions = new ArrayList<>();
\r
115 bucketsBuilder.setAction(actions);
\r
116 bucketsList.add(bucketsBuilder.build());
\r
117 builder.setBucketsList(bucketsList);
\r
118 groupDescStats.add(builder.build());
\r
120 List<GroupDescStats> statsList = convertor.toSALGroupDescStatsList(groupDescStats, OpenflowVersion.OF13);
\r
122 Assert.assertEquals("Wrong groupDesc stats size", 2, statsList.size());
\r
123 GroupDescStats stat = statsList.get(0);
\r
124 Assert.assertEquals("Wrong type", GroupTypes.GroupFf, stat.getGroupType());
\r
125 Assert.assertEquals("Wrong group-id", 42, stat.getGroupId().getValue().intValue());
\r
126 Assert.assertEquals("Wrong key", 42, stat.getKey().getGroupId().getValue().intValue());
\r
127 Assert.assertEquals("Wrong buckets size", 1, stat.getBuckets().getBucket().size());
\r
128 Bucket bucket = stat.getBuckets().getBucket().get(0);
\r
129 Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
\r
130 Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
\r
131 Assert.assertEquals("Wrong type", 16, bucket.getWeight().intValue());
\r
132 Assert.assertEquals("Wrong type", 168, bucket.getWatchGroup().intValue());
\r
133 Assert.assertEquals("Wrong type", 84, bucket.getWatchPort().intValue());
\r
134 Assert.assertEquals("Wrong type", 1, bucket.getAction().size());
\r
135 org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list
\r
136 .Action action = bucket.getAction().get(0);
\r
137 Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
\r
138 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
139 + ".action.action.CopyTtlInCase", action.getAction().getImplementedInterface().getName());
\r
141 stat = statsList.get(1);
\r
142 Assert.assertEquals("Wrong type", GroupTypes.GroupIndirect, stat.getGroupType());
\r
143 Assert.assertEquals("Wrong group-id", 50, stat.getGroupId().getValue().intValue());
\r
144 Assert.assertEquals("Wrong key", 50, stat.getKey().getGroupId().getValue().intValue());
\r
145 Assert.assertEquals("Wrong buckets size", 2, stat.getBuckets().getBucket().size());
\r
146 bucket = stat.getBuckets().getBucket().get(0);
\r
147 Assert.assertEquals("Wrong type", 0, bucket.getKey().getBucketId().getValue().intValue());
\r
148 Assert.assertEquals("Wrong type", 0, bucket.getBucketId().getValue().intValue());
\r
149 Assert.assertEquals("Wrong type", 100, bucket.getWeight().intValue());
\r
150 Assert.assertEquals("Wrong type", 400, bucket.getWatchGroup().intValue());
\r
151 Assert.assertEquals("Wrong type", 200, bucket.getWatchPort().intValue());
\r
152 Assert.assertEquals("Wrong type", 3, bucket.getAction().size());
\r
153 action = bucket.getAction().get(0);
\r
154 Assert.assertEquals("Wrong type", 0, action.getOrder().intValue());
\r
155 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
156 + ".action.action.CopyTtlOutCase", action.getAction().getImplementedInterface().getName());
\r
157 action = bucket.getAction().get(1);
\r
158 Assert.assertEquals("Wrong type", 1, action.getOrder().intValue());
\r
159 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
160 + ".action.action.DecNwTtlCase", action.getAction().getImplementedInterface().getName());
\r
161 action = bucket.getAction().get(2);
\r
162 Assert.assertEquals("Wrong type", 2, action.getOrder().intValue());
\r
163 Assert.assertEquals("Wrong type", "org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112"
\r
164 + ".action.action.PopPbbActionCase", action.getAction().getImplementedInterface().getName());
\r
165 bucket = stat.getBuckets().getBucket().get(1);
\r
166 Assert.assertEquals("Wrong type", 1, bucket.getKey().getBucketId().getValue().intValue());
\r
167 Assert.assertEquals("Wrong type", 1, bucket.getBucketId().getValue().intValue());
\r
168 Assert.assertEquals("Wrong type", 5, bucket.getWeight().intValue());
\r
169 Assert.assertEquals("Wrong type", 15, bucket.getWatchGroup().intValue());
\r
170 Assert.assertEquals("Wrong type", 10, bucket.getWatchPort().intValue());
\r
171 Assert.assertEquals("Wrong type", 0, bucket.getAction().size());
\r