Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.store.trivial.impl; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | import static org.onosproject.net.DeviceId.deviceId; |
| 20 | |
| 21 | import java.util.ArrayList; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 22 | import java.util.Arrays; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 23 | import java.util.List; |
| 24 | |
| 25 | import org.junit.After; |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.onlab.packet.MacAddress; |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 29 | import org.onlab.packet.MplsLabel; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 30 | import org.onosproject.core.ApplicationId; |
| 31 | import org.onosproject.core.DefaultApplicationId; |
| 32 | import org.onosproject.core.GroupId; |
| 33 | import org.onosproject.net.DeviceId; |
| 34 | import org.onosproject.net.PortNumber; |
| 35 | import org.onosproject.net.flow.DefaultTrafficTreatment; |
| 36 | import org.onosproject.net.flow.TrafficTreatment; |
| 37 | import org.onosproject.net.group.DefaultGroupBucket; |
| 38 | import org.onosproject.net.group.DefaultGroupDescription; |
| 39 | import org.onosproject.net.group.Group; |
| 40 | import org.onosproject.net.group.GroupBucket; |
| 41 | import org.onosproject.net.group.GroupBuckets; |
| 42 | import org.onosproject.net.group.GroupDescription; |
| 43 | import org.onosproject.net.group.GroupEvent; |
| 44 | import org.onosproject.net.group.GroupKey; |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 45 | import org.onosproject.net.group.GroupOperation; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 46 | import org.onosproject.net.group.GroupStore.UpdateType; |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 47 | import org.onosproject.net.group.GroupStoreDelegate; |
| 48 | |
| 49 | import com.google.common.collect.Iterables; |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * Test of the simple DeviceStore implementation. |
| 53 | */ |
| 54 | public class SimpleGroupStoreTest { |
| 55 | |
| 56 | private SimpleGroupStore simpleGroupStore; |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 57 | private final ApplicationId appId = |
| 58 | new DefaultApplicationId(2, "org.groupstore.test"); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 59 | |
| 60 | public static final DeviceId D1 = deviceId("of:1"); |
| 61 | |
| 62 | @Before |
| 63 | public void setUp() throws Exception { |
| 64 | simpleGroupStore = new SimpleGroupStore(); |
| 65 | simpleGroupStore.activate(); |
| 66 | } |
| 67 | |
| 68 | @After |
| 69 | public void tearDown() throws Exception { |
| 70 | simpleGroupStore.deactivate(); |
| 71 | } |
| 72 | |
| 73 | public class TestGroupKey implements GroupKey { |
| 74 | private String groupId; |
| 75 | |
| 76 | public TestGroupKey(String id) { |
| 77 | this.groupId = id; |
| 78 | } |
| 79 | |
| 80 | public String id() { |
| 81 | return this.groupId; |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public int hashCode() { |
| 86 | return groupId.hashCode(); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public boolean equals(Object obj) { |
| 91 | if (obj instanceof TestGroupKey) { |
| 92 | return this.groupId.equals(((TestGroupKey) obj).id()); |
| 93 | } |
| 94 | return false; |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | private class InternalGroupStoreDelegate |
| 99 | implements GroupStoreDelegate { |
| 100 | private GroupId createdGroupId = null; |
| 101 | private GroupKey createdGroupKey; |
| 102 | private GroupBuckets createdBuckets; |
| 103 | private GroupEvent.Type expectedEvent; |
| 104 | |
| 105 | public InternalGroupStoreDelegate(GroupKey key, |
| 106 | GroupBuckets buckets, |
| 107 | GroupEvent.Type expectedEvent) { |
| 108 | this.createdBuckets = buckets; |
| 109 | this.createdGroupKey = key; |
| 110 | this.expectedEvent = expectedEvent; |
| 111 | } |
| 112 | @Override |
| 113 | public void notify(GroupEvent event) { |
| 114 | assertEquals(expectedEvent, event.type()); |
| 115 | assertEquals(Group.Type.SELECT, event.subject().type()); |
| 116 | assertEquals(D1, event.subject().deviceId()); |
| 117 | assertEquals(createdGroupKey, event.subject().appCookie()); |
| 118 | assertEquals(createdBuckets.buckets(), event.subject().buckets().buckets()); |
| 119 | if (expectedEvent == GroupEvent.Type.GROUP_ADD_REQUESTED) { |
| 120 | createdGroupId = event.subject().id(); |
| 121 | assertEquals(Group.GroupState.PENDING_ADD, |
| 122 | event.subject().state()); |
| 123 | } else if (expectedEvent == GroupEvent.Type.GROUP_ADDED) { |
| 124 | createdGroupId = event.subject().id(); |
| 125 | assertEquals(Group.GroupState.ADDED, |
| 126 | event.subject().state()); |
| 127 | } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_REQUESTED) { |
| 128 | assertEquals(Group.GroupState.PENDING_UPDATE, |
| 129 | event.subject().state()); |
| 130 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_REQUESTED) { |
| 131 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 132 | event.subject().state()); |
| 133 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVED) { |
| 134 | createdGroupId = event.subject().id(); |
| 135 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 136 | event.subject().state()); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 137 | } else if (expectedEvent == GroupEvent.Type.GROUP_ADD_FAILED) { |
| 138 | createdGroupId = event.subject().id(); |
| 139 | assertEquals(Group.GroupState.PENDING_ADD, |
| 140 | event.subject().state()); |
| 141 | } else if (expectedEvent == GroupEvent.Type.GROUP_UPDATE_FAILED) { |
| 142 | createdGroupId = event.subject().id(); |
| 143 | assertEquals(Group.GroupState.PENDING_UPDATE, |
| 144 | event.subject().state()); |
| 145 | } else if (expectedEvent == GroupEvent.Type.GROUP_REMOVE_FAILED) { |
| 146 | createdGroupId = event.subject().id(); |
| 147 | assertEquals(Group.GroupState.PENDING_DELETE, |
| 148 | event.subject().state()); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
| 152 | public void verifyGroupId(GroupId id) { |
| 153 | assertEquals(createdGroupId, id); |
| 154 | } |
| 155 | } |
| 156 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 157 | /** |
| 158 | * Tests group store operations. The following operations are tested: |
| 159 | * a)Tests device group audit completion status change |
| 160 | * b)Tests storeGroup operation |
| 161 | * c)Tests getGroupCount operation |
| 162 | * d)Tests getGroup operation |
| 163 | * e)Tests getGroups operation |
| 164 | * f)Tests addOrUpdateGroupEntry operation from southbound |
| 165 | * g)Tests updateGroupDescription for ADD operation from northbound |
| 166 | * h)Tests updateGroupDescription for REMOVE operation from northbound |
| 167 | * i)Tests deleteGroupDescription operation from northbound |
| 168 | * j)Tests removeGroupEntry operation from southbound |
| 169 | */ |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 170 | @Test |
| 171 | public void testGroupStoreOperations() { |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 172 | // Set the Device AUDIT completed in the store |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 173 | simpleGroupStore.deviceInitialAuditCompleted(D1, true); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 174 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 175 | // Testing storeGroup operation |
| 176 | TestGroupKey newKey = new TestGroupKey("group1"); |
| 177 | testStoreAndGetGroup(newKey); |
| 178 | |
| 179 | // Testing addOrUpdateGroupEntry operation from southbound |
| 180 | TestGroupKey currKey = newKey; |
| 181 | testAddGroupEntryFromSB(currKey); |
| 182 | |
| 183 | // Testing updateGroupDescription for ADD operation from northbound |
| 184 | newKey = new TestGroupKey("group1AddBuckets"); |
| 185 | testAddBuckets(currKey, newKey); |
| 186 | |
| 187 | // Testing updateGroupDescription for REMOVE operation from northbound |
| 188 | currKey = newKey; |
| 189 | newKey = new TestGroupKey("group1RemoveBuckets"); |
| 190 | testRemoveBuckets(currKey, newKey); |
| 191 | |
| 192 | // Testing addOrUpdateGroupEntry operation from southbound |
| 193 | currKey = newKey; |
| 194 | testUpdateGroupEntryFromSB(currKey); |
| 195 | |
| 196 | // Testing deleteGroupDescription operation from northbound |
| 197 | testDeleteGroup(currKey); |
| 198 | |
| 199 | // Testing removeGroupEntry operation from southbound |
| 200 | testRemoveGroupFromSB(currKey); |
| 201 | } |
| 202 | |
| 203 | // Testing storeGroup operation |
| 204 | private void testStoreAndGetGroup(TestGroupKey key) { |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 205 | PortNumber[] ports = {PortNumber.portNumber(31), |
| 206 | PortNumber.portNumber(32)}; |
| 207 | List<PortNumber> outPorts = new ArrayList<PortNumber>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 208 | outPorts.addAll(Arrays.asList(ports)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 209 | |
| 210 | List<GroupBucket> buckets = new ArrayList<GroupBucket>(); |
| 211 | for (PortNumber portNumber: outPorts) { |
| 212 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 213 | tBuilder.setOutput(portNumber) |
| 214 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) |
| 215 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 216 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 217 | .setMpls(MplsLabel.mplsLabel(106)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 218 | buckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 219 | tBuilder.build())); |
| 220 | } |
| 221 | GroupBuckets groupBuckets = new GroupBuckets(buckets); |
| 222 | GroupDescription groupDesc = new DefaultGroupDescription( |
| 223 | D1, |
| 224 | Group.Type.SELECT, |
| 225 | groupBuckets, |
| 226 | key, |
| 227 | appId); |
| 228 | InternalGroupStoreDelegate checkStoreGroupDelegate = |
| 229 | new InternalGroupStoreDelegate(key, |
| 230 | groupBuckets, |
| 231 | GroupEvent.Type.GROUP_ADD_REQUESTED); |
| 232 | simpleGroupStore.setDelegate(checkStoreGroupDelegate); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 233 | // Testing storeGroup operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 234 | simpleGroupStore.storeGroupDescription(groupDesc); |
| 235 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 236 | // Testing getGroupCount operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 237 | assertEquals(1, simpleGroupStore.getGroupCount(D1)); |
| 238 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 239 | // Testing getGroup operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 240 | Group createdGroup = simpleGroupStore.getGroup(D1, key); |
| 241 | checkStoreGroupDelegate.verifyGroupId(createdGroup.id()); |
| 242 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 243 | // Testing getGroups operation |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 244 | Iterable<Group> createdGroups = simpleGroupStore.getGroups(D1); |
| 245 | int groupCount = 0; |
| 246 | for (Group group:createdGroups) { |
| 247 | checkStoreGroupDelegate.verifyGroupId(group.id()); |
| 248 | groupCount++; |
| 249 | } |
| 250 | assertEquals(1, groupCount); |
| 251 | simpleGroupStore.unsetDelegate(checkStoreGroupDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 252 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 253 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 254 | // Testing addOrUpdateGroupEntry operation from southbound |
| 255 | private void testAddGroupEntryFromSB(TestGroupKey currKey) { |
| 256 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
| 257 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 258 | InternalGroupStoreDelegate addGroupEntryDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 259 | new InternalGroupStoreDelegate(currKey, |
| 260 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 261 | GroupEvent.Type.GROUP_ADDED); |
| 262 | simpleGroupStore.setDelegate(addGroupEntryDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 263 | simpleGroupStore.addOrUpdateGroupEntry(existingGroup); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 264 | simpleGroupStore.unsetDelegate(addGroupEntryDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 265 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 266 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 267 | // Testing addOrUpdateGroupEntry operation from southbound |
| 268 | private void testUpdateGroupEntryFromSB(TestGroupKey currKey) { |
| 269 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
| 270 | |
| 271 | InternalGroupStoreDelegate updateGroupEntryDelegate = |
| 272 | new InternalGroupStoreDelegate(currKey, |
| 273 | existingGroup.buckets(), |
| 274 | GroupEvent.Type.GROUP_UPDATED); |
| 275 | simpleGroupStore.setDelegate(updateGroupEntryDelegate); |
| 276 | simpleGroupStore.addOrUpdateGroupEntry(existingGroup); |
| 277 | simpleGroupStore.unsetDelegate(updateGroupEntryDelegate); |
| 278 | } |
| 279 | |
| 280 | // Testing updateGroupDescription for ADD operation from northbound |
| 281 | private void testAddBuckets(TestGroupKey currKey, TestGroupKey addKey) { |
| 282 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
| 283 | List<GroupBucket> buckets = new ArrayList<GroupBucket>(); |
| 284 | buckets.addAll(existingGroup.buckets().buckets()); |
| 285 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 286 | PortNumber[] newNeighborPorts = {PortNumber.portNumber(41), |
| 287 | PortNumber.portNumber(42)}; |
| 288 | List<PortNumber> newOutPorts = new ArrayList<PortNumber>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 289 | newOutPorts.addAll(Arrays.asList(newNeighborPorts[0])); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 290 | |
| 291 | List<GroupBucket> toAddBuckets = new ArrayList<GroupBucket>(); |
| 292 | for (PortNumber portNumber: newOutPorts) { |
| 293 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 294 | tBuilder.setOutput(portNumber) |
| 295 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:03")) |
| 296 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 297 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 298 | .setMpls(MplsLabel.mplsLabel(106)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 299 | toAddBuckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 300 | tBuilder.build())); |
| 301 | } |
| 302 | GroupBuckets toAddGroupBuckets = new GroupBuckets(toAddBuckets); |
| 303 | buckets.addAll(toAddBuckets); |
| 304 | GroupBuckets updatedGroupBuckets = new GroupBuckets(buckets); |
| 305 | InternalGroupStoreDelegate updateGroupDescDelegate = |
| 306 | new InternalGroupStoreDelegate(addKey, |
| 307 | updatedGroupBuckets, |
| 308 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 309 | simpleGroupStore.setDelegate(updateGroupDescDelegate); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 310 | simpleGroupStore.updateGroupDescription(D1, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 311 | currKey, |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 312 | UpdateType.ADD, |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 313 | toAddGroupBuckets, |
| 314 | addKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 315 | simpleGroupStore.unsetDelegate(updateGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 316 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 317 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 318 | // Testing updateGroupDescription for REMOVE operation from northbound |
| 319 | private void testRemoveBuckets(TestGroupKey currKey, TestGroupKey removeKey) { |
| 320 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
| 321 | List<GroupBucket> buckets = new ArrayList<GroupBucket>(); |
| 322 | buckets.addAll(existingGroup.buckets().buckets()); |
| 323 | |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 324 | List<GroupBucket> toRemoveBuckets = new ArrayList<GroupBucket>(); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 325 | |
| 326 | // There should be 4 buckets in the current group |
| 327 | toRemoveBuckets.add(buckets.remove(0)); |
| 328 | toRemoveBuckets.add(buckets.remove(1)); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 329 | GroupBuckets toRemoveGroupBuckets = new GroupBuckets(toRemoveBuckets); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 330 | |
| 331 | GroupBuckets remainingGroupBuckets = new GroupBuckets(buckets); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 332 | InternalGroupStoreDelegate removeGroupDescDelegate = |
| 333 | new InternalGroupStoreDelegate(removeKey, |
| 334 | remainingGroupBuckets, |
| 335 | GroupEvent.Type.GROUP_UPDATE_REQUESTED); |
| 336 | simpleGroupStore.setDelegate(removeGroupDescDelegate); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 337 | simpleGroupStore.updateGroupDescription(D1, |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 338 | currKey, |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 339 | UpdateType.REMOVE, |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 340 | toRemoveGroupBuckets, |
| 341 | removeKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 342 | simpleGroupStore.unsetDelegate(removeGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 343 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 344 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 345 | // Testing deleteGroupDescription operation from northbound |
| 346 | private void testDeleteGroup(TestGroupKey currKey) { |
| 347 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 348 | InternalGroupStoreDelegate deleteGroupDescDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 349 | new InternalGroupStoreDelegate(currKey, |
| 350 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 351 | GroupEvent.Type.GROUP_REMOVE_REQUESTED); |
| 352 | simpleGroupStore.setDelegate(deleteGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 353 | simpleGroupStore.deleteGroupDescription(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 354 | simpleGroupStore.unsetDelegate(deleteGroupDescDelegate); |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 355 | } |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 356 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 357 | // Testing removeGroupEntry operation from southbound |
| 358 | private void testRemoveGroupFromSB(TestGroupKey currKey) { |
| 359 | Group existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 360 | InternalGroupStoreDelegate removeGroupEntryDelegate = |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 361 | new InternalGroupStoreDelegate(currKey, |
| 362 | existingGroup.buckets(), |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 363 | GroupEvent.Type.GROUP_REMOVED); |
| 364 | simpleGroupStore.setDelegate(removeGroupEntryDelegate); |
| 365 | simpleGroupStore.removeGroupEntry(existingGroup); |
| 366 | |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 367 | // Testing getGroup operation |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 368 | existingGroup = simpleGroupStore.getGroup(D1, currKey); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 369 | assertEquals(null, existingGroup); |
Srikanth Vavilapalli | 45c27c8 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 370 | assertEquals(0, Iterables.size(simpleGroupStore.getGroups(D1))); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 371 | assertEquals(0, simpleGroupStore.getGroupCount(D1)); |
| 372 | |
| 373 | simpleGroupStore.unsetDelegate(removeGroupEntryDelegate); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | @Test |
| 377 | public void testGroupOperationFailure() { |
| 378 | |
Srikanth Vavilapalli | ed12ae5 | 2015-02-09 14:43:19 -0800 | [diff] [blame] | 379 | simpleGroupStore.deviceInitialAuditCompleted(D1, true); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 380 | |
| 381 | ApplicationId appId = |
| 382 | new DefaultApplicationId(2, "org.groupstore.test"); |
| 383 | TestGroupKey key = new TestGroupKey("group1"); |
| 384 | PortNumber[] ports = {PortNumber.portNumber(31), |
| 385 | PortNumber.portNumber(32)}; |
| 386 | List<PortNumber> outPorts = new ArrayList<PortNumber>(); |
| 387 | outPorts.add(ports[0]); |
| 388 | outPorts.add(ports[1]); |
| 389 | |
| 390 | List<GroupBucket> buckets = new ArrayList<GroupBucket>(); |
| 391 | for (PortNumber portNumber: outPorts) { |
| 392 | TrafficTreatment.Builder tBuilder = DefaultTrafficTreatment.builder(); |
| 393 | tBuilder.setOutput(portNumber) |
| 394 | .setEthDst(MacAddress.valueOf("00:00:00:00:00:02")) |
| 395 | .setEthSrc(MacAddress.valueOf("00:00:00:00:00:01")) |
| 396 | .pushMpls() |
Michele Santuari | 4b6019e | 2014-12-19 11:31:45 +0100 | [diff] [blame] | 397 | .setMpls(MplsLabel.mplsLabel(106)); |
sangho | 7ff0181 | 2015-02-09 16:21:53 -0800 | [diff] [blame] | 398 | buckets.add(DefaultGroupBucket.createSelectGroupBucket( |
| 399 | tBuilder.build())); |
| 400 | } |
| 401 | GroupBuckets groupBuckets = new GroupBuckets(buckets); |
| 402 | GroupDescription groupDesc = new DefaultGroupDescription( |
| 403 | D1, |
| 404 | Group.Type.SELECT, |
| 405 | groupBuckets, |
| 406 | key, |
| 407 | appId); |
| 408 | InternalGroupStoreDelegate checkStoreGroupDelegate = |
| 409 | new InternalGroupStoreDelegate(key, |
| 410 | groupBuckets, |
| 411 | GroupEvent.Type.GROUP_ADD_REQUESTED); |
| 412 | simpleGroupStore.setDelegate(checkStoreGroupDelegate); |
| 413 | // Testing storeGroup operation |
| 414 | simpleGroupStore.storeGroupDescription(groupDesc); |
| 415 | simpleGroupStore.unsetDelegate(checkStoreGroupDelegate); |
| 416 | |
| 417 | // Testing Group add operation failure |
| 418 | Group createdGroup = simpleGroupStore.getGroup(D1, key); |
| 419 | checkStoreGroupDelegate.verifyGroupId(createdGroup.id()); |
| 420 | |
| 421 | GroupOperation groupAddOp = GroupOperation. |
| 422 | createAddGroupOperation(createdGroup.id(), |
| 423 | createdGroup.type(), |
| 424 | createdGroup.buckets()); |
| 425 | InternalGroupStoreDelegate checkGroupAddFailureDelegate = |
| 426 | new InternalGroupStoreDelegate(key, |
| 427 | groupBuckets, |
| 428 | GroupEvent.Type.GROUP_ADD_FAILED); |
| 429 | simpleGroupStore.setDelegate(checkGroupAddFailureDelegate); |
| 430 | simpleGroupStore.groupOperationFailed(D1, groupAddOp); |
| 431 | |
| 432 | |
| 433 | // Testing Group modify operation failure |
| 434 | simpleGroupStore.unsetDelegate(checkGroupAddFailureDelegate); |
| 435 | GroupOperation groupModOp = GroupOperation. |
| 436 | createModifyGroupOperation(createdGroup.id(), |
| 437 | createdGroup.type(), |
| 438 | createdGroup.buckets()); |
| 439 | InternalGroupStoreDelegate checkGroupModFailureDelegate = |
| 440 | new InternalGroupStoreDelegate(key, |
| 441 | groupBuckets, |
| 442 | GroupEvent.Type.GROUP_UPDATE_FAILED); |
| 443 | simpleGroupStore.setDelegate(checkGroupModFailureDelegate); |
| 444 | simpleGroupStore.groupOperationFailed(D1, groupModOp); |
| 445 | |
| 446 | // Testing Group modify operation failure |
| 447 | simpleGroupStore.unsetDelegate(checkGroupModFailureDelegate); |
| 448 | GroupOperation groupDelOp = GroupOperation. |
| 449 | createDeleteGroupOperation(createdGroup.id(), |
| 450 | createdGroup.type()); |
| 451 | InternalGroupStoreDelegate checkGroupDelFailureDelegate = |
| 452 | new InternalGroupStoreDelegate(key, |
| 453 | groupBuckets, |
| 454 | GroupEvent.Type.GROUP_REMOVE_FAILED); |
| 455 | simpleGroupStore.setDelegate(checkGroupDelFailureDelegate); |
| 456 | simpleGroupStore.groupOperationFailed(D1, groupDelOp); |
Srikanth Vavilapalli | 0599d51 | 2015-01-30 12:57:56 -0800 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |