ONOS-2488 Finished moving network config stuff out of the incubator area.

Change-Id: I62c511938fdf8f33def99ce43f0d4417b4ba1918
diff --git a/core/net/pom.xml b/core/net/pom.xml
index dfd5f21..4ba04c5 100644
--- a/core/net/pom.xml
+++ b/core/net/pom.xml
@@ -60,6 +60,13 @@
 
         <dependency>
             <groupId>org.onosproject</groupId>
+            <artifactId>onos-core-dist</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
             <artifactId>onos-incubator-api</artifactId>
             <scope>test</scope>
             <classifier>tests</classifier>
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
new file mode 100644
index 0000000..ec0b124
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/BasicNetworkConfigs.java
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+package org.onosproject.net.config.impl;
+
+import com.google.common.collect.ImmutableSet;
+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.onosproject.core.CoreService;
+import org.onosproject.incubator.net.config.basics.InterfaceConfig;
+import org.onosproject.net.ConnectPoint;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.HostId;
+import org.onosproject.net.LinkKey;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.basics.BasicDeviceConfig;
+import org.onosproject.net.config.basics.BasicHostConfig;
+import org.onosproject.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.config.basics.OpticalPortConfig;
+import org.onosproject.net.config.basics.SubjectFactories;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Set;
+
+import static org.onosproject.net.config.basics.SubjectFactories.*;
+
+/**
+ * Component for registration of builtin basic network configurations.
+ */
+@Component(immediate = true)
+public class BasicNetworkConfigs {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private final Set<ConfigFactory> factories = ImmutableSet.of(
+            new ConfigFactory<DeviceId, BasicDeviceConfig>(DEVICE_SUBJECT_FACTORY,
+                                                           BasicDeviceConfig.class,
+                                                           "basic") {
+                @Override
+                public BasicDeviceConfig createConfig() {
+                    return new BasicDeviceConfig();
+                }
+            },
+            new ConfigFactory<ConnectPoint, InterfaceConfig>(CONNECT_POINT_SUBJECT_FACTORY,
+                                                             InterfaceConfig.class,
+                                                             "interfaces") {
+                @Override
+                public InterfaceConfig createConfig() {
+                    return new InterfaceConfig();
+                }
+            },
+            new ConfigFactory<HostId, BasicHostConfig>(HOST_SUBJECT_FACTORY,
+                                                       BasicHostConfig.class,
+                                                       "basic") {
+                @Override
+                public BasicHostConfig createConfig() {
+                    return new BasicHostConfig();
+                }
+            },
+            new ConfigFactory<LinkKey, BasicLinkConfig>(LINK_SUBJECT_FACTORY,
+                                                        BasicLinkConfig.class,
+                                                        "basic") {
+                @Override
+                public BasicLinkConfig createConfig() {
+                    return new BasicLinkConfig();
+                }
+            },
+            new ConfigFactory<ConnectPoint, OpticalPortConfig>(CONNECT_POINT_SUBJECT_FACTORY,
+                                                               OpticalPortConfig.class,
+                                                               "basic") {
+                @Override
+                public OpticalPortConfig createConfig() {
+                    return new OpticalPortConfig();
+                }
+            }
+    );
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected CoreService coreService;
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigRegistry registry;
+
+    @Activate
+    public void activate() {
+        SubjectFactories.setCoreService(coreService);
+        factories.forEach(registry::registerConfigFactory);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        factories.forEach(registry::unregisterConfigFactory);
+        log.info("Stopped");
+    }
+
+}
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigLoader.java b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigLoader.java
new file mode 100644
index 0000000..e66c81b
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigLoader.java
@@ -0,0 +1,212 @@
+/*
+ * 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.
+ */
+package org.onosproject.net.config.impl;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.Maps;
+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.onosproject.net.config.NetworkConfigEvent;
+import org.onosproject.net.config.NetworkConfigListener;
+import org.onosproject.net.config.NetworkConfigService;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Component for loading the initial network configuration.
+ */
+@Component(immediate = true)
+public class NetworkConfigLoader {
+
+    private static final File CFG_FILE = new File("../config/network-cfg.json");
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigService networkConfigService;
+
+    // FIXME: Add mutual exclusion to make sure this happens only once per startup.
+
+    private Map<InnerConfigPosition, ObjectNode> jsons = Maps.newHashMap();
+
+    private final NetworkConfigListener configListener = new InnerConfigListener();
+
+    ObjectNode root;
+
+    @Activate
+    public void activate() {
+        //TODO Maybe this should be at the bottom to avoid a potential race
+        networkConfigService.addListener(configListener);
+        try {
+            if (CFG_FILE.exists()) {
+                root = (ObjectNode) new ObjectMapper().readTree(CFG_FILE);
+
+                populateConfigurations();
+
+                applyConfigurations();
+
+                log.info("Loaded initial network configuration from {}", CFG_FILE);
+            }
+        } catch (Exception e) {
+            log.warn("Unable to load initial network configuration from {}",
+                    CFG_FILE, e);
+        }
+    }
+
+    @Deactivate
+    public void deactivate() {
+        networkConfigService.removeListener(configListener);
+    }
+    // sweep through pending config jsons and try to add them
+
+    /**
+     * Inner class that allows for handling of newly added NetConfig types.
+     */
+    private final class InnerConfigListener implements NetworkConfigListener {
+
+        @Override
+        public void event(NetworkConfigEvent event) {
+            //TODO should this be done for other types of NetworkConfigEvents?
+            if (event.type() == NetworkConfigEvent.Type.CONFIG_REGISTERED ||
+                    event.type() == NetworkConfigEvent.Type.CONFIG_ADDED) {
+                applyConfigurations();
+            }
+
+        }
+    }
+
+    /**
+     * Inner class that allows for tracking of JSON class configurations.
+     */
+    private final class InnerConfigPosition {
+        private String subjectKey, subject, classKey;
+
+        private String getSubjectKey() {
+            return subjectKey;
+        }
+
+        private String getSubject() {
+            return subject;
+        }
+
+        private String getClassKey() {
+            return classKey;
+        }
+
+        private InnerConfigPosition(String subjectKey, String subject, String classKey) {
+            this.subjectKey = subjectKey;
+            this.subject = subject;
+            this.classKey = classKey;
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof InnerConfigPosition) {
+                final InnerConfigPosition that = (InnerConfigPosition) obj;
+                return Objects.equals(this.subjectKey, that.subjectKey) && Objects.equals(this.subject, that.subject)
+                        && Objects.equals(this.classKey, that.classKey);
+            }
+            return false;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(subjectKey, subject, classKey);
+        }
+    }
+
+    /**
+     * Save the JSON leaves associated with a specific subject key.
+     *
+     * @param sk   the subject key string.
+     * @param node the node associated with the subject key.
+     */
+    private void saveJson(String sk, ObjectNode node) {
+        node.fieldNames().forEachRemaining(s ->
+                saveSubjectJson(sk, s, (ObjectNode) node.path(s)));
+    }
+
+    /**
+     * Save the JSON leaves of the tree rooted as the node 'node' with subject key 'sk'.
+     *
+     * @param sk   the string of the subject key.
+     * @param s    the subject name.
+     * @param node the node rooting this subtree.
+     */
+    private void saveSubjectJson(String sk,
+                                 String s, ObjectNode node) {
+        node.fieldNames().forEachRemaining(c ->
+                this.jsons.put(new InnerConfigPosition(sk, s, c), (ObjectNode) node.path(c)));
+    }
+
+    /**
+     * Iterate through the JSON and populate a list of the leaf nodes of the structure.
+     */
+    private void populateConfigurations() {
+        root.fieldNames().forEachRemaining(sk ->
+                saveJson(sk, (ObjectNode) root.path(sk)));
+
+    }
+
+    /**
+     * Apply the configurations associated with all of the config classes that are imported and have not yet been
+     * applied.
+     */
+    protected void applyConfigurations() {
+        Iterator<Map.Entry<InnerConfigPosition, ObjectNode>> iter = jsons.entrySet().iterator();
+
+        Map.Entry<InnerConfigPosition, ObjectNode> entry;
+        InnerConfigPosition key;
+        ObjectNode node;
+        String subjectKey;
+        String subject;
+        String classKey;
+
+        while (iter.hasNext()) {
+            entry = iter.next();
+            node = entry.getValue();
+            key = entry.getKey();
+            subjectKey = key.getSubjectKey();
+            subject = key.getSubject();
+            classKey = key.getClassKey();
+            //Check that the config class has been imported
+            if (networkConfigService.getConfigClass(subjectKey, subject) != null) {
+
+                //Apply the configuration
+                networkConfigService.applyConfig(networkConfigService.getSubjectFactory(subjectKey).
+                                createSubject(subject),
+                        networkConfigService.getConfigClass(subjectKey, classKey), node);
+
+                //Now that it has been applied the corresponding JSON entry is no longer needed
+                jsons.remove(key);
+            }
+
+        }
+    }
+
+}
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java
new file mode 100644
index 0000000..5c6cc0e
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/NetworkConfigManager.java
@@ -0,0 +1,288 @@
+/*
+ * 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.
+ */
+package org.onosproject.net.config.impl;
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+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.event.AbstractListenerManager;
+import org.onosproject.net.config.Config;
+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.NetworkConfigStore;
+import org.onosproject.net.config.NetworkConfigStoreDelegate;
+import org.onosproject.net.config.SubjectFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Implementation of the network configuration subsystem.
+ */
+@Component(immediate = true)
+@Service
+public class NetworkConfigManager
+        extends AbstractListenerManager<NetworkConfigEvent, NetworkConfigListener>
+        implements NetworkConfigRegistry, NetworkConfigService {
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private static final String NULL_FACTORY_MSG = "Factory cannot be null";
+    private static final String NULL_SCLASS_MSG = "Subject class cannot be null";
+    private static final String NULL_CCLASS_MSG = "Config class cannot be null";
+    private static final String NULL_SUBJECT_MSG = "Subject cannot be null";
+
+    // Inventory of configuration factories
+    private final Map<ConfigKey, ConfigFactory> factories = Maps.newConcurrentMap();
+
+    // Secondary indices to retrieve subject and config classes by keys
+    private final Map<String, SubjectFactory> subjectClasses = Maps.newConcurrentMap();
+    private final Map<Class, SubjectFactory> subjectClassKeys = Maps.newConcurrentMap();
+    private final Map<ConfigIdentifier, Class<? extends Config>> configClasses = Maps.newConcurrentMap();
+
+    private final NetworkConfigStoreDelegate storeDelegate = new InternalStoreDelegate();
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected NetworkConfigStore store;
+
+
+    @Activate
+    public void activate() {
+        eventDispatcher.addSink(NetworkConfigEvent.class, listenerRegistry);
+        store.setDelegate(storeDelegate);
+        log.info("Started");
+    }
+
+    @Deactivate
+    public void deactivate() {
+        eventDispatcher.removeSink(NetworkConfigEvent.class);
+        store.unsetDelegate(storeDelegate);
+        log.info("Stopped");
+    }
+
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public void registerConfigFactory(ConfigFactory configFactory) {
+        checkNotNull(configFactory, NULL_FACTORY_MSG);
+        factories.put(key(configFactory), configFactory);
+        configClasses.put(identifier(configFactory), configFactory.configClass());
+
+        SubjectFactory subjectFactory = configFactory.subjectFactory();
+        subjectClasses.putIfAbsent(subjectFactory.subjectKey(), subjectFactory);
+        subjectClassKeys.putIfAbsent(subjectFactory.subjectClass(), subjectFactory);
+
+        store.addConfigFactory(configFactory);
+    }
+
+    @Override
+    public void unregisterConfigFactory(ConfigFactory configFactory) {
+        checkNotNull(configFactory, NULL_FACTORY_MSG);
+        factories.remove(key(configFactory));
+        configClasses.remove(identifier(configFactory));
+
+        // Note that we are deliberately not removing subject factory key bindings.
+        store.removeConfigFactory(configFactory);
+    }
+
+    @Override
+    public Set<ConfigFactory> getConfigFactories() {
+        return ImmutableSet.copyOf(factories.values());
+    }
+
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public <S, C extends Config<S>> Set<ConfigFactory<S, C>> getConfigFactories(Class<S> subjectClass) {
+        ImmutableSet.Builder<ConfigFactory<S, C>> builder = ImmutableSet.builder();
+        factories.forEach((key, factory) -> {
+            if (factory.subjectFactory().subjectClass().equals(subjectClass)) {
+                builder.add(factory);
+            }
+        });
+        return builder.build();
+    }
+
+    @Override
+    public <S, C extends Config<S>> ConfigFactory<S, C> getConfigFactory(Class<C> configClass) {
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        return store.getConfigFactory(configClass);
+    }
+
+
+    @Override
+    public Set<Class> getSubjectClasses() {
+        ImmutableSet.Builder<Class> builder = ImmutableSet.builder();
+        factories.forEach((k, v) -> builder.add(k.subjectClass));
+        return builder.build();
+    }
+
+    @Override
+    public SubjectFactory getSubjectFactory(String subjectKey) {
+        return subjectClasses.get(subjectKey);
+    }
+
+    @Override
+    public SubjectFactory getSubjectFactory(Class subjectClass) {
+        return subjectClassKeys.get(subjectClass);
+    }
+
+    @Override
+    public Class<? extends Config> getConfigClass(String subjectKey, String configKey) {
+        return configClasses.get(new ConfigIdentifier(subjectKey, configKey));
+    }
+
+    @Override
+    public <S> Set<S> getSubjects(Class<S> subjectClass) {
+        checkNotNull(subjectClass, NULL_SCLASS_MSG);
+        return store.getSubjects(subjectClass);
+    }
+
+    @Override
+    public <S, C extends Config<S>> Set<S> getSubjects(Class<S> subjectClass, Class<C> configClass) {
+        checkNotNull(subjectClass, NULL_SCLASS_MSG);
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        return store.getSubjects(subjectClass, configClass);
+    }
+
+    @Override
+    public <S> Set<Config<S>> getConfigs(S subject) {
+        checkNotNull(subject, NULL_SUBJECT_MSG);
+        Set<Class<? extends Config<S>>> configClasses = store.getConfigClasses(subject);
+        ImmutableSet.Builder<Config<S>> cfg = ImmutableSet.builder();
+        configClasses.forEach(cc -> cfg.add(store.getConfig(subject, cc)));
+        return cfg.build();
+    }
+
+    @Override
+    public <S, T extends Config<S>> T getConfig(S subject, Class<T> configClass) {
+        checkNotNull(subject, NULL_SUBJECT_MSG);
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        return store.getConfig(subject, configClass);
+    }
+
+
+    @Override
+    public <S, C extends Config<S>> C addConfig(S subject, Class<C> configClass) {
+        checkNotNull(subject, NULL_SUBJECT_MSG);
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        return store.createConfig(subject, configClass);
+    }
+
+    @Override
+    public <S, C extends Config<S>> C applyConfig(S subject, Class<C> configClass, ObjectNode json) {
+        checkNotNull(subject, NULL_SUBJECT_MSG);
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        return store.applyConfig(subject, configClass, json);
+    }
+
+    @Override
+    public <S, C extends Config<S>> void removeConfig(S subject, Class<C> configClass) {
+        checkNotNull(subject, NULL_SUBJECT_MSG);
+        checkNotNull(configClass, NULL_CCLASS_MSG);
+        store.clearConfig(subject, configClass);
+    }
+
+    // Auxiliary store delegate to receive notification about changes in
+    // the network configuration store state - by the store itself.
+    private class InternalStoreDelegate implements NetworkConfigStoreDelegate {
+        @Override
+        public void notify(NetworkConfigEvent event) {
+            post(event);
+        }
+    }
+
+
+    // Produces a key for uniquely tracking a config factory.
+    private static ConfigKey key(ConfigFactory factory) {
+        return new ConfigKey(factory.subjectFactory().subjectClass(), factory.configClass());
+    }
+
+    // Auxiliary key to track config factories.
+    protected static final class ConfigKey {
+        final Class subjectClass;
+        final Class configClass;
+
+        protected ConfigKey(Class subjectClass, Class configClass) {
+            this.subjectClass = subjectClass;
+            this.configClass = configClass;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(subjectClass, configClass);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof ConfigKey) {
+                final ConfigKey other = (ConfigKey) obj;
+                return Objects.equals(this.subjectClass, other.subjectClass)
+                        && Objects.equals(this.configClass, other.configClass);
+            }
+            return false;
+        }
+    }
+
+    private static ConfigIdentifier identifier(ConfigFactory factory) {
+        return new ConfigIdentifier(factory.subjectFactory().subjectKey(), factory.configKey());
+    }
+
+    static final class ConfigIdentifier {
+        final String subjectKey;
+        final String configKey;
+
+        protected ConfigIdentifier(String subjectKey, String configKey) {
+            this.subjectKey = subjectKey;
+            this.configKey = configKey;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(subjectKey, configKey);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj instanceof ConfigIdentifier) {
+                final ConfigIdentifier other = (ConfigIdentifier) obj;
+                return Objects.equals(this.subjectKey, other.subjectKey)
+                        && Objects.equals(this.configKey, other.configKey);
+            }
+            return false;
+        }
+    }
+}
diff --git a/core/net/src/main/java/org/onosproject/net/config/impl/package-info.java b/core/net/src/main/java/org/onosproject/net/config/impl/package-info.java
new file mode 100644
index 0000000..38f7694
--- /dev/null
+++ b/core/net/src/main/java/org/onosproject/net/config/impl/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * 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.
+ */
+
+/**
+ * Implementation of the network configuration subsystem.
+ */
+package org.onosproject.net.config.impl;
\ No newline at end of file
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java b/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java
index ae6a3b2..36686d8 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/BasicDeviceOperator.java
@@ -18,7 +18,7 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 import org.onosproject.net.config.ConfigOperator;
-import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
+import org.onosproject.net.config.basics.BasicDeviceConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Device;
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
index 83c4a69..24ea9f9 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/DeviceManager.java
@@ -31,7 +31,7 @@
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigListener;
 import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
