Moved registering routing configs out of the RoutingConfigImpl

Change-Id: Ib2e7bcfd7a84ee3dc8a285265ca4599e99744531
diff --git a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
index ce43a6a..54b6337 100644
--- a/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
+++ b/apps/bgprouter/src/main/java/org/onosproject/bgprouter/BgpRouter.java
@@ -25,7 +25,7 @@
 import org.onosproject.incubator.component.ComponentService;
 import org.onosproject.incubator.net.intf.InterfaceService;
 import org.onosproject.net.DeviceId;
-import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.NetworkConfigRegistry;
 import org.onosproject.net.device.DeviceEvent;
 import org.onosproject.net.device.DeviceListener;
 import org.onosproject.net.device.DeviceService;
@@ -33,7 +33,7 @@
 import org.onosproject.net.packet.PacketService;
 import org.onosproject.routing.RoutingService;
 import org.onosproject.routing.config.BgpConfig;
-import org.onosproject.routing.config.RoutingConfigurationService;
+import org.onosproject.routing.config.RoutingConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -54,17 +54,11 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected CoreService coreService;
 
-    // We depend on the routing configuration being available before starting
-    // up. When we have dynamic configuration support this will no longer be
-    // necessary.
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected RoutingConfigurationService routingConfigurationService;
-
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected InterfaceService interfaceService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected NetworkConfigService networkConfigService;
+    protected NetworkConfigRegistry networkConfigService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected PacketService packetService;
@@ -101,6 +95,8 @@
     protected void activate() {
         appId = coreService.registerApplication(BGP_ROUTER_APP);
 
+        RoutingConfiguration.register(networkConfigService);
+
         components.forEach(name -> componentService.activate(appId, name));
 
         ApplicationId routerAppId = coreService.getAppId(RoutingService.ROUTER_APP_ID);
@@ -139,6 +135,8 @@
     protected void deactivate() {
         components.forEach(name -> componentService.deactivate(appId, name));
 
+        RoutingConfiguration.unregister(networkConfigService);
+
         connectivityManager.stop();
         icmpHandler.stop();
         deviceService.removeListener(deviceListener);
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/Router.java b/apps/routing-api/src/main/java/org/onosproject/routing/Router.java
index 855084e..c6ee281 100644
--- a/apps/routing-api/src/main/java/org/onosproject/routing/Router.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/Router.java
@@ -96,6 +96,7 @@
         asyncDeviceFetcher.shutdown();
 
         interfaceService.removeListener(listener);
+        asyncDeviceFetcher.shutdown();
 
         unprovision();
     }
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java
deleted file mode 100644
index ddfd1db..0000000
--- a/apps/routing-api/src/main/java/org/onosproject/routing/config/RouterConfigHelper.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.routing.config;
-
-import com.google.common.collect.Sets;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.routing.RoutingService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * Helper class to manage retrieving config from multiple Config sections.
- * Should be unnecessary once old config is removed.
- */
-public final class RouterConfigHelper {
-
-    private static final String WARNING =
-            "Config apps/org.onosproject.routing/router is deprecated "
-                    + "and will be removed in a future release.";
-    private static final String WARNING2 =
-            "Use apps/org.onosproject.routing/routers instead";
-
-    private static final Logger log = LoggerFactory.getLogger(RouterConfigHelper.class);
-
-    private RouterConfigHelper() {
-        // make checkstyle happy
-    }
-
-    /**
-     * Retrieves the router configurations.
-     *
-     * @param configService network config service
-     * @param routingAppId routing app ID
-     * @return set of router configurations
-     */
-    public static Set<RoutersConfig.Router> getRouterConfigurations(
-            NetworkConfigService configService, ApplicationId routingAppId) {
-
-        RouterConfig config = configService.getConfig(
-                routingAppId, RoutingService.ROUTER_CONFIG_CLASS);
-        RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class);
-
-        if (config != null) {
-            log.warn(WARNING);
-            log.warn(WARNING2);
-
-            return Collections.singleton(
-                    new RoutersConfig.Router(config.getControlPlaneConnectPoint(),
-                            config.getOspfEnabled(),
-                            Sets.newHashSet(config.getInterfaces())));
-        } else if (multiConfig != null) {
-            return multiConfig.getRouters();
-        } else {
-            return Collections.emptySet();
-        }
-    }
-}
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfiguration.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfiguration.java
new file mode 100644
index 0000000..8363824
--- /dev/null
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfiguration.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2017-present Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.routing.config;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Sets;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.onosproject.routing.RoutingService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * Helper class to manage routing configurations.
+ */
+public final class RoutingConfiguration {
+
+    private static final String WARNING =
+            "Config apps/org.onosproject.routing/router is deprecated "
+                    + "and will be removed in a future release.";
+    private static final String WARNING2 =
+            "Use apps/org.onosproject.routing/routers instead";
+
+    private static final Logger log = LoggerFactory.getLogger(RoutingConfiguration.class);
+
+    private static ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory =
+            new ConfigFactory<ApplicationId, BgpConfig>(
+                    SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") {
+                @Override
+                public BgpConfig createConfig() {
+                    return new BgpConfig();
+                }
+            };
+
+    private static ConfigFactory<ApplicationId, RouterConfig> routerConfigFactory =
+            new ConfigFactory<ApplicationId, RouterConfig>(
+                    SubjectFactories.APP_SUBJECT_FACTORY, RouterConfig.class, "router") {
+                @Override
+                public RouterConfig createConfig() {
+                    return new RouterConfig();
+                }
+            };
+
+    private static ConfigFactory<ApplicationId, RoutersConfig> routersConfigFactory =
+            new ConfigFactory<ApplicationId, RoutersConfig>(
+                    SubjectFactories.APP_SUBJECT_FACTORY, RoutersConfig.class, "routers", true) {
+                @Override
+                public RoutersConfig createConfig() {
+                    return new RoutersConfig();
+                }
+            };
+
+    private static ImmutableList<ConfigFactory<?, ?>> factories = ImmutableList.<ConfigFactory<?, ?>>builder()
+            .add(bgpConfigFactory)
+            .add(routerConfigFactory)
+            .add(routersConfigFactory)
+            .build();
+
+    private static Integer registrations = 0;
+
+    private RoutingConfiguration() {
+        // make checkstyle happy
+    }
+
+    /**
+     * Registers the routing configuration factories.
+     *
+     * @param registry network config registry service
+     */
+    public static void register(NetworkConfigRegistry registry) {
+        synchronized (registrations) {
+            if (registrations == 0) {
+                factories.forEach(registry::registerConfigFactory);
+            }
+            registrations++;
+        }
+    }
+
+    /**
+     * Unregisters the routing configuration factories.
+     * <p>The factories will only be unregistered from the network config
+     * registry if no other routing applications are using them. Any components
+     * that call NetworkConfigHelper#registerConfigFactories need to also call
+     * this method when they are no longer using the config
+     * </p>
+     *
+     * @param registry network config registry service
+     */
+    public static void unregister(NetworkConfigRegistry registry) {
+        synchronized (registrations) {
+            registrations--;
+            if (registrations == 0) {
+                factories.forEach(registry::unregisterConfigFactory);
+            }
+        }
+    }
+
+    /**
+     * Retrieves the router configurations.
+     *
+     * @param configService network config service
+     * @param routingAppId routing app ID
+     * @return set of router configurations
+     */
+    public static Set<RoutersConfig.Router> getRouterConfigurations(
+            NetworkConfigService configService, ApplicationId routingAppId) {
+
+        RouterConfig config = configService.getConfig(
+                routingAppId, RoutingService.ROUTER_CONFIG_CLASS);
+        RoutersConfig multiConfig = configService.getConfig(routingAppId, RoutersConfig.class);
+
+        if (config != null) {
+            log.warn(WARNING);
+            log.warn(WARNING2);
+
+            return Collections.singleton(
+                    new RoutersConfig.Router(config.getControlPlaneConnectPoint(),
+                            config.getOspfEnabled(),
+                            Sets.newHashSet(config.getInterfaces())));
+        } else if (multiConfig != null) {
+            return multiConfig.getRouters();
+        } else {
+            return Collections.emptySet();
+        }
+    }
+}
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfigurationService.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfigurationService.java
deleted file mode 100644
index 7c7b0e5..0000000
--- a/apps/routing-api/src/main/java/org/onosproject/routing/config/RoutingConfigurationService.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.routing.config;
-
-/**
- * Routing configuration service. Going away very soon.
- *
- * @deprecated in Junco release
- */
-@Deprecated
-public interface RoutingConfigurationService {
-
-    /**
-     * Empty method to pacify checkstyle.
-     */
-    default void nothing() {
-    }
-}
diff --git a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java b/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java
deleted file mode 100644
index c41724f..0000000
--- a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.onosproject.routing.config.impl;
-
-import org.apache.felix.scr.annotations.Activate;
-import org.apache.felix.scr.annotations.Component;
-import org.apache.felix.scr.annotations.Deactivate;
-import org.apache.felix.scr.annotations.Reference;
-import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.apache.felix.scr.annotations.Service;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.core.CoreService;
-import org.onosproject.incubator.net.intf.InterfaceService;
-import org.onosproject.net.config.ConfigFactory;
-import org.onosproject.net.config.NetworkConfigRegistry;
-import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.net.config.basics.SubjectFactories;
-import org.onosproject.routing.config.BgpConfig;
-import org.onosproject.routing.config.RouterConfig;
-import org.onosproject.routing.config.RoutersConfig;
-import org.onosproject.routing.config.RoutingConfigurationService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implementation of RoutingConfigurationService which reads routing
- * configuration from the network configuration service.
- */
-@Component(immediate = true)
-@Service
-public class RoutingConfigurationImpl implements RoutingConfigurationService {
-
-    private final Logger log = LoggerFactory.getLogger(getClass());
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected NetworkConfigRegistry registry;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected NetworkConfigService configService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected CoreService coreService;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected InterfaceService interfaceService;
-
-    private ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory =
-            new ConfigFactory<ApplicationId, BgpConfig>(
-                    SubjectFactories.APP_SUBJECT_FACTORY, BgpConfig.class, "bgp") {
-        @Override
-        public BgpConfig createConfig() {
-            return new BgpConfig();
-        }
-    };
-
-    private ConfigFactory<ApplicationId, RouterConfig> routerConfigFactory =
-            new ConfigFactory<ApplicationId, RouterConfig>(
-                    SubjectFactories.APP_SUBJECT_FACTORY, RouterConfig.class, "router") {
-        @Override
-        public RouterConfig createConfig() {
-            return new RouterConfig();
-        }
-    };
-
-    private ConfigFactory<ApplicationId, RoutersConfig> routersConfigFactory =
-            new ConfigFactory<ApplicationId, RoutersConfig>(
-                    SubjectFactories.APP_SUBJECT_FACTORY, RoutersConfig.class, "routers", true) {
-                @Override
-                public RoutersConfig createConfig() {
-                    return new RoutersConfig();
-                }
-            };
-
-    @Activate
-    public void activate() {
-        registry.registerConfigFactory(bgpConfigFactory);
-        registry.registerConfigFactory(routerConfigFactory);
-        registry.registerConfigFactory(routersConfigFactory);
-        log.info("Routing configuration service started");
-    }
-
-    @Deactivate
-    public void deactivate() {
-        registry.unregisterConfigFactory(bgpConfigFactory);
-        registry.unregisterConfigFactory(routerConfigFactory);
-        registry.unregisterConfigFactory(routersConfigFactory);
-        log.info("Routing configuration service stopped");
-    }
-
-}
diff --git a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/package-info.java b/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/package-info.java
deleted file mode 100644
index b7a9594..0000000
--- a/apps/routing/common/src/main/java/org/onosproject/routing/config/impl/package-info.java
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * Copyright 2017-present Open Networking Laboratory
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * Implementation of routing configuration APIs.
- */
-package org.onosproject.routing.config.impl;
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 8e793e2..6aa2823 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
@@ -44,7 +44,7 @@
 import org.onosproject.net.PortNumber;
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigListener;
-import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.NetworkConfigRegistry;
 import org.onosproject.net.device.DeviceService;
 import org.onosproject.net.flow.DefaultTrafficSelector;
 import org.onosproject.net.flow.DefaultTrafficTreatment;
