Fix vRouter app IDs and deactivation of components.

CORD-710.

Change-Id: I66da47eef8ec5978c3f36447be4d12f6f07f88f8
diff --git a/apps/routing/cpr/src/main/java/org/onosproject/routing/cpr/ControlPlaneRedirectManager.java b/apps/routing/cpr/src/main/java/org/onosproject/routing/cpr/ControlPlaneRedirectManager.java
index d36607f..920c21b 100644
--- a/apps/routing/cpr/src/main/java/org/onosproject/routing/cpr/ControlPlaneRedirectManager.java
+++ b/apps/routing/cpr/src/main/java/org/onosproject/routing/cpr/ControlPlaneRedirectManager.java
@@ -122,7 +122,7 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected ApplicationService applicationService;
 
-    private static final String APP_NAME = "org.onosproject.vrouter";
+    private static final String APP_NAME = "org.onosproject.cpr";
     private ApplicationId appId;
 
     private ConnectPoint controlPlaneConnectPoint;
@@ -137,7 +137,7 @@
     private final InternalHostListener hostListener = new InternalHostListener();
 
     @Activate
-    public void activate() {
+    protected void activate() {
         this.appId = coreService.registerApplication(APP_NAME);
 
         networkConfigService.addListener(networkConfigListener);
@@ -147,8 +147,6 @@
 
         processRouterConfig();
 
-
-        // FIXME There can be an issue when this component is deactivated before vRouter
         applicationService.registerDeactivateHook(this.appId, () -> {
             if (interfaceManager != null) {
                 interfaceManager.cleanup();
@@ -157,7 +155,7 @@
     }
 
     @Deactivate
-    public void deactivate() {
+    protected void deactivate() {
         networkConfigService.removeListener(networkConfigListener);
         hostService.removeListener(hostListener);
         asyncDeviceFetcher.shutdown();
diff --git a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstaller.java b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
similarity index 96%
rename from apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstaller.java
rename to apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
index c6b3af4..6401679 100644
--- a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstaller.java
+++ b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
@@ -85,10 +85,10 @@
  * Programs routes to a single OpenFlow switch.
  */
 @Component(immediate = true)
-public class SingleSwitchFibInstaller {
+public class FibInstaller {
 
     private final Logger log = LoggerFactory.getLogger(getClass());
-    private static final String APP_NAME = "org.onosproject.vrouter";
+    private static final String APP_NAME = "org.onosproject.fibinstaller";
 
     private static final int PRIORITY_OFFSET = 100;
     private static final int PRIORITY_MULTIPLIER = 5;
@@ -138,7 +138,7 @@
 
     private ApplicationId coreAppId;
     private ApplicationId routerAppId;
-    private ApplicationId vrouterAppId;
+    private ApplicationId fibAppId;
 
     // Reference count for how many times a next hop is used by a route
     private final Multiset<IpAddress> nextHopsCount = ConcurrentHashMultiset.create();
@@ -168,7 +168,7 @@
 
         coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME);
         routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
-        vrouterAppId = coreService.registerApplication(APP_NAME);
+        fibAppId = coreService.registerApplication(APP_NAME);
 
         networkConfigRegistry.registerConfigFactory(mcastConfigFactory);
 
@@ -178,19 +178,13 @@
 
         processRouterConfig();
 
-        // FIXME: There can be an issue when this component is deactivated before vRouter.
-        //        This will be addressed in CORD-710.
-        applicationService.registerDeactivateHook(vrouterAppId, () -> cleanUp());
+        applicationService.registerDeactivateHook(fibAppId, () -> cleanUp());
 
         log.info("Started");
     }
 
     @Deactivate
     protected void deactivate() {
-         // FIXME: This will also remove flows when an instance goes down.
-         //        This is a temporary solution and should be addressed in CORD-710.
-        cleanUp();
-
         asyncDeviceFetcher.shutdown();
         networkConfigService.removeListener(configListener);
 
@@ -295,7 +289,7 @@
         int priority = prefix.prefixLength() * PRIORITY_MULTIPLIER + PRIORITY_OFFSET;
 
         ForwardingObjective.Builder fwdBuilder = DefaultForwardingObjective.builder()
-                .fromApp(routerAppId)
+                .fromApp(fibAppId)
                 .makePermanent()
                 .withSelector(selector)
                 .withPriority(priority)
@@ -367,7 +361,7 @@
                     .withId(nextId)
                     .addTreatment(treatment.build())
                     .withType(NextObjective.Type.SIMPLE)
-                    .fromApp(routerAppId);
+                    .fromApp(fibAppId);
             if (metabuilder != null) {
                 nextBuilder.withMeta(metabuilder.build());
             }
@@ -457,7 +451,7 @@
                     .pushVlan().setVlanId(assignedVlan).build();
             fob.withMeta(tt);
         }
-        fob.permit().fromApp(routerAppId);
+        fob.permit().fromApp(fibAppId);
         sendFilteringObjective(install, fob, intf);
 
         if (controlPlaneConnectPoint != null) {
@@ -489,7 +483,7 @@
                 .pushVlan().setVlanId(assignedVlan).build();
         fob.withMeta(tt);
 
-        fob.permit().fromApp(routerAppId);
+        fob.permit().fromApp(fibAppId);
         sendFilteringObjective(install, fob, intf);
     }
 
diff --git a/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstallerTest.java b/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
similarity index 97%
rename from apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstallerTest.java
rename to apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
index f7736f7..e17d779 100644
--- a/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/SingleSwitchFibInstallerTest.java
+++ b/apps/routing/fibinstaller/src/test/java/org/onosproject/routing/fibinstaller/FibInstallerTest.java
@@ -81,7 +81,7 @@
 /**
  * Unit tests for SingleSwitchFibInstaller.
  */
-public class SingleSwitchFibInstallerTest {
+public class FibInstallerTest {
 
     private static final DeviceId DEVICE_ID = DeviceId.deviceId("of:0000000000000001");
 
@@ -118,12 +118,12 @@
     private DeviceListener deviceListener;
 
     private RouterConfig routerConfig;
-    private SingleSwitchFibInstaller sSfibInstaller;
+    private FibInstaller sSfibInstaller;
     private InterfaceListener interfaceListener;
 
     @Before
     public void setUp() throws Exception {
-        sSfibInstaller = new SingleSwitchFibInstaller();
+        sSfibInstaller = new FibInstaller();
 
         sSfibInstaller.componentConfigService = createNiceMock(ComponentConfigService.class);
 
@@ -225,7 +225,7 @@
                      .setVlanPcp((byte) 0);
         } else {
             metabuilder = DefaultTrafficSelector.builder();
-            metabuilder.matchVlanId(VlanId.vlanId(SingleSwitchFibInstaller.ASSIGNED_VLAN));
+            metabuilder.matchVlanId(VlanId.vlanId(FibInstaller.ASSIGNED_VLAN));
         }
 
         treatment.setOutput(port);
@@ -391,7 +391,7 @@
     private class TestRouteService extends RouteServiceAdapter {
         @Override
         public void addListener(RouteListener listener) {
-            SingleSwitchFibInstallerTest.this.routeListener = listener;
+            FibInstallerTest.this.routeListener = listener;
         }
     }
 
@@ -425,7 +425,7 @@
 
         @Override
         public void addListener(DeviceListener listener) {
-            SingleSwitchFibInstallerTest.this.deviceListener = listener;
+            FibInstallerTest.this.deviceListener = listener;
         }
     }
 }