Toggle SingleSwitchFibInstaller via component config

Fix deactivation issues of vRouter components in addition
Clean up flows installed by SingleSwitchFibInstaller when it is deactivated

Change-Id: I398a38852deaafa693ea20a6cd17b9dd70053f21
diff --git a/apps/routing/src/main/java/org/onosproject/routing/impl/ControlPlaneRedirectManager.java b/apps/routing/src/main/java/org/onosproject/routing/impl/ControlPlaneRedirectManager.java
index 1e61cf6..5cd78a9 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/impl/ControlPlaneRedirectManager.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/impl/ControlPlaneRedirectManager.java
@@ -136,6 +136,8 @@
         interfaceService.addListener(interfaceListener);
 
         readConfig();
+
+        // FIXME There can be an issue when this component is deactivated before vRouter
         applicationService.registerDeactivateHook(this.appId, () -> provisionDevice(false));
     }
 
diff --git a/apps/routing/src/main/java/org/onosproject/routing/impl/DirectHostManager.java b/apps/routing/src/main/java/org/onosproject/routing/impl/DirectHostManager.java
index 7e0b2ac..d5c0d27 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/impl/DirectHostManager.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/impl/DirectHostManager.java
@@ -113,13 +113,8 @@
     @Activate
     public void activate(ComponentContext context) {
         componentConfigService.registerProperties(getClass());
-        modified(context);
-
         appId = coreService.registerApplication(APP_NAME);
-
-        if (enabled) {
-            enable();
-        }
+        modified(context);
     }
 
     @Modified
@@ -156,7 +151,9 @@
 
     @Deactivate
     public void deactivate() {
-        disable();
+        if (enabled) {
+            disable();
+        }
 
         componentConfigService.unregisterProperties(getClass(), false);
     }
diff --git a/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java b/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
index dcdba8e..66767a0 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/impl/SingleSwitchFibInstaller.java
@@ -178,6 +178,8 @@
 
         updateConfig();
 
+        // FIXME: There can be an issue when this component is deactivated before vRouter.
+        //        This will be addressed in CORD-710.
         applicationService.registerDeactivateHook(vrouterAppId, () -> cleanUp());
 
         log.info("Started");
@@ -185,7 +187,10 @@
 
     @Deactivate
     protected void deactivate() {
-        routeService.removeListener(routeListener);
+         // FIXME: This will also remove flows when an instance goes down.
+         //        This is a temporary solution and should be addressed in CORD-710.
+        cleanUp();
+
         deviceService.removeListener(deviceListener);
         interfaceService.removeListener(internalInterfaceList);
         networkConfigService.removeListener(configListener);
@@ -292,11 +297,10 @@
     }
 
     private Set<Interface> filterInterfaces(List<String> interfaces) {
-        Set<Interface> intfs = interfaceService.getInterfaces().stream()
+        return interfaceService.getInterfaces().stream()
                 .filter(intf -> intf.connectPoint().deviceId().equals(deviceId))
                 .filter(intf -> interfaces.contains(intf.name()))
                 .collect(Collectors.toSet());
-        return intfs;
     }
 
     private void updateRoute(ResolvedRoute route) {