move the reactive routing to new config subsystem

Change-Id: I3e570138afb800c5bd7dbef872cbf9044732fa49
diff --git a/apps/reactive-routing/features.xml b/apps/reactive-routing/features.xml
new file mode 100644
index 0000000..72ffcf5
--- /dev/null
+++ b/apps/reactive-routing/features.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+  ~ Copyright 2015 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.
+  -->
+<features xmlns="http://karaf.apache.org/xmlns/features/v1.2.0" name="${project.artifactId}-${project.version}">
+    <feature name="onos-app-reactive-routing" version="${project.version}"
+             description="${project.description}">
+        <feature>onos-api</feature>
+        <bundle>mvn:${project.groupId}/onos-app-reactive-routing/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-app-routing-api/${project.version}</bundle>
+        <bundle>mvn:${project.groupId}/onos-app-routing/${project.version}</bundle>
+    </feature>
+</features>
diff --git a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/ReactiveRoutingFib.java b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/ReactiveRoutingFib.java
index 8e86056..ac5f148 100644
--- a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/ReactiveRoutingFib.java
+++ b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/ReactiveRoutingFib.java
@@ -16,8 +16,17 @@
 
 package org.onosproject.reactive.routing;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Maps;
+
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+
 import org.onlab.packet.Ethernet;
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
@@ -39,17 +48,9 @@
 import org.onosproject.net.intent.constraint.PartialFailureConstraint;
 import org.onosproject.routing.IntentRequestListener;
 import org.onosproject.routing.IntentSynchronizationService;
-import org.onosproject.routing.config.RoutingConfigurationService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
 /**
  * FIB component for reactive routing intents.
  */
@@ -64,7 +65,6 @@
 
     private final ApplicationId appId;
     private final HostService hostService;
-    private final RoutingConfigurationService configService;
     private final InterfaceService interfaceService;
     private final IntentSynchronizationService intentSynchronizer;
 
@@ -75,17 +75,14 @@
      *
      * @param appId application ID to use to generate intents
      * @param hostService host service
