[ONOS-6884] Device config related utilities

- misc fixes around dynamic config

Change-Id: I3a7b6130e8c698594fa7deac8a04219c9c8a4af2
diff --git a/apps/config/pom.xml b/apps/config/pom.xml
old mode 100755
new mode 100644
index 2ae48c2..543c457
--- a/apps/config/pom.xml
+++ b/apps/config/pom.xml
@@ -23,7 +23,7 @@
         <version>1.11.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
-    <artifactId>onos-app-config</artifactId>
+    <artifactId>onos-apps-config</artifactId>
     <packaging>bundle</packaging>
     <description>Dynamic Config App6</description>
     <properties>
@@ -59,10 +59,17 @@
         <dependency>
             <groupId>org.hamcrest</groupId>
             <artifactId>hamcrest-core</artifactId>
+            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-junit</artifactId>
+            <scope>test</scope>
         </dependency>
     </dependencies>
 
diff --git a/apps/config/src/main/java/org/onosproject/config/DynamicConfigEvent.java b/apps/config/src/main/java/org/onosproject/config/DynamicConfigEvent.java
index 859e14d..a2e513e 100755
--- a/apps/config/src/main/java/org/onosproject/config/DynamicConfigEvent.java
+++ b/apps/config/src/main/java/org/onosproject/config/DynamicConfigEvent.java
@@ -53,7 +53,7 @@
         NODE_DELETED,
 
         /**
-         * Signifies an unknown and hence invalid store opeartion.
+         * Signifies an unknown and hence invalid store operation.
          */
         UNKNOWN_OPRN
     }
