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)); | ... | ... |
... | @@ -156,7 +156,7 @@ public final class GroupCodec extends JsonCodec<Group> { | ... | @@ -156,7 +156,7 @@ public final class GroupCodec extends JsonCodec<Group> { |
156 | } | 156 | } |
157 | 157 | ||
158 | // parse group buckets | 158 | // parse group buckets |
159 | - // TODO: make sure that INDIRECT group only has one bucket | 159 | + |
160 | GroupBuckets buckets = null; | 160 | GroupBuckets buckets = null; |
161 | List<GroupBucket> groupBucketList = new ArrayList<>(); | 161 | List<GroupBucket> groupBucketList = new ArrayList<>(); |
162 | JsonNode bucketsJson = json.get(BUCKETS); | 162 | 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 | * | ... | ... |
... | @@ -62,7 +62,8 @@ import static org.hamcrest.Matchers.notNullValue; | ... | @@ -62,7 +62,8 @@ import static org.hamcrest.Matchers.notNullValue; |
62 | import static org.hamcrest.Matchers.nullValue; | 62 | import static org.hamcrest.Matchers.nullValue; |
63 | import static org.onosproject.net.NetTestTools.APP_ID; | 63 | import static org.onosproject.net.NetTestTools.APP_ID; |
64 | import static org.onosproject.net.NetTestTools.did; | 64 | import static org.onosproject.net.NetTestTools.did; |
65 | - | 65 | +import static org.onosproject.net.group.GroupDescription.Type.*; |
66 | +import static org.onosproject.net.group.GroupStore.UpdateType.*; | ||
66 | /** | 67 | /** |
67 | * Distributed group store test. | 68 | * Distributed group store test. |
68 | */ | 69 | */ |
... | @@ -88,21 +89,21 @@ public class DistributedGroupStoreTest { | ... | @@ -88,21 +89,21 @@ public class DistributedGroupStoreTest { |
88 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(selectGroupBucket)); | 89 | GroupBuckets buckets = new GroupBuckets(ImmutableList.of(selectGroupBucket)); |
89 | GroupDescription groupDescription1 = new DefaultGroupDescription( | 90 | GroupDescription groupDescription1 = new DefaultGroupDescription( |
90 | deviceId1, | 91 | deviceId1, |
91 | - GroupDescription.Type.INDIRECT, | 92 | + ALL, |
92 | buckets, | 93 | buckets, |
93 | groupKey1, | 94 | groupKey1, |
94 | groupId1.id(), | 95 | groupId1.id(), |
95 | APP_ID); | 96 | APP_ID); |
96 | GroupDescription groupDescription2 = new DefaultGroupDescription( | 97 | GroupDescription groupDescription2 = new DefaultGroupDescription( |
97 | deviceId2, | 98 | deviceId2, |
98 | - GroupDescription.Type.INDIRECT, | 99 | + INDIRECT, |
99 | buckets, | 100 | buckets, |
100 | groupKey2, | 101 | groupKey2, |
101 | groupId2.id(), | 102 | groupId2.id(), |
102 | APP_ID); | 103 | APP_ID); |
103 | GroupDescription groupDescription3 = new DefaultGroupDescription( | 104 | GroupDescription groupDescription3 = new DefaultGroupDescription( |
104 | deviceId2, | 105 | deviceId2, |
105 | - GroupDescription.Type.INDIRECT, | 106 | + INDIRECT, |
106 | buckets, | 107 | buckets, |
107 | groupKey3, | 108 | groupKey3, |
108 | groupId3.id(), | 109 | groupId3.id(), |
... | @@ -264,7 +265,7 @@ public class DistributedGroupStoreTest { | ... | @@ -264,7 +265,7 @@ public class DistributedGroupStoreTest { |
264 | 265 | ||
265 | GroupDescription groupDescription3 = new DefaultGroupDescription( | 266 | GroupDescription groupDescription3 = new DefaultGroupDescription( |
266 | deviceId1, | 267 | deviceId1, |
267 | - GroupDescription.Type.SELECT, | 268 | + SELECT, |
268 | buckets, | 269 | buckets, |
269 | new DefaultGroupKey("aaa".getBytes()), | 270 | new DefaultGroupKey("aaa".getBytes()), |
270 | null, | 271 | null, |
... | @@ -325,7 +326,7 @@ public class DistributedGroupStoreTest { | ... | @@ -325,7 +326,7 @@ public class DistributedGroupStoreTest { |
325 | 326 | ||
326 | GroupOperation opAdd = | 327 | GroupOperation opAdd = |
327 | GroupOperation.createAddGroupOperation(groupId1, | 328 | GroupOperation.createAddGroupOperation(groupId1, |
328 | - GroupDescription.Type.INDIRECT, | 329 | + INDIRECT, |
329 | buckets); | 330 | buckets); |
330 | groupStore.groupOperationFailed(deviceId1, opAdd); | 331 | groupStore.groupOperationFailed(deviceId1, opAdd); |
331 | 332 | ||
... | @@ -339,7 +340,7 @@ public class DistributedGroupStoreTest { | ... | @@ -339,7 +340,7 @@ public class DistributedGroupStoreTest { |
339 | 340 | ||
340 | GroupOperation opModify = | 341 | GroupOperation opModify = |
341 | GroupOperation.createModifyGroupOperation(groupId2, | 342 | GroupOperation.createModifyGroupOperation(groupId2, |
342 | - GroupDescription.Type.INDIRECT, | 343 | + INDIRECT, |
343 | buckets); | 344 | buckets); |
344 | groupStore.groupOperationFailed(deviceId2, opModify); | 345 | groupStore.groupOperationFailed(deviceId2, opModify); |
345 | List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen(); | 346 | List<GroupEvent> eventsAfterModifyFailed = delegate.eventsSeen(); |
... | @@ -350,7 +351,7 @@ public class DistributedGroupStoreTest { | ... | @@ -350,7 +351,7 @@ public class DistributedGroupStoreTest { |
350 | 351 | ||
351 | GroupOperation opDelete = | 352 | GroupOperation opDelete = |
352 | GroupOperation.createDeleteGroupOperation(groupId2, | 353 | GroupOperation.createDeleteGroupOperation(groupId2, |
353 | - GroupDescription.Type.INDIRECT); | 354 | + INDIRECT); |
354 | groupStore.groupOperationFailed(deviceId2, opDelete); | 355 | groupStore.groupOperationFailed(deviceId2, opDelete); |
355 | List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen(); | 356 | List<GroupEvent> eventsAfterDeleteFailed = delegate.eventsSeen(); |
356 | assertThat(eventsAfterDeleteFailed, hasSize(1)); | 357 | assertThat(eventsAfterDeleteFailed, hasSize(1)); |
... | @@ -397,7 +398,7 @@ public class DistributedGroupStoreTest { | ... | @@ -397,7 +398,7 @@ public class DistributedGroupStoreTest { |
397 | GroupKey newKey = new DefaultGroupKey("123".getBytes()); | 398 | GroupKey newKey = new DefaultGroupKey("123".getBytes()); |
398 | groupStore.updateGroupDescription(deviceId1, | 399 | groupStore.updateGroupDescription(deviceId1, |
399 | groupKey1, | 400 | groupKey1, |
400 | - GroupStore.UpdateType.ADD, | 401 | + ADD, |
401 | buckets, | 402 | buckets, |
402 | newKey); | 403 | newKey); |
403 | Group group1 = groupStore.getGroup(deviceId1, groupId1); | 404 | Group group1 = groupStore.getGroup(deviceId1, groupId1); | ... | ... |
-
Please register or login to post a comment