+import org.onosproject.net.config.basics.BasicDeviceConfig;
 import org.onosproject.mastership.MastershipEvent;
 import org.onosproject.mastership.MastershipListener;
 import org.onosproject.mastership.MastershipService;
diff --git a/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java b/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
index 7c551eb..ca43f95 100644
--- a/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/device/impl/OpticalPortOperator.java
@@ -18,7 +18,7 @@
 import static org.slf4j.LoggerFactory.getLogger;
 
 import org.onosproject.net.config.ConfigOperator;
-import org.onosproject.incubator.net.config.basics.OpticalPortConfig;
+import org.onosproject.net.config.basics.OpticalPortConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.PortNumber;
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/BasicHostOperator.java b/core/net/src/main/java/org/onosproject/net/host/impl/BasicHostOperator.java
index f0e100c..68aa27f 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/BasicHostOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/BasicHostOperator.java
@@ -19,7 +19,7 @@
 
 import org.slf4j.Logger;
 import org.onosproject.net.config.ConfigOperator;
-import org.onosproject.incubator.net.config.basics.BasicHostConfig;
+import org.onosproject.net.config.basics.BasicHostConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.SparseAnnotations;
diff --git a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
index b94ca68..fe369ae 100644
--- a/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
+++ b/core/net/src/main/java/org/onosproject/net/host/impl/HostManager.java
@@ -29,7 +29,7 @@
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigListener;
 import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.incubator.net.config.basics.BasicHostConfig;