diff --git a/apps/config/src/main/java/org/onosproject/config/DynamicConfigServiceAdapter.java b/apps/config/src/main/java/org/onosproject/config/DynamicConfigServiceAdapter.java
new file mode 100644
index 0000000..4dcd671
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/DynamicConfigServiceAdapter.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.config;
+
+import static org.onosproject.yang.model.RpcOutput.Status.RPC_NODATA;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.onosproject.event.ListenerRegistry;
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.RpcInput;
+import org.onosproject.yang.model.RpcOutput;
+
+/**
+ * Adapter for DynamicConfigService.
+ */
+public class DynamicConfigServiceAdapter
+    implements DynamicConfigService {
+
+    protected final ListenerRegistry<DynamicConfigEvent, DynamicConfigListener>
+        listenerRegistry = new ListenerRegistry<>();
+
+
+
+    @Override
+    public void createNode(ResourceId path, DataNode node) {
+    }
+
+    @Override
+    public DataNode readNode(ResourceId path, Filter filter) {
+        return null;
+    }
+
+    @Override
+    public Boolean nodeExist(ResourceId path) {
+        return true;
+    }
+
+    @Override
+    public void updateNode(ResourceId path, DataNode node) {
+    }
+
+    @Override
+    public void replaceNode(ResourceId path, DataNode node) {
+    }
+
+    @Override
+    public void deleteNode(ResourceId path) {
+    }
+
+    @Override
+    public CompletableFuture<RpcOutput> invokeRpc(ResourceId id,
+                                                  RpcInput input) {
+        return CompletableFuture.completedFuture(new RpcOutput(RPC_NODATA, null));
+    }
+
+    @Override
+    public void addListener(DynamicConfigListener listener) {
+        listenerRegistry.addListener(listener);
+    }
+
+    @Override
+    public void removeListener(DynamicConfigListener listener) {
+        listenerRegistry.removeListener(listener);
+    }
+
+}
diff --git a/apps/config/src/main/java/org/onosproject/config/ForwardingDynamicConfigService.java b/apps/config/src/main/java/org/onosproject/config/ForwardingDynamicConfigService.java
new file mode 100644
index 0000000..b8e9167
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/config/ForwardingDynamicConfigService.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.config;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import java.util.concurrent.CompletableFuture;
+
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.RpcInput;
+import org.onosproject.yang.model.RpcOutput;
+
+/**
+ * A DynamicConfigService which forwards all its method calls
+ * to another DynamicConfigService.
+ */
+public class ForwardingDynamicConfigService implements DynamicConfigService {
+
+    private final DynamicConfigService delegate;
+
+    protected ForwardingDynamicConfigService(DynamicConfigService delegate) {
+        this.delegate = checkNotNull(delegate);
+    }
+
+    protected DynamicConfigService delegate() {
+        return delegate;
+    }
+
+    @Override
+    public void addListener(DynamicConfigListener listener) {
+        delegate.addListener(listener);
+    }
+
+    @Override
+    public void removeListener(DynamicConfigListener listener) {
+        delegate.removeListener(listener);
+    }
+
+    @Override
+    public void createNode(ResourceId path, DataNode node) {
+        delegate.createNode(path, node);
+    }
+
+    @Override
+    public DataNode readNode(ResourceId path, Filter filter) {
+        return delegate.readNode(path, filter);
+    }
+
+    @Override
+    public Boolean nodeExist(ResourceId path) {
+        return delegate.nodeExist(path);
+    }
+
+    @Override
+    public void updateNode(ResourceId path, DataNode node) {
+        delegate.updateNode(path, node);
+    }
+
+    @Override
+    public void replaceNode(ResourceId path, DataNode node) {
+        delegate.replaceNode(path, node);
+    }
+
+    @Override
+    public void deleteNode(ResourceId path) {
+        delegate.deleteNode(path);
+    }
+
+    @Override
+    public CompletableFuture<RpcOutput> invokeRpc(ResourceId id,
+                                                  RpcInput input) {
+        return delegate.invokeRpc(id, input);
+    }
+}
diff --git a/apps/config/src/main/java/org/onosproject/d/config/DataNodes.java b/apps/config/src/main/java/org/onosproject/d/config/DataNodes.java
new file mode 100644
index 0000000..5998206
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/d/config/DataNodes.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.d.config;
+
+import java.util.Collection;
+import java.util.Optional;
+
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.InnerNode;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.SchemaId;
+
+import com.google.common.annotations.Beta;
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Utility related to DataNode.
+ */
+@Beta
+public abstract class DataNodes {
+
+    // TODO it might make sense to turn these into DataNode methods
+
+    // should avoid using this. use other child methods
+    @Deprecated
+    public static Optional<DataNode> childOnlyByName(DataNode node, String name) {
+        if (node instanceof InnerNode) {
+            InnerNode inode = (InnerNode) node;
+            return inode.childNodes().values().stream()
+                        .filter(dn -> dn.key().schemaId().name().equals(name))
+                        .findFirst();
+        } else {
+            return Optional.empty();
+        }
+    }
+
+    public static Optional<DataNode> child(DataNode node, String name, String namespace) {
+        if (node instanceof InnerNode) {
+            InnerNode inode = (InnerNode) node;
+            NodeKey<?> key = NodeKey.builder().schemaId(name, namespace).build();
+            return Optional.ofNullable(inode.childNodes().get(key));
+        } else {
+            return Optional.empty();
+        }
+    }
+
+    public static Optional<DataNode> child(DataNode node, SchemaId child) {
+        if (node instanceof InnerNode) {
+            InnerNode inode = (InnerNode) node;
+            NodeKey<?> key = NodeKey.builder().schemaId(child).build();
+            return Optional.ofNullable(inode.childNodes().get(key));
+        } else {
+            return Optional.empty();
+        }
+    }
+
+    public static Optional<DataNode> child(DataNode node, NodeKey<?> child) {
+        if (node instanceof InnerNode) {
+            InnerNode inode = (InnerNode) node;
+            return Optional.ofNullable(inode.childNodes().get(child));
+        } else {
+            return Optional.empty();
+        }
+    }
+
+    public static Collection<DataNode> children(DataNode node) {
+        if (node instanceof InnerNode) {
+            InnerNode inode = (InnerNode) node;
+            return inode.childNodes().values();
+        } else {
+            return ImmutableList.of();
+        }
+    }
+
+}
diff --git a/apps/config/src/main/java/org/onosproject/d/config/DeviceResourceIds.java b/apps/config/src/main/java/org/onosproject/d/config/DeviceResourceIds.java
new file mode 100644
index 0000000..a49c6fc
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/d/config/DeviceResourceIds.java
@@ -0,0 +1,197 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.d.config;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import java.util.Optional;
+
+import org.onosproject.net.DeviceId;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Utility related to device ResourceId.
+ */
+@Beta
+public abstract class DeviceResourceIds {
+
+    // assuming following device tree structure
+    // - "/"
+    //    +- devices
+    //         +- device (=device root node:ListKey)
+
+
+    // FIXME randomly defined namespace, replace with something appropriate
+    /**
+     * SchemaId namespace for DCS defined nodes.
+     */
+    public static final String DCS_NAMESPACE = "org.onosproject.dcs";
+
+    /**
+     * SchemaId name for root node.
+     */
+    public static final String ROOT_NAME = "/";
+    /**
+     * SchemaId name for devices node.
+     */
+    public static final String DEVICES_NAME = "devices";
+    /**
+     * SchemaId name for device node.
+     */
+    public static final String DEVICE_NAME = "device";
+    /**
+     * KeyLeaf {@code name}, which holds DeviceId information on device node.
+     */
+    public static final String DEVICE_ID_KL_NAME = "device-id";
+
+    /**
+     * ResourceId pointing at root node.
+     */
+    public static final ResourceId ROOT_ID = ResourceId.builder()
+            .addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE)
+            .build();
+
+    static final NodeKey<?> ROOT_NODE =
+            NodeKey.builder().schemaId(ROOT_NAME, DCS_NAMESPACE).build();
+
+    /**
+     * nodeKeys index for root node.
+     */
+    static final int ROOT_INDEX = 0;
+    /**
+     * nodeKeys index for devices node.
+     */
+    static final int DEVICES_INDEX = 1;
+    /**
+     * nodeKeys index for device node.
+     */
+    static final int DEVICE_INDEX = 2;
+
+    /**
+     * Tests if specified path points to root node of a Device.
+     *
+     * @param path to test.
+     * @return true if path points to root node of a Device.
+     */
+    public static boolean isDeviceRootNode(ResourceId path) {
+        return path.nodeKeys().size() == 3 &&
+               isUnderDeviceRootNode(path);
+    }
+
+    /**
+     * Tests if specified path points to root node of a Device.
+     *
+     * @param path to test.
+     * @return true if path points to root node of a Device.
+     */
+    public static boolean isUnderDeviceRootNode(ResourceId path) {
+        return path.nodeKeys().size() >= 3 &&
+                // TODO Would be better to test whole schemeId
+                DEVICE_NAME.equals(path.nodeKeys().get(DEVICE_INDEX).schemaId().name()) &&
+                (path.nodeKeys().get(DEVICE_INDEX) instanceof ListKey) &&
+                // TODO Would be better to test whole schemeId
+                DEVICES_NAME.equals(path.nodeKeys().get(DEVICES_INDEX).schemaId().name()) &&
+                ROOT_NODE.equals(path.nodeKeys().get(ROOT_INDEX));
+    }
+
+    /**
+     * Tests if specified path points to root or devices node.
+     *
+     * @param path to test.
+     * @return true if path points to root node of a Device.
+     */
+    public static boolean isRootOrDevicesNode(ResourceId path) {
+        return isDevicesNode(path) ||
+               isRootNode(path);
+    }
+
+    public static boolean isDevicesNode(ResourceId path) {
+        return path.nodeKeys().size() == 2 &&
+                // TODO Would be better to test whole schemeId
+                DEVICES_NAME.equals(path.nodeKeys().get(DEVICES_INDEX).schemaId().name()) &&
+                ROOT_NODE.equals(path.nodeKeys().get(ROOT_INDEX));
+    }
+
+    public static boolean isRootNode(ResourceId path) {
+        return path.nodeKeys().size() == 1 &&
+                ROOT_NODE.equals(path.nodeKeys().get(ROOT_INDEX));
+    }
+
+    /**
+     * Transforms device resource path to DeviceId.
+     *
+     * @param path pointing to somewhere in the subtree of a device
+     * @return DeviceId
+     * @throws IllegalArgumentException if the path was not part of devices tree
+     */
+    public static DeviceId toDeviceId(ResourceId path) {
+        checkArgument(isUnderDeviceRootNode(path), path);
+        // FIXME if we decide to drop any of intermediate nodes
+        //        "/" - "devices" - "device"
+        return toDeviceId(path.nodeKeys().get(DEVICE_INDEX));
+    }
+
+    /**
+     * Transforms root node of a device to corresponding DeviceId.
+     *
+     * @param deviceRoot NodeKey of a device root node
+     * @return DeviceId
+     * @throws IllegalArgumentException if not a device node
+     */
+    public static DeviceId toDeviceId(NodeKey<?> deviceRoot) {
+        // TODO Would be better to test whole schemeId
+        if (!DEVICE_NAME.equals(deviceRoot.schemaId().name())) {
+            throw new IllegalArgumentException(deviceRoot + " is not a device node");
+        }
+
+        if (deviceRoot instanceof ListKey) {
+            ListKey device = (ListKey) deviceRoot;
+            Optional<DeviceId> did = device.keyLeafs().stream()
+                // TODO If we decide to define ONOS schema for device ID,
+                // use whole schemaId to filter, not only by name
+                .filter(kl -> DEVICE_ID_KL_NAME.equals(kl.leafSchema().name()))
+                .map(KeyLeaf::leafValAsString)
+                .map(DeviceId::deviceId)
+                .findFirst();
+
+            if (did.isPresent()) {
+                return did.get();
+            }
+            throw new IllegalArgumentException("device-id not found in " + deviceRoot);
+        }
+        throw new IllegalArgumentException("Unexpected type " + deviceRoot.getClass());
+    }
+
+    /**
+     * Transforms DeviceId into a ResourceId pointing to device root node.
+     *
+     * @param deviceId to transform
+     * @return ResourceId
+     */
+    public static ResourceId toResourceId(DeviceId deviceId) {
+        return ResourceId.builder()
+                .addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE)
+                .addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE)
+                .addBranchPointSchema(DEVICE_NAME, DCS_NAMESPACE)
+                .addKeyLeaf(DEVICE_ID_KL_NAME, DCS_NAMESPACE, deviceId.toString())
+                .build();
+    }
+
+}
diff --git a/apps/config/src/main/java/org/onosproject/d/config/ResourceIds.java b/apps/config/src/main/java/org/onosproject/d/config/ResourceIds.java
new file mode 100644
index 0000000..4340d27
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/d/config/ResourceIds.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.d.config;
+
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.slf4j.LoggerFactory.getLogger;
+
+import org.onosproject.yang.model.DataNode;
+import org.onosproject.yang.model.KeyLeaf;
+import org.onosproject.yang.model.LeafListKey;
+import org.onosproject.yang.model.ListKey;
+import org.onosproject.yang.model.NodeKey;
+import org.onosproject.yang.model.ResourceId;
+import org.onosproject.yang.model.ResourceId.Builder;
+import org.onosproject.yang.model.SchemaId;
+import org.slf4j.Logger;
+
+import com.google.common.annotations.Beta;
+
+/**
+ * Utility related to ResourceId.
+ */
+@Beta
+public abstract class ResourceIds {
+
+    private static final Logger log = getLogger(ResourceIds.class);
+
+    /**
+     * Builds the ResourceId of specified {@code node}.
+     *
+     * @param parent ResourceId of {@code node} parent
+     * @param node to create ResourceId.
+     * @return ResourceId of {@code node}
+     */
+    public static ResourceId resourceId(ResourceId parent, DataNode node) {
+        final ResourceId.Builder builder;
+        if (parent == null) {
+            builder = ResourceId.builder();
+        } else {
+            try {
+                builder = parent.copyBuilder();
+            } catch (CloneNotSupportedException e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+
+        SchemaId sid = node.key().schemaId();
+        switch (node.type()) {
+        case MULTI_INSTANCE_LEAF_VALUE_NODE:
+            builder.addLeafListBranchPoint(sid.name(), sid.namespace(),
+                                           ((LeafListKey) node.key()).asString());
+            break;
+
+        case MULTI_INSTANCE_NODE:
+            builder.addBranchPointSchema(sid.name(), sid.namespace());
+            for (KeyLeaf keyLeaf : ((ListKey) node.key()).keyLeafs()) {
+                builder.addKeyLeaf(keyLeaf.leafSchema().name(),
+                                   keyLeaf.leafSchema().namespace(),
+                                   keyLeaf.leafValAsString());
+            }
+            break;
+
+        case SINGLE_INSTANCE_LEAF_VALUE_NODE:
+        case SINGLE_INSTANCE_NODE:
+            builder.addBranchPointSchema(sid.name(), sid.namespace());
+            break;
+
+        default:
+            throw new IllegalArgumentException("Unknown type " + node);
+
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Concats {@code path} after {@code prefix}.
+     *
+     * @param prefix path
+     * @param path to append after {@code path}
+     * @return concatenated ResouceId
+     */
+    public static ResourceId concat(ResourceId prefix, ResourceId path) {
+        checkArgument(!path.nodeKeys().contains(DeviceResourceIds.ROOT_NODE),
+                      "%s was already absolute path", path);
+        try {
+            return prefix.copyBuilder().append(path).build();
+        } catch (CloneNotSupportedException e) {
+            log.error("Could not copy {}", path, e);
+            throw new IllegalArgumentException("Could not copy " + path, e);
+        }
+    }
+
+
+    /**
+     * Returns {@code child} ad relative ResourceId against {@code base}.
+     *
+     * @param base ResourceId
+     * @param child ResourceId to relativize
+     * @return relative ResourceId
+     */
+    public static ResourceId relativize(ResourceId base, ResourceId child) {
+        checkArgument(child.nodeKeys().size() >= base.nodeKeys().size(),
+                      "%s path must be deeper than base prefix %s", child, base);
+        checkArgument(base.nodeKeys().equals(child.nodeKeys().subList(0, base.nodeKeys().size())),
+                      "%s is not a prefix of %s", child, base);
+
+        // FIXME waiting for Yang tools 2.2.0-b4 or later
+//        return ResourceId.builder().append(child.nodeKeys().subList(base.nodeKeys().size(),
+//                                                                    child.nodeKeys().size())).build();
+
+        Builder builder = ResourceId.builder();
+        for (NodeKey nodeKey : child.nodeKeys().subList(base.nodeKeys().size(),
+                                                        child.nodeKeys().size())) {
+            if (nodeKey instanceof ListKey) {
+                ListKey listKey = (ListKey) nodeKey;
+                for (KeyLeaf keyLeaf : listKey.keyLeafs()) {
+                    builder.addKeyLeaf(keyLeaf.leafSchema().name(),
+                                       keyLeaf.leafSchema().namespace(),
+                                       keyLeaf.leafValAsString());
+                }
+            } else if (nodeKey instanceof LeafListKey) {
+                LeafListKey llKey = (LeafListKey) nodeKey;
+                builder.addLeafListBranchPoint(llKey.schemaId().name(),
+                                               llKey.schemaId().namespace(),
+                                               llKey.value());
+
+            } else {
+                builder.addBranchPointSchema(nodeKey.schemaId().name(),
+                                             nodeKey.schemaId().namespace());
+            }
+        }
+        return builder.build();
+    }
+
+    /**
+     * Tests if {@code child} starts with {@code prefix}.
+     *
+     * @param prefix expected
+     * @param child to test
+     * @return true if {@code child} starts with {@code prefix}
+     */
+    public static boolean isPrefix(ResourceId prefix, ResourceId child) {
+
+        return child.nodeKeys().size() >= prefix.nodeKeys().size() &&
+               prefix.nodeKeys().equals(child.nodeKeys().subList(0, prefix.nodeKeys().size()));
+    }
+
+}
diff --git a/apps/config/src/main/java/org/onosproject/d/config/package-info.java b/apps/config/src/main/java/org/onosproject/d/config/package-info.java
new file mode 100644
index 0000000..b833e16
--- /dev/null
+++ b/apps/config/src/main/java/org/onosproject/d/config/package-info.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.
+ */
+/**
+ * Dynamic device config supporting classes and  interfaces.
+ */
+package org.onosproject.d.config;
diff --git a/apps/config/src/test/java/org/onosproject/d/config/DeviceResourceIdsTest.java b/apps/config/src/test/java/org/onosproject/d/config/DeviceResourceIdsTest.java
new file mode 100644
index 0000000..c0cc522
--- /dev/null
+++ b/apps/config/src/test/java/org/onosproject/d/config/DeviceResourceIdsTest.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.d.config;
+
+import static org.junit.Assert.*;
+import static org.onosproject.d.config.DeviceResourceIds.DCS_NAMESPACE;
+import static org.onosproject.d.config.DeviceResourceIds.DEVICES_NAME;
+import static org.onosproject.d.config.DeviceResourceIds.ROOT_NAME;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onosproject.d.config.DeviceResourceIds;
+import org.onosproject.net.DeviceId;
+import org.onosproject.yang.model.ResourceId;
+
+public class DeviceResourceIdsTest {
+
+    static final DeviceId DID_A = DeviceId.deviceId("test:A");
+
+    static final ResourceId DEVICES = ResourceId.builder()
+            .addBranchPointSchema(ROOT_NAME, DCS_NAMESPACE)
+            .addBranchPointSchema(DEVICES_NAME, DCS_NAMESPACE)
+            .build();
+
+    ResourceId ridA;
+    ResourceId ridAcopy;
+
+    @Before
+    public void setUp() throws Exception {
+        ridA = DeviceResourceIds.toResourceId(DID_A);
+        ridAcopy = ridA.copyBuilder().build();
+    }
+
+    @Test
+    public void testToDeviceId() throws CloneNotSupportedException {
+        ResourceId ridAchild = ridA.copyBuilder()
+                    .addBranchPointSchema("some", "ns")
+                    .addBranchPointSchema("random", "ns")
+                    .addBranchPointSchema("child", "ns")
+                    .build();
+
+        assertEquals(DID_A, DeviceResourceIds.toDeviceId(ridAchild));
+    }
+
+    @Test
+    public void testDeviceRootNode() {
+        assertTrue(DeviceResourceIds.isDeviceRootNode(ridA));
+
+        assertFalse(DeviceResourceIds.isRootOrDevicesNode(ridA));
+    }
+
+}
diff --git a/apps/config/src/test/java/org/onosproject/d/config/ResourceIdsTest.java b/apps/config/src/test/java/org/onosproject/d/config/ResourceIdsTest.java
new file mode 100644
index 0000000..dc17b11
--- /dev/null
+++ b/apps/config/src/test/java/org/onosproject/d/config/ResourceIdsTest.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017-present Open Networking Foundation
+ *
+ * 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.d.config;
+
+import static org.junit.Assert.*;
+import static org.onosproject.d.config.DeviceResourceIds.DCS_NAMESPACE;
+
+import org.junit.Test;
+import org.onosproject.yang.model.ResourceId;
+
+public class ResourceIdsTest {
+
+    final ResourceId DEVICES = ResourceId.builder()
+            .addBranchPointSchema(DeviceResourceIds.ROOT_NAME, DCS_NAMESPACE)
+            .addBranchPointSchema(DeviceResourceIds.DEVICES_NAME, DCS_NAMESPACE)
+            .build();
+
+    @Test
+    public void testConcat() {
+        ResourceId devices = ResourceId.builder()
+            .addBranchPointSchema(DeviceResourceIds.DEVICES_NAME,
+                                  DCS_NAMESPACE)
+            .build();
+
+        assertEquals(DEVICES, ResourceIds.concat(DeviceResourceIds.ROOT_ID, devices));
+    }
+
+    @Test
+    public void testRelativize() {
+        ResourceId relDevices = ResourceIds.relativize(DeviceResourceIds.ROOT_ID, DEVICES);
+        assertEquals(DeviceResourceIds.DEVICES_NAME,
+                     relDevices.nodeKeys().get(0).schemaId().name());
+        assertEquals(DCS_NAMESPACE,
+                     relDevices.nodeKeys().get(0).schemaId().namespace());
+        assertEquals(1, relDevices.nodeKeys().size());
+    }
+
+    @Test
+    public void testRelativizeEmpty() {
+        ResourceId relDevices = ResourceIds.relativize(DEVICES, DEVICES);
+        // equivalent of . in file path, expressed as ResourceId with empty
+        assertTrue(relDevices.nodeKeys().isEmpty());
+
+    }
+}
diff --git a/apps/netconf/client/pom.xml b/apps/netconf/client/pom.xml
new file mode 100644
index 0000000..2952033
--- /dev/null
+++ b/apps/netconf/client/pom.xml
@@ -0,0 +1,200 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2017 Open Networking Foundation
+  ~
+  ~ 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.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <artifactId>onos-apps</artifactId>
+        <groupId>org.onosproject</groupId>
+        <version>1.11.0-SNAPSHOT</version>
+        <relativePath>../../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>onos-apps-netconf-client</artifactId>
+    <packaging>bundle</packaging>
+
+    <description>Dynamic Config NETCONF Device synchronizer</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+        <onos.version>${project.version}</onos.version>
+        <onos.app.name>org.onosproject.netconfsb</onos.app.name>
+        <onos.app.origin>ON.Lab</onos.app.origin>
+        <onos.app.requires>org.onosproject.yang,org.onosproject.config,org.onosproject.netconf</onos.app.requires>
+        <onos.app.category>Protocols</onos.app.category>
+        <onos.app.title>NETCONF Device Configuration</onos.app.title>
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-yang-model</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-yang-runtime</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-apps-config</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-netconf-api</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-cli</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.karaf.shell</groupId>
+            <artifactId>org.apache.karaf.shell.console</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.compendium</artifactId>
+            <scope>provided</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+
+    </dependencies>
+
+    <build>
+        <pluginManagement>
+            <plugins>
+
+                <plugin>
+                    <groupId>org.apache.karaf.tooling</groupId>
+                    <artifactId>karaf-maven-plugin</artifactId>
+                    <version>3.0.5</version>
+                    <extensions>true</extensions>
+                </plugin>
+
+            </plugins>
+        </pluginManagement>
+
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <extensions>true</extensions>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+
+        </plugins>
+    </build>
+
+</project>
diff --git a/apps/pom.xml b/apps/pom.xml
index 257d229..7978976 100644
--- a/apps/pom.xml
+++ b/apps/pom.xml
@@ -87,6 +87,8 @@
         <module>network-troubleshoot</module>
         <module>restconf</module>
         <module>yang</module>
+        <module>openroadm</module>
+        <module>netconf/client</module>
     </modules>
 
     <properties>
diff --git a/apps/restconf/restconfmgr/pom.xml b/apps/restconf/restconfmgr/pom.xml
index e12c857..a971d07 100644
--- a/apps/restconf/restconfmgr/pom.xml
+++ b/apps/restconf/restconfmgr/pom.xml
@@ -40,7 +40,7 @@
         </dependency>
         <dependency>
             <groupId>org.onosproject</groupId>
-            <artifactId>onos-app-config</artifactId>
+            <artifactId>onos-apps-config</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>
diff --git a/apps/restconf/utils/pom.xml b/apps/restconf/utils/pom.xml
index bff842b..5a576ba 100644
--- a/apps/restconf/utils/pom.xml
+++ b/apps/restconf/utils/pom.xml
@@ -44,7 +44,7 @@
         </dependency>
         <dependency>
             <groupId>org.onosproject</groupId>
-            <artifactId>onos-app-config</artifactId>
+            <artifactId>onos-apps-config</artifactId>
             <version>${project.version}</version>
         </dependency>
         <dependency>