@@ -57,13 +57,12 @@
 import org.onosproject.net.flowobjective.NextObjective;
 import org.onosproject.net.host.HostService;
 import org.onosproject.net.host.InterfaceIpAddress;
-import org.onosproject.routing.RouterInfo;
 import org.onosproject.routing.InterfaceProvisionRequest;
 import org.onosproject.routing.Router;
+import org.onosproject.routing.RouterInfo;
 import org.onosproject.routing.RoutingService;
-import org.onosproject.routing.config.RouterConfigHelper;
+import org.onosproject.routing.config.RoutingConfiguration;
 import org.onosproject.routing.config.RoutersConfig;
-import org.onosproject.routing.config.RoutingConfigurationService;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 
@@ -113,7 +112,7 @@
     protected FlowObjectiveService flowObjectiveService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected NetworkConfigService networkConfigService;
+    protected NetworkConfigRegistry networkConfigService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected MastershipService mastershipService;
@@ -125,9 +124,6 @@
     protected ApplicationService applicationService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected RoutingConfigurationService rs;
-
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected ComponentConfigService cfgService;
 
     @Property(name = "forceUnprovision", boolValue = false,
@@ -151,6 +147,8 @@
         cfgService.registerProperties(getClass());
         modified(context);
 
+        RoutingConfiguration.register(networkConfigService);
+
         networkConfigService.addListener(networkConfigListener);
 
         processRouterConfig();
@@ -163,6 +161,7 @@
     protected void deactivate() {
         cfgService.unregisterProperties(getClass(), false);
         networkConfigService.removeListener(networkConfigListener);
+        RoutingConfiguration.unregister(networkConfigService);
     }
 
     @Modified
@@ -196,7 +195,7 @@
                 coreService.registerApplication(RoutingService.ROUTER_APP_ID);
 
         Set<RoutersConfig.Router> routerConfigs =
-                RouterConfigHelper.getRouterConfigurations(networkConfigService, routingAppId);
+                RoutingConfiguration.getRouterConfigurations(networkConfigService, routingAppId);
 
         for (RoutersConfig.Router router : routerConfigs) {
             DeviceId deviceId = router.controlPlaneConnectPoint().deviceId();
diff --git a/apps/routing/cpr/src/test/java/org/onosproject/routing/cpr/ControlPlaneRedirectManagerTest.java b/apps/routing/cpr/src/test/java/org/onosproject/routing/cpr/ControlPlaneRedirectManagerTest.java
index 40c27d3..21db3e5 100644
--- a/apps/routing/cpr/src/test/java/org/onosproject/routing/cpr/ControlPlaneRedirectManagerTest.java
+++ b/apps/routing/cpr/src/test/java/org/onosproject/routing/cpr/ControlPlaneRedirectManagerTest.java
@@ -48,8 +48,8 @@
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigEvent.Type;
 import org.onosproject.net.config.NetworkConfigListener;
-import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.net.config.NetworkConfigServiceAdapter;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigRegistryAdapter;
 import org.onosproject.net.device.DeviceEvent;
 import org.onosproject.net.device.DeviceListener;
 import org.onosproject.net.device.DeviceService;
@@ -98,7 +98,7 @@
 
     private DeviceService deviceService;
     private FlowObjectiveService flowObjectiveService;
-    private NetworkConfigService networkConfigService;
+    private NetworkConfigRegistry networkConfigService;
     private final Set<Interface> interfaces = Sets.newHashSet();
     static Device dev3 = NetTestTools.device("0000000000000001");
     private static final int OSPF_IP_PROTO = 0x59;
@@ -588,7 +588,7 @@
 
     }
 
-    private class TestNetworkConfigService extends NetworkConfigServiceAdapter {
+    private class TestNetworkConfigService extends NetworkConfigRegistryAdapter {
 
         @Override
         public void addListener(NetworkConfigListener listener) {
diff --git a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
index 18e28c3..fe8403f 100644
--- a/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
+++ b/apps/routing/fibinstaller/src/main/java/org/onosproject/routing/fibinstaller/FibInstaller.java
@@ -72,9 +72,8 @@
 import org.onosproject.routing.Router;
 import org.onosproject.routing.RouterInfo;
 import org.onosproject.routing.RoutingService;
-import org.onosproject.routing.config.RouterConfigHelper;
+import org.onosproject.routing.config.RoutingConfiguration;
 import org.onosproject.routing.config.RoutersConfig;
-import org.onosproject.routing.config.RoutingConfigurationService;
 import org.osgi.service.component.ComponentContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -126,9 +125,6 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected ApplicationService applicationService;
 
-    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
-    protected RoutingConfigurationService rs;
-
     @Property(name = "routeToNextHop", boolValue = false,
             label = "Install a /32 or /128 route to each next hop")
     private boolean routeToNextHop = false;
@@ -168,6 +164,8 @@
         componentConfigService.registerProperties(getClass());
         modified(context);
 
+        RoutingConfiguration.register(networkConfigRegistry);
+
         coreAppId = coreService.registerApplication(CoreService.CORE_APP_NAME);
         routerAppId = coreService.registerApplication(RoutingService.ROUTER_APP_ID);
         fibAppId = coreService.registerApplication(APP_NAME);
@@ -187,6 +185,8 @@
     protected void deactivate() {
         networkConfigService.removeListener(configListener);
 
+        RoutingConfiguration.unregister(networkConfigRegistry);
+
         componentConfigService.unregisterProperties(getClass(), false);
 
         log.info("Stopped");
@@ -207,7 +207,7 @@
 
     private void processRouterConfig() {
         Set<RoutersConfig.Router> routerConfigs =
-                RouterConfigHelper.getRouterConfigurations(networkConfigService, routerAppId);
+                RoutingConfiguration.getRouterConfigurations(networkConfigService, routerAppId);
         if (routerConfigs.isEmpty()) {
             log.info("Router config not available");
             return;