+import org.onosproject.net.config.basics.BasicHostConfig;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Host;
diff --git a/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java b/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
index 6a21fdd..a6b08f6 100644
--- a/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
+++ b/core/net/src/main/java/org/onosproject/net/link/impl/BasicLinkOperator.java
@@ -21,7 +21,7 @@
 
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.config.ConfigOperator;
-import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.config.basics.BasicLinkConfig;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.Link;
 import org.onosproject.net.SparseAnnotations;
diff --git a/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java b/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
index 04e7939..b4cc17c 100644
--- a/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
+++ b/core/net/src/main/java/org/onosproject/net/link/impl/LinkManager.java
@@ -29,7 +29,7 @@
 import org.onosproject.net.config.NetworkConfigEvent;
 import org.onosproject.net.config.NetworkConfigListener;
 import org.onosproject.net.config.NetworkConfigService;
-import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.config.basics.BasicLinkConfig;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.Link;
diff --git a/core/net/src/test/java/org/onosproject/net/config/impl/NetworkConfigManagerTest.java b/core/net/src/test/java/org/onosproject/net/config/impl/NetworkConfigManagerTest.java
new file mode 100644
index 0000000..2d03bfc
--- /dev/null
+++ b/core/net/src/test/java/org/onosproject/net/config/impl/NetworkConfigManagerTest.java
@@ -0,0 +1,242 @@
+/*
+ * 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.
+ */
+package org.onosproject.net.config.impl;
+
+import java.util.Set;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.junit.TestUtils;
+import org.onosproject.event.EventDeliveryServiceAdapter;
+import org.onosproject.net.config.Config;
+import org.onosproject.net.config.ConfigFactory;
+import org.onosproject.net.config.NetworkConfigRegistry;
+import org.onosproject.net.config.NetworkConfigService;
+import org.onosproject.net.config.SubjectFactory;
+import org.onosproject.net.NetTestTools;
+import org.onosproject.store.config.impl.DistributedNetworkConfigStore;
+import org.onosproject.store.service.TestStorageService;
+
+import static org.hamcrest.Matchers.hasSize;
+import static org.hamcrest.Matchers.instanceOf;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+import static org.junit.Assert.assertThat;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.common.testing.EqualsTester;
+
+/**
+ * Unit tests for network config registry.
+ */
+public class NetworkConfigManagerTest {
+    private NetworkConfigManager manager;
+    private NetworkConfigRegistry registry;
+    private NetworkConfigService configService;
+    private DistributedNetworkConfigStore configStore;
+
+    /**
+     * Config classes for testing.
+     */
+    public class BasicConfig1 extends Config<String> { }
+    public class BasicConfig2 extends Config<String> { }
+
+    public class MockSubjectFactory extends SubjectFactory<String> {
+        protected MockSubjectFactory(Class<String> subjectClass, String subjectKey) {
+            super(subjectClass, subjectKey);
+        }
+
+        @Override
+        public String createSubject(String subjectKey) {
+            return subjectKey + "-subject";
+        }
+    }
+
+    /**
+     * Config factory classes for testing.
+     */
+    public class MockConfigFactory1 extends ConfigFactory<String, BasicConfig1> {
+        protected MockConfigFactory1(SubjectFactory<String> subjectFactory,
+                                    Class<BasicConfig1> configClass, String configKey) {
+            super(subjectFactory, configClass, configKey);
+        }
+        @Override
+        public BasicConfig1 createConfig() {
+            return new BasicConfig1();
+        }
+    }
+
+    public class MockConfigFactory2 extends ConfigFactory<String, BasicConfig2> {
+        protected MockConfigFactory2(SubjectFactory<String> subjectFactory,
+                                    Class<BasicConfig2> configClass, String configKey) {
+            super(subjectFactory, configClass, configKey);
+        }
+        @Override
+        public BasicConfig2 createConfig() {
+            return new BasicConfig2();
+        }
+    }
+
+    MockSubjectFactory factory1 = new MockSubjectFactory(String.class,
+            "key1");
+    MockSubjectFactory factory2 = new MockSubjectFactory(String.class,
+            "key2");
+
+    MockConfigFactory1 config1Factory = new MockConfigFactory1(factory1,
+            BasicConfig1.class, "config1");
+    MockConfigFactory2 config2Factory = new MockConfigFactory2(factory2,
+            BasicConfig2.class, "config2");
+
+
+    @Before
+    public void setUp() throws Exception {
+        configStore = new DistributedNetworkConfigStore();
+        TestUtils.setField(configStore, "storageService", new TestStorageService());
+        configStore.activate();
+        manager = new NetworkConfigManager();
+        manager.store = configStore;
+        NetTestTools.injectEventDispatcher(manager, new EventDeliveryServiceAdapter());
+        manager.activate();
+        registry = manager;
+        configService = manager;
+    }
+
+    @After
+    public void tearDown() {
+        configStore.deactivate();
+        manager.deactivate();
+    }
+
+    @Test
+    public void testRegistry() {
+        assertThat(registry.getConfigFactories(), hasSize(0));
+        assertThat(registry.getConfigFactories(String.class), hasSize(0));
+        assertThat(registry.getConfigFactory(BasicConfig1.class), nullValue());
+
+        registry.registerConfigFactory(config1Factory);
+        registry.registerConfigFactory(config2Factory);
+
+        assertThat(registry.getConfigFactories(), hasSize(2));
+        assertThat(registry.getConfigFactories(String.class), hasSize(2));
+
+        ConfigFactory queried = registry.getConfigFactory(BasicConfig1.class);
+        assertThat(queried, is(config1Factory));
+
+        registry.unregisterConfigFactory(queried);
+        //  Factory associations are not removed according to code documentation
+        assertThat(registry.getConfigFactories(), hasSize(1));
+        assertThat(registry.getConfigFactories(String.class), hasSize(1));
+        assertThat(registry.getConfigFactory(BasicConfig1.class), nullValue());
+    }
+
+    @Test
+    public void configIdEquals() {
+        NetworkConfigManager.ConfigIdentifier id1 =
+                new NetworkConfigManager.ConfigIdentifier("s1", "c1");
+        NetworkConfigManager.ConfigIdentifier likeId1 =
+                new NetworkConfigManager.ConfigIdentifier("s1", "c1");
+        NetworkConfigManager.ConfigIdentifier id2 =
+                new NetworkConfigManager.ConfigIdentifier("s1", "c2");
+        NetworkConfigManager.ConfigIdentifier id3 =
+                new NetworkConfigManager.ConfigIdentifier("s2", "c1");
+
+        new EqualsTester().addEqualityGroup(id1, likeId1)
+                .addEqualityGroup(id2)
+                .addEqualityGroup(id3)
+                .testEquals();
+    }
+
+    @Test
+    public void configKeyEquals() {
+        NetworkConfigManager.ConfigKey key1 =
+                new NetworkConfigManager.ConfigKey(String.class, String.class);
+        NetworkConfigManager.ConfigKey likeKey1 =
+                new NetworkConfigManager.ConfigKey(String.class, String.class);
+        NetworkConfigManager.ConfigKey key2 =
+                new NetworkConfigManager.ConfigKey(String.class, Integer.class);
+        NetworkConfigManager.ConfigKey key3 =
+                new NetworkConfigManager.ConfigKey(Integer.class, String.class);
+
+        new EqualsTester().addEqualityGroup(key1, likeKey1)
+                .addEqualityGroup(key2)
+                .addEqualityGroup(key3)
+                .testEquals();
+    }
+
+    /**
+     * Tests creation, query and removal of a factory.
+     */
+    @Test
+    public void testAddConfig() {
+
+        assertThat(configService.getSubjectFactory(String.class), nullValue());
+        assertThat(configService.getSubjectFactory("key"), nullValue());
+
+        registry.registerConfigFactory(config1Factory);
+        registry.registerConfigFactory(config2Factory);
+        configService.addConfig("configKey", BasicConfig1.class);
+
+        Config newConfig = configService.getConfig("configKey", BasicConfig1.class);
+        assertThat(newConfig, notNullValue());
+
+        assertThat(configService.getSubjectFactory(String.class), notNullValue());
+        assertThat(configService.getSubjectFactory("key1"), notNullValue());
+
+        Set<Class> classes = configService.getSubjectClasses();
+        assertThat(classes, hasSize(1));
+
+        Set<String> subjectsForClass =
+                configService.getSubjects(String.class);
+        assertThat(subjectsForClass, hasSize(1));
+
+        Set<String> subjectsForConfig =
+                configService.getSubjects(String.class, BasicConfig1.class);
+        assertThat(subjectsForConfig, hasSize(1));
+
+        Class queriedConfigClass = configService.getConfigClass("key1", "config1");
+        assertThat(queriedConfigClass == BasicConfig1.class, is(true));
+
+        Set<? extends Config> configs = configService.getConfigs("configKey");
+        assertThat(configs.size(), is(1));
+        configs.forEach(c -> assertThat(c, instanceOf(BasicConfig1.class)));
+
+        configService.removeConfig("configKey", BasicConfig1.class);
+        Config newConfigAfterRemove = configService.getConfig("configKey", BasicConfig1.class);
+        assertThat(newConfigAfterRemove, nullValue());
+    }
+
+    /**
+     * Tests creation, query and removal of a factory.
+     */
+    @Test
+    public void testApplyConfig() {
+
+        assertThat(configService.getSubjectFactory(String.class), nullValue());
+        assertThat(configService.getSubjectFactory("key"), nullValue());
+
+        registry.registerConfigFactory(config1Factory);
+        registry.registerConfigFactory(config2Factory);
+        configService.applyConfig("configKey", BasicConfig1.class, new ObjectMapper().createObjectNode());
+
+        Config newConfig = configService.getConfig("configKey", BasicConfig1.class);
+        assertThat(newConfig, notNullValue());
+
+        assertThat(configService.getSubjectFactory(String.class), notNullValue());
+        assertThat(configService.getSubjectFactory("key1"), notNullValue());
+    }
+}
diff --git a/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java b/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
index 66d74c5..8827c55 100644
--- a/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/device/impl/BasicDeviceOperatorTest.java
@@ -26,7 +26,7 @@
 import org.onlab.packet.ChassisId;
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.ConfigApplyDelegate;
-import org.onosproject.incubator.net.config.basics.BasicDeviceConfig;
+import org.onosproject.net.config.basics.BasicDeviceConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DefaultAnnotations;
 import org.onosproject.net.DeviceId;
