Kavitha Alagesan
Committed by Gerrit Code Review

Merged master fixed conflict.

Change-Id: I1260048f4cc90c422ce6033d506c25ec38d6cc3a
...@@ -21,6 +21,8 @@ import org.onosproject.net.Device; ...@@ -21,6 +21,8 @@ import org.onosproject.net.Device;
21 import org.onosproject.net.Host; 21 import org.onosproject.net.Host;
22 import org.onosproject.net.Link; 22 import org.onosproject.net.Link;
23 import org.onosproject.net.device.DeviceAdminService; 23 import org.onosproject.net.device.DeviceAdminService;
24 +import org.onosproject.net.flow.FlowRuleService;
25 +import org.onosproject.net.group.GroupService;
24 import org.onosproject.net.host.HostAdminService; 26 import org.onosproject.net.host.HostAdminService;
25 import org.onosproject.net.intent.Intent; 27 import org.onosproject.net.intent.Intent;
26 import org.onosproject.net.intent.IntentService; 28 import org.onosproject.net.intent.IntentService;
...@@ -28,6 +30,11 @@ import org.onosproject.net.intent.IntentState; ...@@ -28,6 +30,11 @@ import org.onosproject.net.intent.IntentState;
28 import org.onosproject.net.link.LinkAdminService; 30 import org.onosproject.net.link.LinkAdminService;
29 import org.onosproject.net.region.RegionAdminService; 31 import org.onosproject.net.region.RegionAdminService;
30 import org.onosproject.ui.UiTopoLayoutService; 32 import org.onosproject.ui.UiTopoLayoutService;
33 +import java.util.EnumSet;
34 +import java.util.concurrent.CountDownLatch;
35 +import java.util.concurrent.TimeUnit;
36 +import static org.onosproject.net.intent.IntentState.FAILED;
37 +import static org.onosproject.net.intent.IntentState.WITHDRAWN;
31 38
32 /** 39 /**
33 * Wipes-out the entire network information base, i.e. devices, links, hosts, intents. 40 * Wipes-out the entire network information base, i.e. devices, links, hosts, intents.
...@@ -37,7 +44,7 @@ import org.onosproject.ui.UiTopoLayoutService; ...@@ -37,7 +44,7 @@ import org.onosproject.ui.UiTopoLayoutService;
37 public class WipeOutCommand extends ClustersListCommand { 44 public class WipeOutCommand extends ClustersListCommand {
38 45
39 private static final String PLEASE = "please"; 46 private static final String PLEASE = "please";
40 - 47 + private static final EnumSet<IntentState> CAN_PURGE = EnumSet.of(WITHDRAWN, FAILED);
41 @Argument(index = 0, name = "please", description = "Confirmation phrase", 48 @Argument(index = 0, name = "please", description = "Confirmation phrase",
42 required = false, multiValued = false) 49 required = false, multiValued = false)
43 String please = null; 50 String please = null;
...@@ -51,6 +58,8 @@ public class WipeOutCommand extends ClustersListCommand { ...@@ -51,6 +58,8 @@ public class WipeOutCommand extends ClustersListCommand {
51 58
52 wipeOutIntents(); 59 wipeOutIntents();
53 wipeOutHosts(); 60 wipeOutHosts();
61 + wipeOutFlows();
62 + wipeOutGroups();
54 wipeOutDevices(); 63 wipeOutDevices();
55 wipeOutLinks(); 64 wipeOutLinks();
56 65
...@@ -61,11 +70,38 @@ public class WipeOutCommand extends ClustersListCommand { ...@@ -61,11 +70,38 @@ public class WipeOutCommand extends ClustersListCommand {
61 private void wipeOutIntents() { 70 private void wipeOutIntents() {
62 print("Wiping intents"); 71 print("Wiping intents");
63 IntentService intentService = get(IntentService.class); 72 IntentService intentService = get(IntentService.class);
73 + final CountDownLatch withdrawLatch;
74 + withdrawLatch = new CountDownLatch(1);
64 for (Intent intent : intentService.getIntents()) { 75 for (Intent intent : intentService.getIntents()) {
65 if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) { 76 if (intentService.getIntentState(intent.key()) != IntentState.WITHDRAWN) {
66 intentService.withdraw(intent); 77 intentService.withdraw(intent);
78 + try { // wait for withdraw event
79 + withdrawLatch.await(5, TimeUnit.SECONDS);
80 + } catch (InterruptedException e) {
81 + print("Timed out waiting for intent {} withdraw");
82 + }
83 + }
84 + if (CAN_PURGE.contains(intentService.getIntentState(intent.key()))) {
85 + intentService.purge(intent);
67 } 86 }
68 - intentService.purge(intent); 87 + }
88 + }
89 +
90 + private void wipeOutFlows() {
91 + print("Wiping Flows");
92 + FlowRuleService flowRuleService = get(FlowRuleService.class);
93 + DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
94 + for (Device device : deviceAdminService.getDevices()) {
95 + flowRuleService.purgeFlowRules(device.id());
96 + }
97 + }
98 +
99 + private void wipeOutGroups() {
100 + print("Wiping groups");
101 + GroupService groupService = get(GroupService.class);
102 + DeviceAdminService deviceAdminService = get(DeviceAdminService.class);
103 + for (Device device : deviceAdminService.getDevices()) {
104 + groupService.purgeGroupEntries(device.id());
69 } 105 }
70 } 106 }
71 107
......
...@@ -61,6 +61,12 @@ public interface FlowRuleService ...@@ -61,6 +61,12 @@ public interface FlowRuleService
61 void applyFlowRules(FlowRule... flowRules); 61 void applyFlowRules(FlowRule... flowRules);
62 62
63 /** 63 /**
64 + * Purges all the flow rules on the specified device.
65 + * @param deviceId device identifier
66 + */
67 + void purgeFlowRules(DeviceId deviceId);
68 +
69 + /**
64 * Removes the specified flow rules from their respective devices. If the 70 * Removes the specified flow rules from their respective devices. If the
65 * device is not presently connected to the controller, these flow will 71 * device is not presently connected to the controller, these flow will
66 * be removed once the device reconnects. 72 * be removed once the device reconnects.
......
...@@ -107,6 +107,12 @@ public interface GroupService ...@@ -107,6 +107,12 @@ public interface GroupService
107 ApplicationId appId); 107 ApplicationId appId);
108 108
109 /** 109 /**
110 + * Purges all the group entries on the specified device.
111 + * @param deviceId device identifier
112 + */
113 + void purgeGroupEntries(DeviceId deviceId);
114 +
115 + /**
110 * Deletes a group associated to an application cookie. 116 * Deletes a group associated to an application cookie.
111 * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be 117 * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be
112 * provided along with cookie depending on the result of the 118 * provided along with cookie depending on the result of the
......
...@@ -38,6 +38,10 @@ public class FlowRuleServiceAdapter implements FlowRuleService { ...@@ -38,6 +38,10 @@ public class FlowRuleServiceAdapter implements FlowRuleService {
38 } 38 }
39 39
40 @Override 40 @Override
41 + public void purgeFlowRules(DeviceId deviceId){
42 + }
43 +
44 + @Override
41 public void removeFlowRules(FlowRule... flowRules) { 45 public void removeFlowRules(FlowRule... flowRules) {
42 } 46 }
43 47
......
...@@ -244,6 +244,12 @@ public class FlowRuleManager ...@@ -244,6 +244,12 @@ public class FlowRuleManager
244 } 244 }
245 245
246 @Override 246 @Override
247 + public void purgeFlowRules(DeviceId deviceId) {
248 + checkPermission(FLOWRULE_WRITE);
249 + store.purgeFlowRule(deviceId);
250 + }
251 +
252 + @Override
247 public void removeFlowRules(FlowRule... flowRules) { 253 public void removeFlowRules(FlowRule... flowRules) {
248 checkPermission(FLOWRULE_WRITE); 254 checkPermission(FLOWRULE_WRITE);
249 255
......
...@@ -224,6 +224,13 @@ public class GroupManager ...@@ -224,6 +224,13 @@ public class GroupManager
224 newCookie); 224 newCookie);
225 } 225 }
226 226
227 + @Override
228 + public void purgeGroupEntries(DeviceId deviceId) {
229 + checkPermission(GROUP_WRITE);
230 + store.purgeGroupEntry(deviceId);
231 + }
232 +
233 +
227 /** 234 /**
228 * Delete a group associated to an application cookie. 235 * Delete a group associated to an application cookie.
229 * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be 236 * GROUP_DELETED or GROUP_DELETE_FAILED notifications would be
......
...@@ -260,6 +260,22 @@ public class FlowRuleManagerTest { ...@@ -260,6 +260,22 @@ public class FlowRuleManagerTest {
260 } 260 }
261 261
262 @Test 262 @Test
263 + public void purgeFlowRules() {
264 + FlowRule f1 = addFlowRule(1);
265 + FlowRule f2 = addFlowRule(2);
266 + FlowRule f3 = addFlowRule(3);
267 + assertEquals("3 rules should exist", 3, flowCount());
268 + FlowEntry fe1 = new DefaultFlowEntry(f1);
269 + FlowEntry fe2 = new DefaultFlowEntry(f2);
270 + FlowEntry fe3 = new DefaultFlowEntry(f3);
271 + providerService.pushFlowMetrics(DID, ImmutableList.of(fe1, fe2, fe3));
272 + validateEvents(RULE_ADD_REQUESTED, RULE_ADD_REQUESTED, RULE_ADD_REQUESTED,
273 + RULE_ADDED, RULE_ADDED, RULE_ADDED);
274 + mgr.purgeFlowRules(DID);
275 + assertEquals("0 rule should exist", 0, flowCount());
276 + }
277 +
278 + @Test
263 public void removeFlowRules() { 279 public void removeFlowRules() {
264 FlowRule f1 = addFlowRule(1); 280 FlowRule f1 = addFlowRule(1);
265 FlowRule f2 = addFlowRule(2); 281 FlowRule f2 = addFlowRule(2);
......
...@@ -188,6 +188,21 @@ public class GroupManagerTest { ...@@ -188,6 +188,21 @@ public class GroupManagerTest {
188 } 188 }
189 189
190 /** 190 /**
191 + * Tests group Purge Operation.
192 + */
193 + @Test
194 + public void testPurgeGroups() {
195 + //Test Group creation before AUDIT process
196 + testGroupCreationBeforeAudit(DID);
197 + programmableTestCleanUp();
198 + testAuditWithExtraneousMissingGroups(DID);
199 + // Test group add bucket operations
200 + testAddBuckets(DID);
201 + // Test group Purge operations
202 + testPurgeGroupEntry(DID);
203 + }
204 +
205 + /**
191 * Tests group bucket modifications (additions and deletions) and 206 * Tests group bucket modifications (additions and deletions) and
192 * Tests group deletion. 207 * Tests group deletion.
193 */ 208 */
...@@ -507,6 +522,13 @@ public class GroupManagerTest { ...@@ -507,6 +522,13 @@ public class GroupManagerTest {
507 internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED)); 522 internalListener.validateEvent(Collections.singletonList(GroupEvent.Type.GROUP_UPDATED));
508 } 523 }
509 524
525 + // Test purge group entry operations
526 + private void testPurgeGroupEntry(DeviceId deviceId) {
527 + assertEquals(1, Iterables.size(groupService.getGroups(deviceId, appId)));
528 + groupService.purgeGroupEntries(deviceId);
529 + assertEquals(0, Iterables.size(groupService.getGroups(deviceId, appId)));
530 + }
531 +
510 // Test group remove operations 532 // Test group remove operations
511 private void testRemoveGroup(DeviceId deviceId) { 533 private void testRemoveGroup(DeviceId deviceId) {
512 GroupKey currKey = new DefaultGroupKey("group1RemoveBuckets".getBytes()); 534 GroupKey currKey = new DefaultGroupKey("group1RemoveBuckets".getBytes());
......