Committed by
Gerrit Code Review
ONOS-4751-Fix:creating GroupType INDIRECT, multiple bucket(REST API)
Change-Id: Ic8d5a04b8b00ca43bfadbb3019aa5d72e799da6f
Showing
5 changed files
with
39 additions
and
14 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.net.group; | ... | @@ -17,6 +17,7 @@ package org.onosproject.net.group; |
17 | 17 | ||
18 | import static com.google.common.base.MoreObjects.toStringHelper; | 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
19 | import static com.google.common.base.Preconditions.checkNotNull; | 19 | import static com.google.common.base.Preconditions.checkNotNull; |
20 | +import static com.google.common.base.Preconditions.checkArgument; | ||
20 | 21 | ||
21 | import java.util.Objects; | 22 | import java.util.Objects; |
22 | 23 | ||
... | @@ -61,6 +62,10 @@ public class DefaultGroupDescription implements GroupDescription { | ... | @@ -61,6 +62,10 @@ public class DefaultGroupDescription implements GroupDescription { |
61 | this.type = checkNotNull(type); | 62 | this.type = checkNotNull(type); |
62 | this.deviceId = checkNotNull(deviceId); | 63 | this.deviceId = checkNotNull(deviceId); |
63 | this.buckets = checkNotNull(buckets); | 64 | this.buckets = checkNotNull(buckets); |
65 | + if (this.type == GroupDescription.Type.INDIRECT) { | ||
66 | + checkArgument(buckets.buckets().size() == 1, "Indirect group " + | ||
67 | + "should have only one action bucket"); | ||
68 | + } | ||
64 | this.appCookie = appCookie; | 69 | this.appCookie = appCookie; |
65 | this.givenGroupId = groupId; | 70 | this.givenGroupId = groupId; |
66 | this.appId = appId; | 71 | this.appId = appId; | ... | ... |
... | @@ -34,6 +34,8 @@ import static org.onosproject.net.NetTestTools.did; | ... | @@ -34,6 +34,8 @@ import static org.onosproject.net.NetTestTools.did; |
34 | public class DefaultGroupTest { | 34 | public class DefaultGroupTest { |
35 | private final GroupId id1 = new DefaultGroupId(6); | 35 | private final GroupId id1 = new DefaultGroupId(6); |
36 | private final GroupId id2 = new DefaultGroupId(7); | 36 | private final GroupId id2 = new DefaultGroupId(7); |
37 | + private final GroupId id3 = new DefaultGroupId(1234); | ||
38 | + | ||
37 | private final GroupBucket bucket = | 39 | private final GroupBucket bucket = |
38 | DefaultGroupBucket.createSelectGroupBucket( | 40 | DefaultGroupBucket.createSelectGroupBucket( |
39 | DefaultTrafficTreatment.emptyTreatment()); | 41 | DefaultTrafficTreatment.emptyTreatment()); |
... | @@ -48,10 +50,16 @@ public class DefaultGroupTest { | ... | @@ -48,10 +50,16 @@ public class DefaultGroupTest { |
48 | GroupDescription.Type.FAILOVER, | 50 | GroupDescription.Type.FAILOVER, |
49 | groupBuckets); | 51 | groupBuckets); |
50 | 52 | ||
53 | + private final GroupDescription groupDesc3 = | ||
54 | + new DefaultGroupDescription(did("3"), | ||
55 | + GroupDescription.Type.INDIRECT, | ||
56 | + groupBuckets); | ||
57 | + | ||
51 | DefaultGroup group1 = new DefaultGroup(id1, groupDesc1); | 58 | DefaultGroup group1 = new DefaultGroup(id1, groupDesc1); |
52 | DefaultGroup sameAsGroup1 = new DefaultGroup(id1, groupDesc1); | 59 | DefaultGroup sameAsGroup1 = new DefaultGroup(id1, groupDesc1); |
53 | DefaultGroup group2 = new DefaultGroup(id1, groupDesc2); | 60 | DefaultGroup group2 = new DefaultGroup(id1, groupDesc2); |
54 | DefaultGroup group3 = new DefaultGroup(id2, groupDesc2); | 61 | DefaultGroup group3 = new DefaultGroup(id2, groupDesc2); |
62 | + DefaultGroup group4 = new DefaultGroup(id3, groupDesc3); | ||
55 | 63 | ||
56 | /** | 64 | /** |
57 | * Tests for proper operation of equals(), hashCode() and toString() methods. | 65 | * Tests for proper operation of equals(), hashCode() and toString() methods. |
... | @@ -62,6 +70,7 @@ public class DefaultGroupTest { | ... | @@ -62,6 +70,7 @@ public class DefaultGroupTest { |
62 | .addEqualityGroup(group1, sameAsGroup1) | 70 | .addEqualityGroup(group1, sameAsGroup1) |
63 | .addEqualityGroup(group2) | 71 | .addEqualityGroup(group2) |
64 | .addEqualityGroup(group3) | 72 | .addEqualityGroup(group3) |
73 | + .addEqualityGroup(group4) | ||
65 | .testEquals(); | 74 | .testEquals(); |
66 | } | 75 | } |
67 | 76 | ||
... | @@ -85,7 +94,7 @@ public class DefaultGroupTest { | ... | @@ -85,7 +94,7 @@ public class DefaultGroupTest { |
85 | @Test | 94 | @Test |
86 | public void checkConstructionWithDid() { | 95 | public void checkConstructionWithDid() { |
87 | DefaultGroup group = new DefaultGroup(id2, NetTestTools.did("1"), | 96 | DefaultGroup group = new DefaultGroup(id2, NetTestTools.did("1"), |
88 | - GroupDescription.Type.INDIRECT, groupBuckets); | 97 | + GroupDescription.Type.ALL, groupBuckets); |
89 | assertThat(group.id(), is(id2)); | 98 | assertThat(group.id(), is(id2)); |
90 | assertThat(group.bytes(), is(0L)); | 99 | assertThat(group.bytes(), is(0L)); |
91 | assertThat(group.life(), is(0L)); | 100 | assertThat(group.life(), is(0L)); | ... | ... |
... | @@ -155,7 +155,7 @@ public final class GroupCodec extends JsonCodec<Group> { | ... | @@ -155,7 +155,7 @@ public final class GroupCodec extends JsonCodec<Group> { |
155 | } | 155 | } |
156 | 156 | ||
157 | // parse group buckets | 157 | // parse group buckets |
158 | - // TODO: make sure that INDIRECT group only has one bucket | 158 | + |
159 | GroupBuckets buckets = null; | 159 | GroupBuckets buckets = null; |
160 | List<GroupBucket> groupBucketList = new ArrayList<>(); | 160 | List<GroupBucket> groupBucketList = new ArrayList<>(); |
161 | JsonNode bucketsJson = json.get(BUCKETS); | 161 | JsonNode bucketsJson = json.get(BUCKETS); | ... | ... |
... | @@ -33,7 +33,6 @@ import org.onosproject.net.group.DefaultGroupBucket; | ... | @@ -33,7 +33,6 @@ import org.onosproject.net.group.DefaultGroupBucket; |
33 | import org.onosproject.net.group.Group; | 33 | import org.onosproject.net.group.Group; |
34 | import org.onosproject.net.group.GroupBucket; | 34 | import org.onosproject.net.group.GroupBucket; |
35 | import org.onosproject.net.group.GroupBuckets; | 35 | import org.onosproject.net.group.GroupBuckets; |
36 | -import org.onosproject.net.group.GroupDescription; | ||
37 | 36 | ||
38 | import java.io.IOException; | 37 | import java.io.IOException; |
39 | import java.io.InputStream; | 38 | import java.io.InputStream; |
... | @@ -47,6 +46,7 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -47,6 +46,7 @@ import static org.hamcrest.Matchers.notNullValue; |
47 | import static org.hamcrest.Matchers.equalTo; | 46 | import static org.hamcrest.Matchers.equalTo; |
48 | import static org.onosproject.codec.impl.GroupJsonMatcher.matchesGroup; | 47 | import static org.onosproject.codec.impl.GroupJsonMatcher.matchesGroup; |
49 | import static org.onosproject.net.NetTestTools.APP_ID; | 48 | import static org.onosproject.net.NetTestTools.APP_ID; |
49 | +import static org.onosproject.net.group.GroupDescription.Type.*; | ||
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Group codec unit tests. | 52 | * Group codec unit tests. |
... | @@ -81,19 +81,27 @@ public class GroupCodecTest { | ... | @@ -81,19 +81,27 @@ public class GroupCodecTest { |
81 | GroupBucket bucket2 = DefaultGroupBucket | 81 | GroupBucket bucket2 = DefaultGroupBucket |
82 | .createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment()); | 82 | .createIndirectGroupBucket(DefaultTrafficTreatment.emptyTreatment()); |
83 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2)); | 83 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(bucket1, bucket2)); |
84 | - | 84 | + GroupBuckets bucketsIndirect = new GroupBuckets(ImmutableList.of(bucket2)); |
85 | 85 | ||
86 | DefaultGroup group = new DefaultGroup( | 86 | DefaultGroup group = new DefaultGroup( |
87 | new DefaultGroupId(1), | 87 | new DefaultGroupId(1), |
88 | NetTestTools.did("d1"), | 88 | NetTestTools.did("d1"), |
89 | - GroupDescription.Type.INDIRECT, | 89 | + ALL, |
90 | buckets); | 90 | buckets); |
91 | + DefaultGroup group1 = new DefaultGroup( | ||
92 | + new DefaultGroupId(2), | ||
93 | + NetTestTools.did("d2"), | ||
94 | + INDIRECT, | ||
95 | + bucketsIndirect); | ||
91 | 96 | ||
92 | MockCodecContext context = new MockCodecContext(); | 97 | MockCodecContext context = new MockCodecContext(); |
93 | GroupCodec codec = new GroupCodec(); | 98 | GroupCodec codec = new GroupCodec(); |
94 | ObjectNode groupJson = codec.encode(group, context); | 99 | ObjectNode groupJson = codec.encode(group, context); |
95 | 100 | ||
101 | + ObjectNode groupJsonIndirect = codec.encode(group1, context); | ||
102 | + | ||
96 | assertThat(groupJson, matchesGroup(group)); | 103 | assertThat(groupJson, matchesGroup(group)); |
104 | + assertThat(groupJsonIndirect, matchesGroup(group1)); | ||
97 | } | 105 | } |
98 | 106 | ||
99 | @Test | 107 | @Test |
... | @@ -108,6 +116,7 @@ public class GroupCodecTest { | ... | @@ -108,6 +116,7 @@ public class GroupCodecTest { |
108 | Instruction instruction1 = groupBucket.treatment().allInstructions().get(0); | 116 | Instruction instruction1 = groupBucket.treatment().allInstructions().get(0); |
109 | assertThat(instruction1.type(), is(Instruction.Type.OUTPUT)); | 117 | assertThat(instruction1.type(), is(Instruction.Type.OUTPUT)); |
110 | assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.portNumber(2))); | 118 | assertThat(((Instructions.OutputInstruction) instruction1).port(), is(PortNumber.portNumber(2))); |
119 | + | ||
111 | } | 120 | } |
112 | 121 | ||
113 | @Test(expected = IllegalArgumentException.class) | 122 | @Test(expected = IllegalArgumentException.class) |
... | @@ -129,6 +138,7 @@ public class GroupCodecTest { | ... | @@ -129,6 +138,7 @@ public class GroupCodecTest { |
129 | assertThat(group.id().id(), is(1)); | 138 | assertThat(group.id().id(), is(1)); |
130 | } | 139 | } |
131 | 140 | ||
141 | + | ||
132 | /** | 142 | /** |
133 | * Reads in a group from the given resource and decodes it. | 143 | * Reads in a group from the given resource and decodes it. |
134 | * | 144 | * | ... | ... |
... | @@ -61,7 +61,8 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -61,7 +61,8 @@ import static org.hamcrest.Matchers.notNullValue; |
61 | import static org.hamcrest.Matchers.nullValue; | 61 | import static org.hamcrest.Matchers.nullValue; |
62 | import static org.onosproject.net.NetTestTools.APP_ID; | 62 | import static org.onosproject.net.NetTestTools.APP_ID; |
63 | import static org.onosproject.net.NetTestTools.did; | 63 | import static org.onosproject.net.NetTestTools.did; |
64 | - | 64 | +import static org.onosproject.net.group.GroupDescription.Type.*; |
65 | +import static org.onosproject.net.group.GroupStore.UpdateType.*; | ||
65 | /** | 66 | /** |
66 | * Distributed group store test. | 67 | * Distributed group store test. |
67 | */ | 68 | */ |
... | @@ -87,21 +88,21 @@ public class DistributedGroupStoreTest { | ... | @@ -87,21 +88,21 @@ public class DistributedGroupStoreTest { |
87 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(selectGroupBucket)); | 88 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(selectGroupBucket)); |
88 | GroupDescription groupDescription1 = new DefaultGroupDescription( | 89 | GroupDescription groupDescription1 = new DefaultGroupDescription( |
89 | deviceId1, | 90 | deviceId1, |
90 | - GroupDescription.Type.INDIRECT, | 91 | + ALL, |
91 | buckets, | 92 | buckets, |
92 | groupKey1, | 93 | groupKey1, |
93 | groupId1.id(), | 94 | groupId1.id(), |
94 | APP_ID); | 95 | APP_ID); |
95 | GroupDescription groupDescription2 = new DefaultGroupDescription( | 96 | GroupDescription groupDescription2 = new DefaultGroupDescription( |
96 | deviceId2, | 97 | deviceId2, |
97 | - GroupDescription.Type.INDIRECT, | 98 | + INDIRECT, |
98 | buckets, | 99 | buckets, |
99 | groupKey2, | 100 | groupKey2, |
100 | groupId2.id(), | 101 | groupId2.id(), |
101 | APP_ID); | 102 | APP_ID); |
102 | GroupDescription groupDescription3 = new DefaultGroupDescription( | 103 | GroupDescription groupDescription3 = new DefaultGroupDescription( |
103 | deviceId2, | 104 | deviceId2, |
104 | - GroupDescription.Type.INDIRECT, | 105 | + INDIRECT, |
105 | buckets, | 106 | buckets, |
106 | groupKey3, | 107 | groupKey3, |
107 | groupId3.id(), | 108 | groupId3.id(), |
... | @@ -262,7 +263,7 @@ public class DistributedGroupStoreTest { | ... | @@ -262,7 +263,7 @@ public class DistributedGroupStoreTest { |
262 | 263 | ||
263 | GroupDescription groupDescription3 = new DefaultGroupDescription( | 264 | GroupDescription groupDescription3 = new DefaultGroupDescription( |
264 | deviceId1, | 265 | deviceId1, |
265 | - GroupDescription.Type.SELECT, | 266 | + SELECT, |
266 | buckets, | 267 | buckets, |
267 | new DefaultGroupKey("aaa".getBytes()), | 268 | new DefaultGroupKey("aaa".getBytes()), |
268 | null, | 269 | null, |
... | @@ -323,7 +324,7 @@ public class DistributedGroupStoreTest { | ... | @@ -323,7 +324,7 @@ public class DistributedGroupStoreTest { |
323 | 324 | ||
324 | GroupOperation opAdd = | 325 | GroupOperation opAdd = |
325 | GroupOperation.createAddGroupOperation(groupId1, | 326 | GroupOperation.createAddGroupOperation(groupId1, |
326 | - GroupDescription.Type.INDIRECT, | 327 | + INDIRECT, |
327 | buckets); | 328 | buckets); |
328 | groupStore.groupOperationFailed(deviceId1, opAdd); | 329 | groupStore.groupOperationFailed(deviceId1, opAdd); |
329 | 330 | ||
... | @@ -337,7 +338,7 @@ public class DistributedGroupStoreTest { | ... | @@ -337,7 +338,7 @@ public class DistributedGroupStoreTest { |
337 | 338 | ||
338 | GroupOperation opModify = | 339 | GroupOperation opModify = |
339 | GroupOperation.createModifyGroupOperation(groupId2, | 340 | GroupOperation.createModifyGroupOperation(groupId2, |
340 | - GroupDescription.Type.INDIRECT, | 341 | + INDIRECT, |
341 | buckets); | 342 | buckets); |
342 | groupStore.groupOperationFailed(deviceId2, opModify); | 343 | groupStore.groupOperationFailed(deviceId2, opModify); |
343 | List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen(); | 344 | List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen(); |
... | @@ -348,7 +349,7 @@ public class DistributedGroupStoreTest { | ... | @@ -348,7 +349,7 @@ public class DistributedGroupStoreTest { |
348 | 349 | ||
349 | GroupOperation opDelete = | 350 | GroupOperation opDelete = |
350 | GroupOperation.createDeleteGroupOperation(groupId2, | 351 | GroupOperation.createDeleteGroupOperation(groupId2, |
351 | - GroupDescription.Type.INDIRECT); | 352 | + INDIRECT); |
352 | groupStore.groupOperationFailed(deviceId2, opDelete); | 353 | groupStore.groupOperationFailed(deviceId2, opDelete); |
353 | List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen(); | 354 | List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen(); |
354 | assertThat(eventsAfterDeleteFailed, hasSize(1)); | 355 | assertThat(eventsAfterDeleteFailed, hasSize(1)); |
... | @@ -395,7 +396,7 @@ public class DistributedGroupStoreTest { | ... | @@ -395,7 +396,7 @@ public class DistributedGroupStoreTest { |
395 | GroupKey newKey = new DefaultGroupKey("123".getBytes()); | 396 | GroupKey newKey = new DefaultGroupKey("123".getBytes()); |
396 | groupStore.updateGroupDescription(deviceId1, | 397 | groupStore.updateGroupDescription(deviceId1, |
397 | groupKey1, | 398 | groupKey1, |
398 | - GroupStore.UpdateType.ADD, | 399 | + ADD, |
399 | buckets, | 400 | buckets, |
400 | newKey); | 401 | newKey); |
401 | Group group1 = groupStore.getGroup(deviceId1, groupId1); | 402 | Group group1 = groupStore.getGroup(deviceId1, groupId1); | ... | ... |
-
Please register or login to post a comment