[ONOS-4213] Creates a OpenstackNetworking Config for common use

Change-Id: I241db20fc32788a405b260372eedc3dce2de73fd
diff --git a/apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackNetworkingConfig.java b/apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackInterfaceConfig.java
similarity index 90%
rename from apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackNetworkingConfig.java
rename to apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackInterfaceConfig.java
index 7fa3ca7..1dc4749 100644
--- a/apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackNetworkingConfig.java
+++ b/apps/openstackinterface/api/src/main/java/org/onosproject/openstackinterface/OpenstackInterfaceConfig.java
@@ -20,12 +20,12 @@
 import org.onosproject.net.config.basics.BasicElementConfig;
 
 /**
- * Handles configuration for OpenstackSwitching app.
+ * Handles configuration for OpenstackInterface app.
  */
-public class OpenstackNetworkingConfig extends Config<ApplicationId> {
-    public static final String NEUTRON_SERVER = "neutron_server";
-    public static final String KEYSTONE_SERVER = "keystone_server";
-    public static final String USER_NAME = "user_name";
+public class OpenstackInterfaceConfig extends Config<ApplicationId> {
+    public static final String NEUTRON_SERVER = "neutronServer";
+    public static final String KEYSTONE_SERVER = "keystoneServer";
+    public static final String USER_NAME = "userName";
     public static final String PASSWORD = "password";
     public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
 
diff --git a/apps/openstackinterface/app/src/main/java/org/onosproject/openstackinterface/impl/OpenstackInterfaceManager.java b/apps/openstackinterface/app/src/main/java/org/onosproject/openstackinterface/impl/OpenstackInterfaceManager.java
index 0f5e009..722305c 100644
--- a/apps/openstackinterface/app/src/main/java/org/onosproject/openstackinterface/impl/OpenstackInterfaceManager.java
+++ b/apps/openstackinterface/app/src/main/java/org/onosproject/openstackinterface/impl/OpenstackInterfaceManager.java
@@ -35,7 +35,7 @@
 import org.onosproject.net.config.NetworkConfigRegistry;
 import org.onosproject.openstackinterface.OpenstackInterfaceService;
 import org.onosproject.openstackinterface.OpenstackNetwork;
-import org.onosproject.openstackinterface.OpenstackNetworkingConfig;
+import org.onosproject.openstackinterface.OpenstackInterfaceConfig;
 import org.onosproject.openstackinterface.OpenstackPort;
 import org.onosproject.openstackinterface.OpenstackRouter;
 import org.onosproject.openstackinterface.OpenstackSecurityGroup;
@@ -121,12 +121,12 @@
             Executors.newSingleThreadExecutor(groupedThreads("onos/openstackinterface", "config-event"));
 
     private final Set<ConfigFactory> factories = ImmutableSet.of(
-            new ConfigFactory<ApplicationId, OpenstackNetworkingConfig>(APP_SUBJECT_FACTORY,
-                    OpenstackNetworkingConfig.class,
+            new ConfigFactory<ApplicationId, OpenstackInterfaceConfig>(APP_SUBJECT_FACTORY,
+                    OpenstackInterfaceConfig.class,
                     "openstackinterface") {
                 @Override
-                public OpenstackNetworkingConfig createConfig() {
-                    return new OpenstackNetworkingConfig();
+                public OpenstackInterfaceConfig createConfig() {
+                    return new OpenstackInterfaceConfig();
                 }
             }
     );
@@ -417,8 +417,8 @@
     private class InternalConfigListener implements NetworkConfigListener {
 
         public void configureNetwork() {
-            OpenstackNetworkingConfig cfg =
-                    cfgService.getConfig(appId, OpenstackNetworkingConfig.class);
+            OpenstackInterfaceConfig cfg =
+                    cfgService.getConfig(appId, OpenstackInterfaceConfig.class);
             if (cfg == null) {
                 log.error("There is no openstack server information in config.");
                 return;
@@ -434,7 +434,7 @@
         public void event(NetworkConfigEvent event) {
             if (((event.type() == NetworkConfigEvent.Type.CONFIG_ADDED ||
                     event.type() == NetworkConfigEvent.Type.CONFIG_UPDATED)) &&
-                    event.configClass().equals(OpenstackNetworkingConfig.class)) {
+                    event.configClass().equals(OpenstackInterfaceConfig.class)) {
 
                 log.info("Network configuration changed");
                 networkEventExcutorService.execute(this::configureNetwork);
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingConfig.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackNetworkingConfig.java
similarity index 92%
rename from apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingConfig.java
rename to apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackNetworkingConfig.java
index 7c9f126..d539c58 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingConfig.java
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackNetworkingConfig.java
@@ -13,12 +13,11 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.openstacknetworking.routing;
+package org.onosproject.openstacknetworking;
 
 import com.fasterxml.jackson.databind.JsonNode;
 import com.google.common.collect.Maps;
 import org.onlab.packet.Ip4Address;
-import org.onosproject.core.ApplicationId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.config.Config;
 import org.slf4j.Logger;
@@ -28,46 +27,24 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 /**
- * Configuration object for OpenstackRouting service.
+ * Network Config for OpenstackNetworking application.
+ *
  */
-public class OpenstackRoutingConfig extends Config<ApplicationId> {
+public class OpenstackNetworkingConfig extends Config<String> {
+
     protected final Logger log = getLogger(getClass());
 
     public static final String PHYSICAL_ROUTER_MAC = "physicalRouterMac";
     public static final String GATEWAY_BRIDGE_ID = "gatewayBridgeId";
     public static final String GATEWAY_EXTERNAL_INTERFACE_NAME = "gatewayExternalInterfaceName";
     public static final String GATEWAY_EXTERNAL_INTERFACE_MAC = "gatewayExternalInterfaceMac";
+
     public static final String NODES = "nodes";
     public static final String DATAPLANE_IP = "dataPlaneIp";
     public static final String BRIDGE_ID = "bridgeId";
 
 
     /**
-     * Returns the data plane IP map of nodes read from network config.
-     *
-     * @return data plane IP map
-     */
-    public Map<DeviceId, Ip4Address> nodes() {
-        Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
-
-        JsonNode jsonNodes = object.get(NODES);
-        if (jsonNodes == null) {
-            log.error("There's no node information");
-            return null;
-        }
-
-        jsonNodes.forEach(jsonNode -> {
-            try {
-                nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
-                        Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
-            } catch (IllegalArgumentException | NullPointerException e) {
-                log.error("Failed to read {}", e.toString());
-            }
-        });
-        return nodeMap;
-    }
-
-    /**
      * Returns physical router mac.
      *
      * @return physical router mac
@@ -102,4 +79,30 @@
     public String gatewayExternalInterfaceMac() {
         return this.get(GATEWAY_EXTERNAL_INTERFACE_MAC, "");
     }
+
+    /**
+     * Returns the data plane IP map of nodes read from network config.
+     *
+     * @return data plane IP map
+     */
+    public Map<DeviceId, Ip4Address> nodes() {
+        Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
+
+        JsonNode jsonNodes = object.get(NODES);
+        if (jsonNodes == null) {
+            log.error("There's no node information");
+            return null;
+        }
+
+        jsonNodes.forEach(jsonNode -> {
+            try {
+                nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
+                        Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
+            } catch (IllegalArgumentException | NullPointerException e) {
+                log.error("Failed to read {}", e.toString());
+            }
+        });
+        return nodeMap;
+    }
+
 }
diff --git a/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackSubjectFactories.java b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackSubjectFactories.java
new file mode 100644
index 0000000..ce72674
--- /dev/null
+++ b/apps/openstacknetworking/api/src/main/java/org/onosproject/openstacknetworking/OpenstackSubjectFactories.java
@@ -0,0 +1,37 @@
+/*
+ * 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.openstacknetworking;
+
+import org.onosproject.net.config.SubjectFactory;
+
+/**
+ * SubjectFactory class for OpenstackNetworking configuration.
+ *
+ */
+public final class OpenstackSubjectFactories {
+
+    private OpenstackSubjectFactories() {
+
+    }
+
+    public static final SubjectFactory<String> USER_DEFINED_SUBJECT_FACTORY =
+            new SubjectFactory<String>(String.class, "userDefined") {
+                @Override
+                public String createSubject(String key) {
+                    return key;
+                }
+            };
+}
diff --git a/apps/openstacknetworking/network-cfg.json b/apps/openstacknetworking/network-cfg.json
index bff83ea..6026478 100644
--- a/apps/openstacknetworking/network-cfg.json
+++ b/apps/openstacknetworking/network-cfg.json
@@ -1,94 +1,48 @@
 {
-  "apps" : {
-    "org.onosproject.openstackrouting" : {
-      "openstackrouting" : {
-        "physicalRouterMac" : "36:e3:f7:7b:cc:52",
+  "userDefined" : {
+    "openstacknetworking" : {
+      "config" : {
+        "physicalRouterMac" : "86:1e:e1:b1:85:bd",
         "gatewayBridgeId" : "of:0000000000000003",
         "gatewayExternalInterfaceName" : "veth0",
-        "gatewayExternalInterfaceMac" : "96:87:bc:64:99:ad",
+        "gatewayExternalInterfaceMac" : "d2:b3:eb:36:bd:ae",
         "nodes" : [
           {
-            "dataPlaneIp" : "192.168.57.103",
+            "dataPlaneIp" : "10.40.101.208",
             "bridgeId" : "of:0000000000000001"
           },
           {
-            "dataPlaneIp" : "192.168.57.104",
+            "dataPlaneIp" : "10.40.101.227",
             "bridgeId" : "of:0000000000000002"
           },
           {
-            "dataPlaneIp" : "192.168.57.105",
+            "dataPlaneIp" : "10.40.101.240",
             "bridgeId" : "of:0000000000000003"
           }
         ]
       }
-    },
-    "org.onosproject.openstackswitching" : {
-      "openstackswitching" : {
-        "nodes" : [
-          {
-            "dataPlaneIp" : "192.168.57.103",
-            "bridgeId" : "of:0000000000000001"
-          },
-          {
-            "dataPlaneIp" : "192.168.57.104",
-            "bridgeId" : "of:0000000000000002"
-          },
-          {
-            "dataPlaneIp" : "192.168.57.105",
-            "bridgeId" : "of:0000000000000003"
-          }
-        ]
-      }
-    },
-    "org.onosproject.openstacknode" : {
-      "openstacknode" : {
-        "nodes" : [
-          {
-            "hostname" : "compute-01",
-            "ovsdbIp" : "192.168.56.121",
-            "ovsdbPort" : "6640",
-            "bridgeId" : "of:0000000000000001",
-            "openstackNodeType" : "COMPUTENODE"
-          },
-          {
-            "hostname" : "compute-02",
-            "ovsdbIp" : "192.168.56.122",
-            "ovsdbPort" : "6640",
-            "bridgeId" : "of:0000000000000002",
-            "openstackNodeType" : "COMPUTENODE"
-          },
-          {
-            "hostname" : "network",
-            "ovsdbIp" : "192.168.56.114",
-            "ovsdbPort" : "6640",
-            "bridgeId" : "of:0000000000000003",
-            "openstackNodeType" : "GATEWAYNODE",
-            "gatewayExternalInterfaceName" : "veth0",
-            "gatewayExternalInterfaceMac" : "96:87:bc:64:99:ad"
-          }
-        ]
-      }
-    },
-    "org.onosproject.openstackinterface" : {
-      "openstackinterface" : {
-        "neutron_server" : "http://192.168.56.118:9696/v2.0/",
-        "keystone_server" : "http://192.168.56.118:5000/v2.0/",
-        "user_name" : "admin",
-        "password" : "rocks"
-      }
     }
   },
-  "devices" : {
-    "of:0000000000000001" : {
-      "basic" : {
-        "driver" : "sona"
-      }
+    "apps" : {
+        "org.onosproject.openstackinterface" : {
+            "openstackinterface" : {
+                 "neutronServer" : "http://10.40.101.209:9696/v2.0/",
+                 "keystoneServer" : "http://10.40.101.209:5000/v2.0/",
+		 "userName" : "admin",
+                 "password" : "nova"
+             }
+        }
     },
-    "of:0000000000000002" : {
-      "basic" : {
-        "driver" : "sona"
-      }
+    "devices" : {
+        "of:0000000000000001" : {
+            "basic" : {
+                "driver" : "sona"
+            }
+        },
+        "of:0000000000000002" : {
+            "basic" : {
+                "driver" : "sona"
+            }
+        }
     }
-  }
 }
-
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
index c971b99..4c5dc38 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
+++ b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackIcmpHandler.java
@@ -37,6 +37,7 @@
 import org.onosproject.net.packet.PacketService;
 import org.onosproject.openstackinterface.OpenstackInterfaceService;
 import org.onosproject.openstackinterface.OpenstackPort;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.onosproject.openstacknetworking.OpenstackPortInfo;
 import org.onosproject.openstacknetworking.OpenstackSwitchingService;
 import org.slf4j.Logger;
@@ -61,7 +62,7 @@
     private final Map<String, OpenstackPortInfo> icmpInfoMap = Maps.newHashMap();
     private final OpenstackSwitchingService openstackSwitchingService;
     private final OpenstackInterfaceService openstackService;
-    private final OpenstackRoutingConfig config;
+    private final OpenstackNetworkingConfig config;
     private static final MacAddress GATEWAY_MAC = MacAddress.valueOf("1f:1f:1f:1f:1f:1f");
     private static final String NETWORK_ROUTER_INTERFACE = "network:router_interface";
     private static final String PORTNAME = "portName";
@@ -76,7 +77,7 @@
      * @param openstackSwitchingService openstackSwitching service
      */
     OpenstackIcmpHandler(PacketService packetService, DeviceService deviceService,
-                         OpenstackInterfaceService openstackService, OpenstackRoutingConfig config,
+                         OpenstackInterfaceService openstackService, OpenstackNetworkingConfig config,
                          OpenstackSwitchingService openstackSwitchingService) {
         this.packetService = packetService;
         this.deviceService = deviceService;
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java
index 25ee9a5..f144e88 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java
+++ b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackPnatHandler.java
@@ -33,6 +33,7 @@
 import org.onosproject.openstackinterface.OpenstackNetwork;
 import org.onosproject.openstackinterface.OpenstackPort;
 import org.onosproject.openstackinterface.OpenstackRouter;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,12 +57,12 @@
     private final int portNum;
     private final OpenstackPort openstackPort;
     private final Port port;
-    private OpenstackRoutingConfig config;
+    private OpenstackNetworkingConfig config;
 
     private static final String DEVICE_OWNER_ROUTER_INTERFACE = "network:router_interface";
 
     OpenstackPnatHandler(OpenstackRoutingRulePopulator rulePopulator, PacketContext context,
-                         int portNum, OpenstackPort openstackPort, Port port, OpenstackRoutingConfig config) {
+                         int portNum, OpenstackPort openstackPort, Port port, OpenstackNetworkingConfig config) {
         this.rulePopulator = checkNotNull(rulePopulator);
         this.context = checkNotNull(context);
         this.portNum = checkNotNull(portNum);
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingArpHandler.java b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingArpHandler.java
index ff0a4ef..7dee2c1 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingArpHandler.java
+++ b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingArpHandler.java
@@ -33,6 +33,7 @@
 import org.onosproject.net.packet.PacketService;
 import org.onosproject.openstackinterface.OpenstackInterfaceService;
 import org.onosproject.openstackinterface.OpenstackPort;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.slf4j.Logger;
 
 import java.nio.ByteBuffer;
@@ -49,7 +50,7 @@
 
     private final PacketService packetService;
     private final OpenstackInterfaceService openstackService;
-    private final OpenstackRoutingConfig config;
+    private final OpenstackNetworkingConfig config;
     private static final String NETWORK_ROUTER_GATEWAY = "network:router_gateway";
 
     /**
@@ -60,7 +61,7 @@
      * @param config openstackRoutingConfig
      */
     OpenstackRoutingArpHandler(PacketService packetService, OpenstackInterfaceService openstackService,
-                               OpenstackRoutingConfig config) {
+                               OpenstackNetworkingConfig config) {
         this.packetService = packetService;
         this.openstackService = checkNotNull(openstackService);
         this.config = checkNotNull(config);
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java
index 891b622..62e8cdf 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java
+++ b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingManager.java
@@ -37,7 +37,6 @@
 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.net.device.DeviceService;
 import org.onosproject.net.driver.DriverService;
 import org.onosproject.net.flowobjective.FlowObjectiveService;
@@ -50,8 +49,10 @@
 import org.onosproject.openstackinterface.OpenstackPort;
 import org.onosproject.openstackinterface.OpenstackRouter;
 import org.onosproject.openstackinterface.OpenstackRouterInterface;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.onosproject.openstacknetworking.OpenstackPortInfo;
 import org.onosproject.openstacknetworking.OpenstackRoutingService;
+import org.onosproject.openstacknetworking.OpenstackSubjectFactories;
 import org.onosproject.openstacknetworking.OpenstackSwitchingService;
 import org.onosproject.store.serializers.KryoNamespaces;
 import org.onosproject.store.service.ConsistentMap;
@@ -124,16 +125,19 @@
     private static final int PNAT_PORT_EXPIRE_TIME = 1200 * 1000;
     private static final int TP_PORT_MINIMUM_NUM = 1024;
     private static final int TP_PORT_MAXIMUM_NUM = 65535;
+
     private final ConfigFactory configFactory =
-            new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY, OpenstackRoutingConfig.class, "openstackrouting") {
+            new ConfigFactory(OpenstackSubjectFactories.USER_DEFINED_SUBJECT_FACTORY, OpenstackNetworkingConfig.class,
+                    "config") {
                 @Override
-                public OpenstackRoutingConfig createConfig() {
-                    return new OpenstackRoutingConfig();
+                public OpenstackNetworkingConfig createConfig() {
+                    return new OpenstackNetworkingConfig();
                 }
             };
+
     private final NetworkConfigListener configListener = new InternalConfigListener();
 
-    private OpenstackRoutingConfig config;
+    private OpenstackNetworkingConfig config;
     private static final KryoNamespace.Builder FLOATING_IP_SERIALIZER = KryoNamespace.newBuilder()
             .register(KryoNamespaces.API)
             .register(KryoNamespaces.MISC)
@@ -167,8 +171,6 @@
         configRegistry.registerConfigFactory(configFactory);
         configService.addListener(configListener);
 
-        readConfiguration();
-
         floatingIpMap = storageService.<String, OpenstackFloatingIP>consistentMapBuilder()
                 .withSerializer(Serializer.using(FLOATING_IP_SERIALIZER.build()))
                 .withName(FLOATING_IP_MAP_NAME)
@@ -180,6 +182,8 @@
                 .withApplicationId(appId)
                 .build();
 
+        readConfiguration();
+
         log.info("onos-openstackrouting started");
     }
 
@@ -488,7 +492,7 @@
     }
 
     private void readConfiguration() {
-        config = configService.getConfig(appId, OpenstackRoutingConfig.class);
+        config = configService.getConfig("openstacknetworking", OpenstackNetworkingConfig.class);
         if (config == null) {
             log.error("No configuration found");
             return;
@@ -499,7 +503,7 @@
         checkNotNull(config.gatewayExternalInterfaceMac());
         checkNotNull(config.gatewayExternalInterfaceName());
 
-        log.debug("Configured info: {}, {}, {}, {}", config.physicalRouterMac(), config.gatewayBridgeId(),
+        log.warn("Configured info: {}, {}, {}, {}", config.physicalRouterMac(), config.gatewayBridgeId(),
                 config.gatewayExternalInterfaceMac(), config.gatewayExternalInterfaceName());
 
         rulePopulator = new OpenstackRoutingRulePopulator(appId,
@@ -512,6 +516,7 @@
         openstackIcmpHandler.requestPacket(appId);
         openstackArpHandler.requestPacket(appId);
         reloadInitL3Rules();
+
         log.info("OpenstackRouting configured");
     }
 
@@ -519,7 +524,7 @@
 
         @Override
         public void event(NetworkConfigEvent event) {
-            if (!event.configClass().equals(OpenstackRoutingConfig.class)) {
+            if (!event.configClass().equals(OpenstackNetworkingConfig.class)) {
                 return;
             }
 
diff --git a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java
index d8d56e6..5616e0a 100644
--- a/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java
+++ b/apps/openstacknetworking/openstackrouting/src/main/java/org/onosproject/openstacknetworking/routing/OpenstackRoutingRulePopulator.java
@@ -52,6 +52,7 @@
 import org.onosproject.openstackinterface.OpenstackRouterInterface;
 import org.onosproject.openstackinterface.OpenstackSubnet;
 import org.onosproject.openstackinterface.OpenstackFloatingIP;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.onosproject.openstacknetworking.OpenstackPortInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -72,7 +73,7 @@
     private final OpenstackInterfaceService openstackService;
     private final DeviceService deviceService;
     private final DriverService driverService;
-    private final OpenstackRoutingConfig config;
+    private final OpenstackNetworkingConfig config;
 
     private static final String PORTNAME_PREFIX_TUNNEL = "vxlan";
     private static final String PORTNAME = "portName";
@@ -106,7 +107,7 @@
      */
     public OpenstackRoutingRulePopulator(ApplicationId appId, OpenstackInterfaceService openstackService,
                                          FlowObjectiveService flowObjectiveService, DeviceService deviceService,
-                                         DriverService driverService, OpenstackRoutingConfig config) {
+                                         DriverService driverService, OpenstackNetworkingConfig config) {
         this.appId = appId;
         this.flowObjectiveService = flowObjectiveService;
         this.openstackService = checkNotNull(openstackService);
diff --git a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingConfig.java b/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingConfig.java
deleted file mode 100644
index 78443cc..0000000
--- a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingConfig.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.openstacknetworking.switching;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.google.common.collect.Maps;
-import org.onlab.packet.Ip4Address;
-import org.onosproject.core.ApplicationId;
-import org.onosproject.net.DeviceId;
-import org.onosproject.net.config.Config;
-import org.slf4j.Logger;
-
-import java.util.Map;
-
-import static org.slf4j.LoggerFactory.getLogger;
-
-/**
- * Configuration object for OpenstackSwitching service.
- */
-public class OpenstackSwitchingConfig extends Config<ApplicationId> {
-
-    protected final Logger log = getLogger(getClass());
-
-    public static final String NODES = "nodes";
-    public static final String DATAPLANE_IP = "dataPlaneIp";
-    public static final String BRIDGE_ID = "bridgeId";
-
-    /**
-     * Returns the data plane IP map of nodes read from network config.
-     *
-     * @return data plane IP map
-     */
-    public Map<DeviceId, Ip4Address> nodes() {
-        Map<DeviceId, Ip4Address> nodeMap = Maps.newHashMap();
-
-        JsonNode jsonNodes = object.get(NODES);
-        if (jsonNodes == null) {
-            log.error("There's no node information");
-            return null;
-        }
-
-        jsonNodes.forEach(jsonNode -> {
-            try {
-                nodeMap.putIfAbsent(DeviceId.deviceId(jsonNode.path(BRIDGE_ID).asText()),
-                        Ip4Address.valueOf(jsonNode.path(DATAPLANE_IP).asText()));
-            } catch (IllegalArgumentException | NullPointerException e) {
-                log.error("Failed to read {}", e.getMessage());
-            }
-        });
-        return nodeMap;
-    }
-}
diff --git a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java b/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
index 4d6d439..808f2e0 100644
--- a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
+++ b/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingManager.java
@@ -38,7 +38,6 @@
 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.net.device.DeviceEvent;
 import org.onosproject.net.device.DeviceListener;
 import org.onosproject.net.device.DeviceService;
@@ -57,6 +56,8 @@
 import org.onosproject.openstackinterface.OpenstackSecurityGroup;
 import org.onosproject.openstackinterface.OpenstackSubnet;
 import org.onosproject.openstacknetworking.OpenstackPortInfo;
+import org.onosproject.openstacknetworking.OpenstackSubjectFactories;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.onosproject.openstacknetworking.OpenstackSwitchingService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -99,6 +100,9 @@
     protected DriverService driverService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry networkConfig;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
     protected OpenstackInterfaceService openstackService;
 
     @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
@@ -136,16 +140,16 @@
     private Map<String, OpenstackSecurityGroup> securityGroupMap = Maps.newConcurrentMap();
 
     private final ConfigFactory configFactory =
-            new ConfigFactory(SubjectFactories.APP_SUBJECT_FACTORY,
-                    OpenstackSwitchingConfig.class, "openstackswitching") {
+            new ConfigFactory(OpenstackSubjectFactories.USER_DEFINED_SUBJECT_FACTORY, OpenstackNetworkingConfig.class,
+                    "config") {
                 @Override
-                public OpenstackSwitchingConfig createConfig() {
-                    return new OpenstackSwitchingConfig();
+                public OpenstackNetworkingConfig createConfig() {
+                    return new OpenstackNetworkingConfig();
                 }
             };
     private final NetworkConfigListener configListener = new InternalConfigListener();
 
-    private OpenstackSwitchingConfig config;
+    private OpenstackNetworkingConfig config;
 
     @Activate
     protected void activate() {
@@ -158,6 +162,12 @@
         configRegistry.registerConfigFactory(configFactory);
         configService.addListener(configListener);
 
+        arpHandler = new OpenstackArpHandler(openstackService, packetService, hostService);
+        sgRulePopulator = new OpenstackSecurityGroupRulePopulator(appId, openstackService, flowObjectiveService);
+
+        networkConfig.registerConfigFactory(configFactory);
+        networkConfig.addListener(configListener);
+
         readConfiguration();
 
         log.info("Started");
@@ -484,7 +494,7 @@
     }
 
     private void readConfiguration() {
-        config = configService.getConfig(appId, OpenstackSwitchingConfig.class);
+        config = configService.getConfig("openstacknetworking", OpenstackNetworkingConfig.class);
         if (config == null) {
             log.error("No configuration found");
             return;
@@ -500,7 +510,7 @@
 
         @Override
         public void event(NetworkConfigEvent event) {
-            if (!event.configClass().equals(OpenstackSwitchingConfig.class)) {
+            if (!event.configClass().equals(OpenstackNetworkingConfig.class)) {
                 return;
             }
 
@@ -508,7 +518,6 @@
                     event.type().equals(NetworkConfigEvent.Type.CONFIG_UPDATED)) {
                 configEventExecutorService.execute(OpenstackSwitchingManager.this::readConfiguration);
 
-
             }
         }
     }
diff --git a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingRulePopulator.java b/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingRulePopulator.java
index 5c7bd5e..5f072bd 100644
--- a/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingRulePopulator.java
+++ b/apps/openstacknetworking/openstackswitching/src/main/java/org/onosproject/openstacknetworking/switching/OpenstackSwitchingRulePopulator.java
@@ -43,6 +43,7 @@
 import org.onosproject.openstackinterface.OpenstackInterfaceService;
 import org.onosproject.openstackinterface.OpenstackNetwork;
 import org.onosproject.openstackinterface.OpenstackPort;
+import org.onosproject.openstacknetworking.OpenstackNetworkingConfig;
 import org.onosproject.openstacknetworking.OpenstackPortInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -65,7 +66,7 @@
     private DriverService driverService;
     private DeviceService deviceService;
     private ApplicationId appId;
-    private OpenstackSwitchingConfig config;
+    private OpenstackNetworkingConfig config;
 
     private Collection<OpenstackNetwork> openstackNetworkList;
     private Collection<OpenstackPort> openstackPortList;
@@ -85,7 +86,7 @@
                                            DeviceService deviceService,
                                            OpenstackInterfaceService openstackService,
                                            DriverService driverService,
-                                           OpenstackSwitchingConfig config) {
+                                           OpenstackNetworkingConfig config) {
         this.flowObjectiveService = flowObjectiveService;
         this.deviceService = deviceService;
         this.driverService = driverService;