-     * @param configService routing configuration service
      * @param interfaceService interface service
      * @param intentSynchronizer intent synchronization service
      */
     public ReactiveRoutingFib(ApplicationId appId, HostService hostService,
-                              RoutingConfigurationService configService,
                               InterfaceService interfaceService,
                               IntentSynchronizationService intentSynchronizer) {
         this.appId = appId;
         this.hostService = hostService;
-        this.configService = configService;
         this.interfaceService = interfaceService;
         this.intentSynchronizer = intentSynchronizer;
 
@@ -95,8 +92,6 @@
     @Override
     public void setUpConnectivityInternetToHost(IpAddress hostIpAddress) {
         checkNotNull(hostIpAddress);
-        Set<ConnectPoint> ingressPoints =
-                configService.getBgpPeerConnectPoints();
 
         TrafficSelector.Builder selector = DefaultTrafficSelector.builder();
 
@@ -130,6 +125,24 @@
         Key key = Key.of(ipPrefix.toString(), appId);
         int priority = ipPrefix.prefixLength() * PRIORITY_MULTIPLIER
                 + PRIORITY_OFFSET;
+
+        Set<ConnectPoint> interfaceConnectPoints =
+                interfaceService.getInterfaces().stream()
+                .map(intf -> intf.connectPoint()).collect(Collectors.toSet());
+
+        if (interfaceConnectPoints.isEmpty()) {
+            log.error("The interface connect points are empty!");
+            return;
+        }
+
+        Set<ConnectPoint> ingressPoints = new HashSet<>();
+
+        for (ConnectPoint connectPoint : interfaceConnectPoints) {
+            if (!connectPoint.equals(egressPoint)) {
+                ingressPoints.add(connectPoint);
+            }
+        }
+
         MultiPointToSinglePointIntent intent =
                 MultiPointToSinglePointIntent.builder()
                         .appId(appId)
@@ -150,7 +163,8 @@
     public void setUpConnectivityHostToInternet(IpAddress hostIp, IpPrefix prefix,
                                                 IpAddress nextHopIpAddress) {
         // Find the attachment point (egress interface) of the next hop
-        Interface egressInterface = interfaceService.getMatchingInterface(nextHopIpAddress);
+        Interface egressInterface =
+                interfaceService.getMatchingInterface(nextHopIpAddress);
         if (egressInterface == null) {
             log.warn("No outgoing interface found for {}",
                     nextHopIpAddress);
diff --git a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
index ffbdf10..a18e263 100644
--- a/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
+++ b/apps/reactive-routing/src/main/java/org/onosproject/reactive/routing/SdnIpReactiveRouting.java
@@ -15,6 +15,16 @@
  */
 package org.onosproject.reactive.routing;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.onlab.packet.Ethernet.TYPE_ARP;
+import static org.onlab.packet.Ethernet.TYPE_IPV4;
+import static org.onosproject.net.packet.PacketPriority.REACTIVE;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import java.nio.ByteBuffer;
+import java.util.Optional;
+import java.util.Set;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -53,16 +63,6 @@
 import org.onosproject.routing.config.RoutingConfigurationService;
 import org.slf4j.Logger;
 
-import java.nio.ByteBuffer;
-import java.util.Optional;
-import java.util.Set;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.onlab.packet.Ethernet.TYPE_ARP;
-import static org.onlab.packet.Ethernet.TYPE_IPV4;
-import static org.onosproject.net.packet.PacketPriority.REACTIVE;
-import static org.slf4j.LoggerFactory.getLogger;
-
 /**
  * This is reactive routing to handle 3 cases:
  * (1) one host wants to talk to another host, both two hosts are in
@@ -107,9 +107,8 @@
     @Activate
     public void activate() {
         appId = coreService.registerApplication(APP_NAME);
-
         intentRequestListener = new ReactiveRoutingFib(appId, hostService,
-                config, interfaceService, intentSynchronizer);
+                interfaceService, intentSynchronizer);
 
         packetService.addProcessor(processor, PacketProcessor.director(2));
         requestIntercepts();
@@ -300,23 +299,26 @@
      * @return the traffic type which this packet belongs to
      */
     private TrafficType trafficTypeClassifier(ConnectPoint srcConnectPoint,
-                                                             IpAddress dstIp) {
+                                              IpAddress dstIp) {
         LocationType dstIpLocationType = getLocationType(dstIp);
         Optional<Interface> srcInterface =
                 interfaceService.getInterfacesByPort(srcConnectPoint).stream().findFirst();
-        Set<ConnectPoint> ingressPoints = config.getBgpPeerConnectPoints();
+
+        Set<ConnectPoint> bgpPeerConnectPoints = config.getBgpPeerConnectPoints();
+
+
 
         switch (dstIpLocationType) {
         case INTERNET:
             if (srcInterface.isPresent() &&
-                    (!ingressPoints.contains(srcConnectPoint))) {
+                    (!bgpPeerConnectPoints.contains(srcConnectPoint))) {
                 return TrafficType.HOST_TO_INTERNET;
             } else {
                 return TrafficType.INTERNET_TO_INTERNET;
             }
         case LOCAL:
             if (srcInterface.isPresent() &&
-                    (!ingressPoints.contains(srcConnectPoint))) {
+                    (!bgpPeerConnectPoints.contains(srcConnectPoint))) {
                 return TrafficType.HOST_TO_HOST;
             } else {
                 // TODO Currently we only consider local public prefixes.
@@ -394,6 +396,5 @@
         packetService.emit(packet);
         log.trace("sending packet: {}", packet);
     }
-
 }
 
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/LocalIpPrefixEntry.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/LocalIpPrefixEntry.java
index d9d1824..00c598f 100644
--- a/apps/routing-api/src/main/java/org/onosproject/routing/config/LocalIpPrefixEntry.java
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/LocalIpPrefixEntry.java
@@ -15,7 +15,6 @@
  */
 package org.onosproject.routing.config;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
 import com.google.common.base.MoreObjects;
 
 import java.util.Objects;
@@ -53,15 +52,14 @@
     /**
      * Creates a new IP prefix entry.
      *
-     * @param ipPrefix         an IP prefix as a String
+     * @param ipPrefix         an IP prefix
      * @param type             an IP prefix type as an IpPrefixType
      * @param gatewayIpAddress IP of the gateway
      */
-    public LocalIpPrefixEntry(@JsonProperty("ipPrefix") String ipPrefix,
-                              @JsonProperty("type") IpPrefixType type,
-                              @JsonProperty("gatewayIp") IpAddress
-                                      gatewayIpAddress) {
-        this.ipPrefix = IpPrefix.valueOf(ipPrefix);
+    public LocalIpPrefixEntry(IpPrefix ipPrefix,
+                              IpPrefixType type,
+                              IpAddress gatewayIpAddress) {
+        this.ipPrefix = ipPrefix;
         this.type = type;
         this.gatewayIpAddress = gatewayIpAddress;
     }
diff --git a/apps/routing-api/src/main/java/org/onosproject/routing/config/ReactiveRoutingConfig.java b/apps/routing-api/src/main/java/org/onosproject/routing/config/ReactiveRoutingConfig.java
new file mode 100644
index 0000000..caf723d
--- /dev/null
+++ b/apps/routing-api/src/main/java/org/onosproject/routing/config/ReactiveRoutingConfig.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright 2016 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.fasterxml.jackson.databind.JsonNode;
+import com.google.common.collect.Sets;
+
+import java.util.Set;
+
+import org.onlab.packet.IpAddress;
+import org.onlab.packet.IpPrefix;
+import org.onlab.packet.MacAddress;
+import org.onosproject.core.ApplicationId;
+import org.onosproject.net.config.Config;
+import org.onosproject.routing.config.LocalIpPrefixEntry.IpPrefixType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Configuration object for prefix config.
+ */
+public class ReactiveRoutingConfig extends Config<ApplicationId> {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    public static final String IP4LOCALPREFIXES = "ip4LocalPrefixes";
+    public static final String IP6LOCALPREFIXES = "ip6LocalPrefixes";
+    public static final String IPPREFIX = "ipPrefix";
+    public static final String TYPE = "type";
+    public static final String GATEWAYIP = "gatewayIp";
+    public static final String VIRTUALGATEWAYMACADDRESS =
+                               "virtualGatewayMacAddress";
+
+    /**
+     * Gets the set of configured local IPv4 prefixes.
+     *
+     * @return IPv4 prefixes
+     */
+    public Set<LocalIpPrefixEntry> localIp4PrefixEntries() {
+        Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
+
+        JsonNode prefixesNode = object.get(IP4LOCALPREFIXES);
+        if (prefixesNode == null) {
+            log.warn("ip4LocalPrefixes is null!");
+            return prefixes;
+        }
+
+        prefixesNode.forEach(jsonNode -> {
+
+            prefixes.add(new LocalIpPrefixEntry(
+                    IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
+                    IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
+                    IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
+        });
+
+        return prefixes;
+    }
+
+    /**
+     * Gets the set of configured local IPv6 prefixes.
+     *
+     * @return IPv6 prefixes
+     */
+    public Set<LocalIpPrefixEntry> localIp6PrefixEntries() {
+        Set<LocalIpPrefixEntry> prefixes = Sets.newHashSet();
+
+        JsonNode prefixesNode = object.get(IP6LOCALPREFIXES);
+
+        if (prefixesNode == null) {
+            log.warn("ip6LocalPrefixes is null!");
+            return prefixes;
+        }
+
+        prefixesNode.forEach(jsonNode -> {
+
+            prefixes.add(new LocalIpPrefixEntry(
+                    IpPrefix.valueOf(jsonNode.get(IPPREFIX).asText()),
+                    IpPrefixType.valueOf(jsonNode.get(TYPE).asText()),
+                    IpAddress.valueOf(jsonNode.get(GATEWAYIP).asText())));
+        });
+
+        return prefixes;
+    }
+
+    /**
+     *  Gets of the virtual gateway MAC address.
+     *
+     */
+    public MacAddress virtualGatewayMacAddress() {
+        return MacAddress.valueOf(
+                object.get(VIRTUALGATEWAYMACADDRESS).asText());
+    }
+}
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
index 45316bd..9a298a6 100644
--- 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
@@ -15,38 +15,23 @@
  */
 package org.onosproject.routing.config;
 
+import java.util.Set;
+
 import org.onlab.packet.IpAddress;
 import org.onlab.packet.IpPrefix;
 import org.onlab.packet.MacAddress;
 import org.onosproject.net.ConnectPoint;
 
-import java.util.Map;
-import java.util.Set;
-
 /**
  * Provides information about the routing configuration.
  */
 public interface RoutingConfigurationService {
 
-    /**
-     * Gets the list of BGP speakers inside the SDN network.
-     *
-     * @return the map of BGP speaker names to BGP speaker objects
-     */
-    Map<String, BgpSpeaker> getBgpSpeakers();
+    String REACTIVE_ROUTING_APP_ID = "org.onosproject.reactive.routing";
 
-    /**
-     * Gets the list of configured BGP peers.
-     *
-     * @return the map from peer IP address to BgpPeer object
-     */
-    Map<IpAddress, BgpPeer> getBgpPeers();
+    Class<ReactiveRoutingConfig> CONFIG_CLASS = ReactiveRoutingConfig.class;
 
-    /**
-     * Gets the MAC address configured for virtual gateway in SDN network.
-     *
-     * @return the MAC address of virtual gateway
-     */
+
     MacAddress getVirtualGatewayMacAddress();
 
     /**
@@ -81,15 +66,5 @@
      */
     Set<ConnectPoint> getBgpPeerConnectPoints();
 
-    /**
-     * Retrieves the interface that matches the given IP address. Matching
-     * means that the IP address is in one of the interface's assigned subnets.
-     *
-     * @param ipAddress IP address to match
-     * @return the matching interface
-     * @deprecated in Drake release - use InterfaceService instead
-     */
-    @Deprecated
-    Interface getMatchingInterface(IpAddress ipAddress);
 
 }
diff --git a/apps/routing/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java b/apps/routing/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java
index 0917d75..9a5f096 100644
--- a/apps/routing/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java
+++ b/apps/routing/src/main/java/org/onosproject/routing/config/impl/RoutingConfigurationImpl.java
@@ -15,10 +15,18 @@
  */
 package org.onosproject.routing.config.impl;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
+import static org.onosproject.routing.RouteEntry.createBinaryString;
+
+import com.google.common.collect.ImmutableSet;
 import com.googlecode.concurrenttrees.radix.node.concrete.DefaultByteArrayNodeFactory;
 import com.googlecode.concurrenttrees.radixinverted.ConcurrentInvertedRadixTree;
 import com.googlecode.concurrenttrees.radixinverted.InvertedRadixTree;
+
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -35,33 +43,20 @@
 import org.onosproject.incubator.net.intf.InterfaceService;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
 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.BgpPeer;
-import org.onosproject.routing.config.BgpSpeaker;
-import org.onosproject.routing.config.RouterConfig;
-import org.onosproject.routing.config.Interface;
 import org.onosproject.routing.config.LocalIpPrefixEntry;
+import org.onosproject.routing.config.ReactiveRoutingConfig;
+import org.onosproject.routing.config.RouterConfig;
 import org.onosproject.routing.config.RoutingConfigurationService;
 import org.onosproject.routing.impl.Router;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.stream.Collectors;
-
-import static org.onosproject.routing.RouteEntry.createBinaryString;
-
 /**
  * Implementation of RoutingConfigurationService which reads routing
  * configuration from a file.
@@ -72,10 +67,6 @@
 
     private final Logger log = LoggerFactory.getLogger(getClass());
 
-    private static final String CONFIG_DIR = "../config";
-    private static final String DEFAULT_CONFIG_FILE = "sdnip.json";
-    private String configFileName = DEFAULT_CONFIG_FILE;
-
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected NetworkConfigRegistry registry;
 
@@ -88,8 +79,6 @@
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected InterfaceService interfaceService;
 
-    private Map<String, BgpSpeaker> bgpSpeakers = new ConcurrentHashMap<>();
-    private Map<IpAddress, BgpPeer> bgpPeers = new ConcurrentHashMap<>();
     private Set<IpAddress> gatewayIpAddresses = new HashSet<>();
     private Set<ConnectPoint> bgpPeerConnectPoints = new HashSet<>();
 
@@ -101,6 +90,8 @@
                     new DefaultByteArrayNodeFactory());
 
     private MacAddress virtualGatewayMacAddress;
+    private final InternalNetworkConfigListener configListener =
+            new InternalNetworkConfigListener();
 
     private ConfigFactory<ApplicationId, BgpConfig> bgpConfigFactory =
             new ConfigFactory<ApplicationId, BgpConfig>(
@@ -114,100 +105,80 @@
     private ConfigFactory<ApplicationId, RouterConfig> routerConfigFactory =
             new ConfigFactory<ApplicationId, RouterConfig>(
                     SubjectFactories.APP_SUBJECT_FACTORY, RouterConfig.class, "router") {
-                @Override
-                public RouterConfig createConfig() {
-                    return new RouterConfig();
-                }
-            };
+        @Override
+        public RouterConfig createConfig() {
+            return new RouterConfig();
+        }
+    };
+
+    private ConfigFactory<ApplicationId, ReactiveRoutingConfig>
+            reactiveRoutingConfigFactory =
+            new ConfigFactory<ApplicationId, ReactiveRoutingConfig>(
+                    SubjectFactories.APP_SUBJECT_FACTORY,
+                    ReactiveRoutingConfig.class, "reactiveRouting") {
+        @Override
+        public ReactiveRoutingConfig createConfig() {
+            return new ReactiveRoutingConfig();
+        }
+    };
 
     @Activate
     public void activate() {
+        configService.addListener(configListener);
         registry.registerConfigFactory(bgpConfigFactory);
         registry.registerConfigFactory(routerConfigFactory);
-        readConfiguration();
+        registry.registerConfigFactory(reactiveRoutingConfigFactory);
+        setUpConfiguration();
         log.info("Routing configuration service started");
     }
 
     @Deactivate
     public void deactivate() {
         registry.unregisterConfigFactory(bgpConfigFactory);
-        registry.registerConfigFactory(routerConfigFactory);
+        registry.unregisterConfigFactory(routerConfigFactory);
+        registry.unregisterConfigFactory(reactiveRoutingConfigFactory);
+        configService.removeListener(configListener);
         log.info("Routing configuration service stopped");
     }
 
     /**
-     * Reads SDN-IP related information contained in the configuration file.
-     *
-     * @param configFilename the name of the configuration file for the SDN-IP
-     * application
+     * Set up reactive routing information from configuration.
      */
-    private void readConfiguration(String configFilename) {
-        File configFile = new File(CONFIG_DIR, configFilename);
-        ObjectMapper mapper = new ObjectMapper();
-
-        try {
-            log.info("Loading config: {}", configFile.getAbsolutePath());
-            Configuration config = mapper.readValue(configFile,
-                                                    Configuration.class);
-            for (BgpSpeaker speaker : config.getBgpSpeakers()) {
-                bgpSpeakers.put(speaker.name(), speaker);
-            }
-            for (BgpPeer peer : config.getPeers()) {
-                bgpPeers.put(peer.ipAddress(), peer);
-                bgpPeerConnectPoints.add(peer.connectPoint());
-            }
-
-            for (LocalIpPrefixEntry entry : config.getLocalIp4PrefixEntries()) {
-                localPrefixTable4.put(createBinaryString(entry.ipPrefix()),
-                                      entry);
-                gatewayIpAddresses.add(entry.getGatewayIpAddress());
-            }
-            for (LocalIpPrefixEntry entry : config.getLocalIp6PrefixEntries()) {
-                localPrefixTable6.put(createBinaryString(entry.ipPrefix()),
-                                      entry);
-                gatewayIpAddresses.add(entry.getGatewayIpAddress());
-            }
-
-            virtualGatewayMacAddress = config.getVirtualGatewayMacAddress();
-
-        } catch (FileNotFoundException e) {
-            log.warn("Configuration file not found: {}", configFileName);
-        } catch (IOException e) {
-            log.error("Error loading configuration", e);
+    private void setUpConfiguration() {
+        ReactiveRoutingConfig config = configService.getConfig(
+                coreService.registerApplication(RoutingConfigurationService
+                        .REACTIVE_ROUTING_APP_ID),
+                RoutingConfigurationService.CONFIG_CLASS);
+        if (config == null) {
+            log.warn("No reactive routing config available!");
+            return;
         }
-    }
+        for (LocalIpPrefixEntry entry : config.localIp4PrefixEntries()) {
+            localPrefixTable4.put(createBinaryString(entry.ipPrefix()), entry);
+            gatewayIpAddresses.add(entry.getGatewayIpAddress());
+        }
+        for (LocalIpPrefixEntry entry : config.localIp6PrefixEntries()) {
+            localPrefixTable6.put(createBinaryString(entry.ipPrefix()), entry);
+            gatewayIpAddresses.add(entry.getGatewayIpAddress());
+        }
 
-    /**
-     * Instructs the configuration reader to read the configuration from the
-     * file.
-     */
-    public void readConfiguration() {
-        readConfiguration(configFileName);
-    }
+        virtualGatewayMacAddress = config.virtualGatewayMacAddress();
 
-    @Override
-    public Map<String, BgpSpeaker> getBgpSpeakers() {
-        return Collections.unmodifiableMap(bgpSpeakers);
-    }
-
-    @Override
-    public Map<IpAddress, BgpPeer> getBgpPeers() {
-        return Collections.unmodifiableMap(bgpPeers);
-    }
-
-    @Override
-    public Set<ConnectPoint> getBgpPeerConnectPoints() {
-        // TODO perhaps cache this result in future
+        // Setup BGP peer connect points
         ApplicationId routerAppId = coreService.getAppId(Router.ROUTER_APP_ID);
         if (routerAppId == null) {
-            return Collections.emptySet();
+            log.info("Router application ID is null!");
+            return;
         }
 
         BgpConfig bgpConfig = configService.getConfig(routerAppId, BgpConfig.class);
+
         if (bgpConfig == null) {
-            return Collections.emptySet();
+            log.info("BGP config is null!");
+            return;
         } else {
-            return bgpConfig.bgpSpeakers().stream()
+            bgpPeerConnectPoints =
+                    bgpConfig.bgpSpeakers().stream()
                     .flatMap(speaker -> speaker.peers().stream())
                     .map(peer -> interfaceService.getMatchingInterface(peer))
                     .filter(Objects::nonNull)
@@ -217,11 +188,6 @@
     }
 
     @Override
-    public Interface getMatchingInterface(IpAddress ipAddress) {
-        return null;
-    }
-
-    @Override
     public boolean isIpAddressLocal(IpAddress ipAddress) {
         if (ipAddress.isIp4()) {
             return localPrefixTable4.getValuesForKeysPrefixing(
@@ -254,4 +220,31 @@
         return virtualGatewayMacAddress;
     }
 
+    private class InternalNetworkConfigListener implements NetworkConfigListener {
+
+        @Override
+        public void event(NetworkConfigEvent event) {
+            switch (event.type()) {
+            case CONFIG_REGISTERED:
+                break;
+            case CONFIG_UNREGISTERED:
+                break;
+            case CONFIG_ADDED:
+            case CONFIG_UPDATED:
+            case CONFIG_REMOVED:
+                if (event.configClass() == RoutingConfigurationService.CONFIG_CLASS) {
+                    setUpConfiguration();
+                }
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    @Override
+    public Set<ConnectPoint> getBgpPeerConnectPoints() {
+        return ImmutableSet.copyOf(bgpPeerConnectPoints);
+    }
+
 }