Use removedSwitchEvents and removedPortEvents for rerouting

Change-Id: I8ef66c8220c30ec0254279555913aa57eedd12d9
diff --git a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
index 67902dd..8cb935f 100755
--- a/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
+++ b/src/main/java/net/onrc/onos/intent/runtime/PathCalcRuntimeModule.java
@@ -53,16 +53,8 @@
 	// private methods
 	// ================================================================================
 
-	private void reroutePaths(Collection<LinkEvent> removedLinkEvents) {
-		HashSet<PathIntent> oldPaths = new HashSet<>();
-		for (LinkEvent linkEvent : removedLinkEvents) {
-			Collection<PathIntent> intents = pathIntents.getIntentsByLink(linkEvent);
-			if (intents == null)
-				continue;
-			oldPaths.addAll(intents);
-		}
-
-		if (oldPaths.isEmpty())
+	private void reroutePaths(Collection<PathIntent> oldPaths) {
+		if (oldPaths == null || oldPaths.isEmpty())
 			return;
 
 		IntentOperationList reroutingOperation = new IntentOperationList();
@@ -85,14 +77,14 @@
 
 	@Override
 	public Map<Class<? extends IFloodlightService>, IFloodlightService> getServiceImpls() {
-		Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>(1);
+		Map<Class<? extends IFloodlightService>, IFloodlightService> m = new HashMap<>();
 		m.put(IPathCalcRuntimeService.class, this);
 		return m;
 	}
 
 	@Override
 	public Collection<Class<? extends IFloodlightService>> getModuleDependencies() {
-		Collection<Class<? extends IFloodlightService>> l = new ArrayList<>();
+		Collection<Class<? extends IFloodlightService>> l = new ArrayList<>(2);
 		l.add(IDatagridService.class);
 		l.add(INetworkGraphService.class);
 		return l;
@@ -199,8 +191,19 @@
 			Collection<LinkEvent> removedLinkEvents,
 			Collection<DeviceEvent> addedDeviceEvents,
 			Collection<DeviceEvent> removedDeviceEvents) {
-		// TODO add getIntentsByPort() and getIntentsBySwitch() to PathIntentMap.
-		reroutePaths(removedLinkEvents);
+
+		HashSet<PathIntent> affectedPaths = new HashSet<>();
+
+		for (SwitchEvent switchEvent: removedSwitchEvents)
+			affectedPaths.addAll(pathIntents.getIntentsByDpid(switchEvent.getDpid()));
+
+		for (PortEvent portEvent: removedPortEvents)
+			affectedPaths.addAll(pathIntents.getIntentsByPort(portEvent.getDpid(), portEvent.getNumber()));
+
+		for (LinkEvent linkEvent: removedLinkEvents)
+			affectedPaths.addAll(pathIntents.getIntentsByLink(linkEvent));
+
+		reroutePaths(affectedPaths);
 	}
 
 	// ================================================================================
@@ -246,4 +249,4 @@
 		highLevelIntents.changeStates(parentStates);
 		pathIntents.changeStates(value);
 	}
-}
\ No newline at end of file
+}