diff --git a/core/net/src/test/java/org/onosproject/net/device/impl/OpticalPortOperatorTest.java b/core/net/src/test/java/org/onosproject/net/device/impl/OpticalPortOperatorTest.java
index 83aa8a0..78bc08e 100644
--- a/core/net/src/test/java/org/onosproject/net/device/impl/OpticalPortOperatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/device/impl/OpticalPortOperatorTest.java
@@ -4,7 +4,7 @@
 import org.junit.Test;
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.ConfigApplyDelegate;
-import org.onosproject.incubator.net.config.basics.OpticalPortConfig;
+import org.onosproject.net.config.basics.OpticalPortConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultAnnotations;
diff --git a/core/net/src/test/java/org/onosproject/net/host/impl/BasicHostOperatorTest.java b/core/net/src/test/java/org/onosproject/net/host/impl/BasicHostOperatorTest.java
index fe0d97a..e7f14b5 100644
--- a/core/net/src/test/java/org/onosproject/net/host/impl/BasicHostOperatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/host/impl/BasicHostOperatorTest.java
@@ -24,7 +24,7 @@
 import org.onlab.packet.VlanId;
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.ConfigApplyDelegate;
-import org.onosproject.incubator.net.config.basics.BasicHostConfig;
+import org.onosproject.net.config.basics.BasicHostConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.HostId;
diff --git a/core/net/src/test/java/org/onosproject/net/link/impl/BasicLinkOperatorTest.java b/core/net/src/test/java/org/onosproject/net/link/impl/BasicLinkOperatorTest.java
index 610c974..fe9e37c 100644
--- a/core/net/src/test/java/org/onosproject/net/link/impl/BasicLinkOperatorTest.java
+++ b/core/net/src/test/java/org/onosproject/net/link/impl/BasicLinkOperatorTest.java
@@ -24,7 +24,7 @@
 import org.junit.Test;
 import org.onosproject.net.config.Config;
 import org.onosproject.net.config.ConfigApplyDelegate;
-import org.onosproject.incubator.net.config.basics.BasicLinkConfig;
+import org.onosproject.net.config.basics.BasicLinkConfig;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.net.ConnectPoint;
 import org.onosproject.net.DefaultAnnotations;