Sketching out basis for network configuration subsystem API.
Change-Id: I9d56a8392bd300566fb333607102cc965b2fa66e
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/Config.java b/exp/api/src/main/java/org/onosproject/exp/net/config/Config.java
new file mode 100644
index 0000000..2423de5
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/Config.java
@@ -0,0 +1,67 @@
+/*
+ * 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.exp.net.config;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+/**
+ * Base abstraction of a configuration facade for a specific subject. Derived
+ * classes should keep all state in the specified JSON tree.
+ *
+ * @param <S> type of subject
+ */
+public abstract class Config<S> {
+
+ protected ObjectMapper mapper;
+ protected ObjectNode node;
+ private S subject;
+ private ConfigApplyDelegate<S> delegate;
+
+ /**
+ * Returns the specific subject to which this configuration pertains.
+ *
+ * @return configuration subject
+ */
+ S subject() {
+ return subject;
+ }
+
+ /**
+ * Initializes the configuration behaviour with necessary context.
+ *
+ * @param subject configuration subject
+ * @param node JSON object node where configuration data is stored
+ * @param mapper JSON object mapper
+ */
+ public void init(S subject, ObjectNode node, ObjectMapper mapper,
+ ConfigApplyDelegate<S> delegate) {
+ this.subject = checkNotNull(subject);
+ this.node = checkNotNull(node);
+ this.mapper = checkNotNull(mapper);
+ this.delegate = checkNotNull(delegate);
+ }
+
+ /**
+ * Applies any configuration changes made via this configuration.
+ */
+ public void apply() {
+ delegate.onApply(this);
+ }
+
+}
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigApplyDelegate.java b/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigApplyDelegate.java
new file mode 100644
index 0000000..6f3cb6d
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigApplyDelegate.java
@@ -0,0 +1,30 @@
+/*
+ * 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.exp.net.config;
+
+/**
+ * Delegate for notification when configuration changes have been applied.
+ */
+public interface ConfigApplyDelegate<S> {
+
+ /**
+ * Processes changes applied to the specified configuration.
+ *
+ * @param config changed configuration
+ */
+ void onApply(Config<S> config);
+
+}
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigFactory.java b/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigFactory.java
new file mode 100644
index 0000000..94e599a
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/ConfigFactory.java
@@ -0,0 +1,67 @@
+/*
+ * 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.exp.net.config;
+
+
+/**
+ * Base abstract factory for creating configurations for the specified subject type.
+ *
+ * @param <S> subject class
+ */
+public abstract class ConfigFactory<S> {
+
+ private final Class<S> subjectClass;
+ private final String key;
+
+ /**
+ * Creates a new configuration factory for the specified class of subjects
+ * and bound to the given subject configuration key.
+ *
+ * @param subjectClass subject class
+ * @param key subject configuration key
+ */
+ protected ConfigFactory(Class<S> subjectClass, String key) {
+ this.subjectClass = subjectClass;
+ this.key = key;
+ }
+
+ /**
+ * Returns the class of the subject to which this factory applies.
+ *
+ * @return subject type
+ */
+ public Class<S> subjectClass() {
+ return subjectClass;
+ }
+
+ /**
+ * Returns the key to which produced configurations should be bound.
+ *
+ * @return subject configuration key
+ */
+ public String key() {
+ return key;
+ }
+
+ /**
+ * Creates a new but uninitialized configuration. Framework will initialize
+ * the configuration via {@link Config#init} method.
+ *
+ * @return new uninitialized configuration
+ */
+ public abstract Config<S> createConfig();
+
+}
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigRegistry.java b/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigRegistry.java
new file mode 100644
index 0000000..711279b
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigRegistry.java
@@ -0,0 +1,63 @@
+/*
+ * 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.exp.net.config;
+
+import java.util.Set;
+
+/**
+ * Service for tracking network configuration factories.
+ */
+public interface NetworkConfigRegistry {
+
+ /**
+ * Registers the specified configuration factory.
+ *
+ * @param configFactory configuration factory
+ */
+ void registerConfigFactory(ConfigFactory configFactory);
+
+ /**
+ * Unregisters the specified configuration factory.
+ *
+ * @param configFactory configuration factory
+ */
+ void unregisterConfigFactory(ConfigFactory configFactory);
+
+ /**
+ * Returns set of configuration factories available for the specified
+ * class of subject.
+ *
+ * @param subjectClass subject class
+ */
+ <T> Set<ConfigFactory<T>> getConfigFactories(Class<T> subjectClass);
+
+ /**
+ * Returns the configuration type registered for the specified
+ * subject type and key.
+ *
+ * @param subjectClass subject class
+ */
+ <T> ConfigFactory<T> getConfigFactory(Class<T> subjectClass, String configKey);
+
+ /**
+ * Returns the configuration type registered for the specified
+ * configuration class.
+ *
+ * @param configClass configuration class
+ */
+ <T> ConfigFactory<T> getConfigFactory(Class<Config<T>> configClass);
+
+}
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigService.java b/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigService.java
new file mode 100644
index 0000000..3dae379
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/NetworkConfigService.java
@@ -0,0 +1,64 @@
+/*
+ * 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.exp.net.config;
+
+import java.util.Set;
+
+/**
+ * Service for tracking network configurations which specify how the discovered
+ * network information should be interpretted and how the network should be
+ * configured.
+ */
+public interface NetworkConfigService {
+
+ /**
+ * Returns the set of subjects for which some configuration is available.
+ *
+ * @param subjectClass subject class
+ * @return set of configured subjects
+ */
+ <T> Set<T> getSubjects(Class<T> subjectClass);
+
+ /**
+ * Returns the set of subjects for which the specified configuration is
+ * available.
+ *
+ * @param subjectClass subject class
+ * @param configClass configuration class
+ * @return set of configured subjects
+ */
+ <T> Set<T> getSubjects(Class<T> subjectClass, Class<Config<T>> configClass);
+
+
+ /**
+ * Returns all configurations for the specified subject.
+ *
+ * @param subject configuration subject
+ * @return set of configurations
+ */
+ <T> Set<Config<T>> getConfigs(T subject);
+
+ /**
+ * Returns the configuration for the specified subject and configuration
+ * class if one is available; null otherwise.
+ *
+ * @param subject configuration subject
+ * @param configClass configuration class
+ * @return configuration or null if one is not available
+ */
+ <T> Config<T> getConfig(T subject, Class<Config<T>> configClass);
+
+}
diff --git a/exp/api/src/main/java/org/onosproject/exp/net/config/package-info.java b/exp/api/src/main/java/org/onosproject/exp/net/config/package-info.java
new file mode 100644
index 0000000..836af2b
--- /dev/null
+++ b/exp/api/src/main/java/org/onosproject/exp/net/config/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.
+ */
+
+/**
+ * Subsystem for tracking network environment configuration.
+ */
+package org.onosproject.exp.net.config;
\ No newline at end of file