[ONOS-5076] YANG data tree Builder
Change-Id: I25160b651c26e614d29d7fad85e63f77a262d77c
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/TraversalType.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/TraversalType.java
new file mode 100644
index 0000000..d5b58f9
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/TraversalType.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-present 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.yms.app.utils;
+
+/**
+ * Represents traversal type of the YANG node tree.
+ */
+public enum TraversalType {
+
+ /*
+ * Start of traversal at the tree root.
+ */
+ ROOT,
+
+ /*
+ * Child node traversal.
+ */
+ CHILD,
+
+ /*
+ * Sibling node traversal.
+ */
+ SIBLING,
+
+ /*
+ * Parent node traversal.
+ */
+ PARENT
+}
+
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/package-info.java
new file mode 100644
index 0000000..5957cf3
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/utils/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-present 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.
+ */
+
+/**
+ * Provides implementation of build and obtain YANG data tree which is data
+ * (sub)instance representation, abstract of protocol.
+ */
+package org.onosproject.yms.app.utils;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppData.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppData.java
new file mode 100644
index 0000000..8fee570
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppData.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.List;
+
+/**
+ * Maintains application data, which will be used by Application broker to
+ * interact with applications.
+ */
+public interface AppData {
+
+ /**
+ * Returns the list of nodes with operation type delete.
+ *
+ * @return list of nodes with operation type delete
+ */
+ List<YdtContext> getDeleteNodes();
+
+ /**
+ * Adds the ydt node with operation type delete in module delete node list.
+ *
+ * @param node ydt node with operation type delete/remove
+ */
+ void addDeleteNodes(YdtContext node);
+
+ /**
+ * Returns application's root ydtContext.
+ *
+ * @return YdtContext of application root node
+ */
+ YdtContext getModuleContext();
+
+ /**
+ * Sets the application's ydtContext.
+ *
+ * @param moduleNode application's ydtContext
+ */
+ void setModuleContext(YdtContext moduleNode);
+
+ /**
+ * Returns the YangSchemaNode of augmenting application.
+ *
+ * @return YangSchemaNode of augmenting application
+ */
+ YangSchemaNode getAugmentingSchemaNode();
+
+ /**
+ * Sets the YangSchemaNode of augmenting application root node.
+ *
+ * @param schemaNode YangSchemaNode of augmenting application module
+ */
+ void setAugmentingSchemaNode(YangSchemaNode schemaNode);
+
+ /**
+ * Returns the schema node current context.
+ *
+ * @return schema node
+ */
+ YangSchemaNode getSchemaNode();
+
+ /**
+ * Returns the root/module schema node current application.
+ *
+ * @return schema node
+ */
+ YangSchemaNode getRootSchemaNode();
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppNodeFactory.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppNodeFactory.java
new file mode 100644
index 0000000..621eda6
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppNodeFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import static org.onosproject.yms.app.ydt.DefaultYdtAppContext.getAugmentAppContext;
+import static org.onosproject.yms.app.ydt.DefaultYdtAppContext.getModuleAppContext;
+
+/**
+ * Represents an application tree node factory to create different types of
+ * application tree node.
+ */
+public final class AppNodeFactory {
+
+ // No instantiation
+ private AppNodeFactory() {
+ }
+
+ /**
+ * Returns the appropriate application context on the basis of provided
+ * isAugmented flag for given request.
+ *
+ * @param isAugmented true for augmented context; false for module context
+ * @return appContext application context
+ */
+ public static DefaultYdtAppContext getAppContext(boolean isAugmented) {
+ return isAugmented ? getAugmentAppContext() : getModuleAppContext();
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppType.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppType.java
new file mode 100644
index 0000000..4d581a3
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AppType.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+/**
+ * Represents type of application, which is intended to maintain additional
+ * information in YDT node.
+ */
+public enum AppType {
+
+ /**
+ * YANG tree builder application.
+ */
+ YTB,
+
+ /**
+ * YANG object builder application.
+ */
+ YOB
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AugmentedSchemaData.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AugmentedSchemaData.java
new file mode 100644
index 0000000..6a45cad
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/AugmentedSchemaData.java
@@ -0,0 +1,82 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yms.app.ydt.exceptions.YdtException;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.List;
+
+/**
+ * Manages the application information required for schema nodes defined in
+ * the module (sub-module).
+ */
+public class AugmentedSchemaData implements AppData {
+
+ private static final String E_NOT_ROOTAPP =
+ "Augmented application depends on root app.";
+ private static final String E_NOT_EXIST =
+ "Augmented nodes are not part of the schema.";
+ private static final String E_NOT_MAINTAINED =
+ "Module context is not maintained.";
+
+ /*
+ * Reference for schema node of augmenting application.
+ */
+ private YangSchemaNode augModSchema;
+
+ @Override
+ public List<YdtContext> getDeleteNodes() {
+ throw new YdtException(E_NOT_ROOTAPP);
+ }
+
+ @Override
+ public void addDeleteNodes(YdtContext deletedNode) {
+ }
+
+ @Override
+ public YdtContext getModuleContext() {
+ throw new YdtException(E_NOT_EXIST);
+ }
+
+ @Override
+ public void setModuleContext(YdtContext moduleContext) {
+ throw new YdtException(E_NOT_MAINTAINED);
+ }
+
+ @Override
+ public YangSchemaNode getAugmentingSchemaNode() {
+ return augModSchema;
+ }
+
+ @Override
+ public void setAugmentingSchemaNode(YangSchemaNode schemaNode) {
+ augModSchema = schemaNode;
+ }
+
+ @Override
+ public YangSchemaNode getSchemaNode() {
+ return augModSchema;
+ }
+
+ @Override
+ public YangSchemaNode getRootSchemaNode() {
+ return ((YangNode) getSchemaNode()).getParent();
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java
new file mode 100644
index 0000000..f75fc9c
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtAppContext.java
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangAugment;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yms.app.ydt.exceptions.YdtException;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.BOTH;
+import static org.onosproject.yms.app.ydt.YdtNodeFactory.getAppOpTypeFromYdtOpType;
+
+/**
+ * Represents YANG request work bench which contains all parameters for
+ * request handling and methods to build and obtain YANG application data tree
+ * which is data (sub)instance representation, abstract of protocol.
+ */
+public final class DefaultYdtAppContext<T extends AppData>
+ implements YdtAppContext {
+
+ /*
+ * Parent reference.
+ */
+ private YdtAppContext parent;
+
+ /*
+ * First child reference.
+ */
+ private YdtAppContext child;
+
+ /*
+ * Next sibling reference.
+ */
+ private YdtAppContext nextSibling;
+
+ /*
+ * Previous sibling reference.
+ */
+ private YdtAppContext previousSibling;
+
+ /*
+ * Last child reference.
+ */
+ private YdtAppContext lastChild;
+
+ /*
+ * YDT application tree extended information.
+ */
+ private T appData;
+
+ /*
+ * Reference for operation type for application root node.
+ */
+ private YdtAppNodeOperationType operationType;
+
+ /*
+ * Reference application node set.
+ */
+ private Set<YangSchemaNode> appSet;
+
+ /**
+ * Creates an instance of YANG application tree which is used by all node
+ * needs delete list.
+ */
+ private DefaultYdtAppContext() {
+ appSet = new HashSet<>();
+ }
+
+ /**
+ * Adds schema node of new requested augmented node in current context of
+ * application tree.
+ *
+ * @param schemaNode schema node of requested node
+ * @return addition result(true/false)
+ */
+ public boolean addSchemaToAppSet(YangSchemaNode schemaNode) {
+ return appSet.add(schemaNode);
+ }
+
+ @Override
+ public void updateAppOperationType(YdtContextOperationType ydtOpType) {
+ if (parent == null) {
+ return;
+ }
+ YdtAppNodeOperationType opType = getAppOpTypeFromYdtOpType(ydtOpType);
+ YdtAppContext curNode = this;
+ YdtAppNodeOperationType parentOpType = operationType;
+ if (parentOpType != null && opType != parentOpType) {
+ while (curNode.getOperationType() != BOTH &&
+ curNode.getParent() != null) {
+ curNode.setOperationType(BOTH);
+ curNode = curNode.getParent();
+ }
+ }
+ }
+
+ @Override
+ public void setAppData(YdtNode moduleNode, YangSchemaNode augmentNode) {
+ if (augmentNode != null) {
+ appData.setAugmentingSchemaNode(augmentNode);
+ } else {
+ appData.setModuleContext(moduleNode);
+ }
+ }
+
+ @Override
+ public AppData getAppData() {
+ return appData;
+ }
+
+ @Override
+ public YdtAppContext getParent() {
+ return parent;
+ }
+
+ @Override
+ public void setParent(YdtAppContext parent) {
+ this.parent = parent;
+ }
+
+ @Override
+ public YdtAppContext getFirstChild() {
+ return child;
+ }
+
+ @Override
+ public void setChild(YdtAppContext child) {
+ this.child = child;
+ }
+
+ @Override
+ public YdtAppContext getNextSibling() {
+ return nextSibling;
+ }
+
+ @Override
+ public void setNextSibling(YdtAppContext nextSibling) {
+ this.nextSibling = nextSibling;
+ }
+
+ @Override
+ public YdtAppContext getPreviousSibling() {
+ return previousSibling;
+ }
+
+ @Override
+ public void setPreviousSibling(YdtAppContext previousSibling) {
+ this.previousSibling = previousSibling;
+ }
+
+ @Override
+ public YdtAppNodeOperationType getOperationType() {
+ return operationType;
+ }
+
+ @Override
+ public void setOperationType(YdtAppNodeOperationType opType) {
+ operationType = opType;
+ }
+
+ @Override
+ public List<YdtContext> getDeleteNodes() {
+ return appData.getDeleteNodes();
+ }
+
+
+ @Override
+ public void addDeleteNode(YdtNode node) {
+ DefaultYdtAppContext<?> curNode = this;
+ while (curNode.getParent().getParent() != null) {
+ curNode = (DefaultYdtAppContext<?>) curNode.getParent();
+ }
+
+ curNode.appData.addDeleteNodes(node);
+ }
+
+ @Override
+ public YdtContext getModuleContext() {
+ return appData.getModuleContext();
+ }
+
+ @Override
+ public void setModuleContext(YdtContext moduleNode) {
+ appData.setModuleContext(moduleNode);
+ }
+
+ @Override
+ public YangSchemaNode getAugmentingSchemaNode() {
+ return appData.getAugmentingSchemaNode();
+ }
+
+ @Override
+ public void setAugmentingSchemaNode(YangSchemaNode schemaNode) {
+ appData.setAugmentingSchemaNode(schemaNode);
+ }
+
+
+ @Override
+ public YangSchemaNode getAugmentingSchemaNode(
+ YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo contextInfo) {
+ YangSchemaNode lastAugMod = null;
+ YangSchemaNode switchedNode =
+ contextInfo.getContextSwitchedNode();
+
+ while (switchedNode != null) {
+ if (switchedNode instanceof YangAugment) {
+ lastAugMod = switchedNode;
+ }
+ try {
+ switchedNode = switchedNode.getChildSchema(id)
+ .getContextSwitchedNode();
+ } catch (DataModelException e) {
+ throw new YdtException(e.getMessage());
+ }
+ }
+ return lastAugMod;
+ }
+
+ @Override
+ public YdtAppContext getLastChild() {
+ return lastChild;
+ }
+
+ @Override
+ public void setLastChild(YdtAppContext lastChild) {
+ this.lastChild = lastChild;
+ }
+
+ @Override
+ public void addChild(YdtAppContext newChild) {
+
+ if (newChild.getParent() == null) {
+ newChild.setParent(this);
+ }
+
+ // First child to be added.
+ if (getFirstChild() == null) {
+ setChild(newChild);
+ // Update last child.
+ setLastChild(newChild);
+ return;
+ }
+
+ // If the new node needs to be add as last child.
+ YdtAppContext curNode = getLastChild();
+ curNode.setNextSibling(newChild);
+ newChild.setPreviousSibling(curNode);
+ setLastChild(newChild);
+ }
+
+ @Override
+ public YangSchemaNode getYangSchemaNode() {
+ return appData.getSchemaNode();
+ }
+
+ /**
+ * Creates an instance of application tree context with module schema data.
+ *
+ * @return application tree context
+ */
+ public static DefaultYdtAppContext getModuleAppContext() {
+ DefaultYdtAppContext context =
+ new DefaultYdtAppContext<ModuleSchemaData>();
+ context.appData = new ModuleSchemaData();
+ return context;
+ }
+
+ /**
+ * Creates an instance of application tree context with augment schema data.
+ *
+ * @return application tree context
+ */
+ public static DefaultYdtAppContext getAugmentAppContext() {
+ DefaultYdtAppContext context =
+ new DefaultYdtAppContext<AugmentedSchemaData>();
+ context.appData = new AugmentedSchemaData();
+ return context;
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtWalker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtWalker.java
new file mode 100644
index 0000000..bb692cf
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/DefaultYdtWalker.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+
+import org.onosproject.yms.app.utils.TraversalType;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtListener;
+
+import static org.onosproject.yms.app.utils.TraversalType.CHILD;
+import static org.onosproject.yms.app.utils.TraversalType.PARENT;
+import static org.onosproject.yms.app.utils.TraversalType.ROOT;
+import static org.onosproject.yms.app.utils.TraversalType.SIBLING;
+
+/**
+ * Represents implementation of YDT walker, which walks the YDT.
+ */
+public class DefaultYdtWalker implements YdtExtendedWalker {
+
+ @Override
+ public void walk(YdtListener ydtListener, YdtContext rootNode) {
+ walkTree(ydtListener, rootNode, false);
+ }
+
+ /**
+ * Walks the YANG data tree till the node provided by the user.
+ * Protocols implements YDT listener and YDT Extended Listener and
+ * walks YDT tree with input as implemented object.
+ * YDT walker provides call backs to implemented methods.
+ *
+ * @param ydtListener YDT listener implemented by the protocol
+ * @param rootNode root node of YDT
+ * @param isExtended flag denotes the call type
+ */
+ private void walkTree(YdtListener ydtListener, YdtContext rootNode,
+ boolean isExtended) {
+ YdtContext curNode = rootNode;
+ TraversalType curTraversal = ROOT;
+
+ while (curNode != null) {
+ if (curTraversal != PARENT) {
+
+ // Visit (curNode) for entry callback
+ if (isExtended) {
+ ((YdtExtendedListener) ydtListener)
+ .enterYdtNode((YdtExtendedContext) curNode);
+ } else {
+ ydtListener.enterYdtNode(curNode);
+ }
+ }
+ if (curTraversal != PARENT &&
+ curNode.getFirstChild() != null) {
+ curTraversal = CHILD;
+ curNode = curNode.getFirstChild();
+ } else if (curNode.getNextSibling() != null) {
+ // Revisit (curNode) for exit callback
+ exitCallBack(ydtListener, curNode, isExtended);
+
+ /*
+ *Stop traversing the tree , tree need to be traversed
+ * till user requested node
+ */
+ if (curNode.equals(rootNode)) {
+ return;
+ }
+ curTraversal = SIBLING;
+ curNode = curNode.getNextSibling();
+ } else {
+ // Revisit (curNode) for exit callback
+ exitCallBack(ydtListener, curNode, isExtended);
+
+ /*
+ *Stop traversing the tree , tree need to be traversed
+ * till user requested node
+ */
+ if (curNode.equals(rootNode)) {
+ return;
+ }
+
+ curTraversal = PARENT;
+ curNode = curNode.getParent();
+ }
+ }
+ }
+
+ /**
+ * Provides exit call back per node on the basis of extended flag,
+ * If isExtended set then YdtExtendedListener exit node call back will
+ * be provided else YdtListener with respective type of context
+ * (YdtContext/YdtExtendedContext).
+ *
+ * @param ydtListener YDT listener implemented by the protocol
+ * @param curNode current node of YDT
+ * @param isExtended flag denotes the call type
+ */
+ private void exitCallBack(YdtListener ydtListener, YdtContext curNode,
+ boolean isExtended) {
+ if (isExtended) {
+ ((YdtExtendedListener) ydtListener)
+ .exitYdtNode((YdtExtendedContext) curNode);
+ } else {
+ ydtListener.exitYdtNode(curNode);
+ }
+ }
+
+ @Override
+ public void walk(YdtExtendedListener ydtExtendedListener,
+ YdtExtendedContext rootNode) {
+ walkTree(ydtExtendedListener, rootNode, true);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/ModuleSchemaData.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/ModuleSchemaData.java
new file mode 100644
index 0000000..fd4f1b6
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/ModuleSchemaData.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yms.app.ydt.exceptions.YdtException;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Manages the application information required for schema nodes defined in
+ * the module (sub-module).
+ */
+public class ModuleSchemaData implements AppData {
+
+ private static final String E_NOT_MAINTAINED =
+ "Augmented info is not maintained.";
+
+ /*
+ * Reference for application's root ydtContext.
+ */
+ private YdtContext moduleContext;
+
+ /*
+ * Reference for list of nodes with operation type delete.
+ */
+ private List<YdtContext> deleteNodes = new ArrayList<>();
+
+ @Override
+ public List<YdtContext> getDeleteNodes() {
+ // This suppose to be mutable for YAB
+ return deleteNodes;
+ }
+
+ @Override
+ public void addDeleteNodes(YdtContext deletedNode) {
+ deleteNodes.add(deletedNode);
+ }
+
+ @Override
+ public YdtContext getModuleContext() {
+ return moduleContext;
+ }
+
+ @Override
+ public void setModuleContext(YdtContext moduleContext) {
+ this.moduleContext = moduleContext;
+ }
+
+ @Override
+ public YangSchemaNode getAugmentingSchemaNode() {
+ throw new YdtException(E_NOT_MAINTAINED);
+ }
+
+ @Override
+ public void setAugmentingSchemaNode(YangSchemaNode schemaNode) {
+ throw new YdtException(E_NOT_MAINTAINED);
+ }
+
+ @Override
+ public YangSchemaNode getSchemaNode() {
+ return ((YdtExtendedContext) moduleContext).getYangSchemaNode();
+ }
+
+ @Override
+ public YangSchemaNode getRootSchemaNode() {
+ return getSchemaNode();
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCallType.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCallType.java
new file mode 100644
index 0000000..ace971b
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCallType.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+/**
+ * Represents type of YANG data tree creation method caller type.
+ */
+enum RequestedCallType {
+
+ /**
+ * Requested Node is of type single/multi instance leaf.
+ */
+ LEAF,
+
+ /**
+ * Requested Node is of type single/multi instance node.
+ */
+ OTHER,
+
+ /**
+ * Requested Node is of type multi instance leaf/node.
+ */
+ MULTI_INSTANCE,
+}
+
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCardinality.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCardinality.java
new file mode 100644
index 0000000..ed16951
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/RequestedCardinality.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+/**
+ * Represents type of YANG data tree node operation.
+ */
+enum RequestedCardinality {
+
+ /**
+ * Single instance of requested node.
+ */
+ SINGLE_INSTANCE,
+
+ /**
+ * Multi instance of requested node.
+ */
+ MULTI_INSTANCE,
+
+ /**
+ * Instance of requested node/leaf is unknown.
+ */
+ UNKNOWN,
+
+ /**
+ * Single instance of requested leaf.
+ */
+ SINGLE_INSTANCE_LEAF,
+
+ /**
+ * Multi instance of requested leaf.
+ */
+ MULTI_INSTANCE_LEAF
+}
+
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
new file mode 100644
index 0000000..5ae1230
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangRequestWorkBench.java
@@ -0,0 +1,758 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import com.google.common.collect.ImmutableMap;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yms.app.ysr.YangSchemaRegistry;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+import org.onosproject.yms.ydt.YdtType;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_MULTI_INSTANCE_LEAF_NODE;
+import static org.onosproject.yms.app.ydt.AppNodeFactory.getAppContext;
+import static org.onosproject.yms.app.ydt.RequestedCallType.LEAF;
+import static org.onosproject.yms.app.ydt.RequestedCallType.OTHER;
+import static org.onosproject.yms.app.ydt.RequestedCardinality.MULTI_INSTANCE;
+import static org.onosproject.yms.app.ydt.RequestedCardinality.MULTI_INSTANCE_LEAF;
+import static org.onosproject.yms.app.ydt.RequestedCardinality.SINGLE_INSTANCE;
+import static org.onosproject.yms.app.ydt.RequestedCardinality.UNKNOWN;
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+import static org.onosproject.yms.app.ydt.YdtNodeFactory.getAppOpTypeFromYdtOpType;
+import static org.onosproject.yms.ydt.YdtContextOperationType.CREATE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.DELETE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.MERGE;
+import static org.onosproject.yms.ydt.YdtContextOperationType.REMOVE;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_LEAF_VALUE_NODE;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
+
+/**
+ * Represents YANG request work bench which contains all parameters for
+ * request handling and methods to build and obtain YANG data tree
+ * which is data (sub)instance representation, abstract of protocol.
+ */
+public class YangRequestWorkBench implements YdtExtendedBuilder {
+
+ // ydt formatted error string
+ private static final String FMT_NOT_EXIST =
+ "Application with name \"%s\" doesn't exist.";
+ private static final String E_USE_ADDLEAF =
+ "Requested Node should be created using addLeaf interface";
+ private static final String E_MULTI_INS =
+ "Adds an instance of type list or leaf-list node only";
+ private static final String E_CREATE =
+ "Create request is not allowed under delete operation";
+ private static final String E_DEL =
+ "Delete request is not allowed under create operation";
+ private static final String E_INVOKE_PARENT =
+ "Can't invoke get parent at logical root node";
+ private static final String FMT_TOO_FEW =
+ "Too few key parameters in %s. Expected %d; actual %d.";
+ private static final String FMT_TOO_MANY =
+ "Too many key parameters in %s. Expected %d; actual %d.";
+
+ /*
+ * Current node in YANG data tree, kept to maintain the
+ * current context in YDT.
+ */
+ private YdtNode curNode;
+
+ /*
+ * Root node in YANG data tree, kept to maintain the root context in
+ * YDT.
+ */
+ private YdtNode rootNode;
+
+ /*
+ * Current node in YANG data tree, kept to maintain the current context
+ * in ydt application tree.
+ */
+ private YdtAppContext appCurNode;
+
+ /*
+ * Root node in YANG data tree, kept to maintain the root context in ydt
+ * application tree.
+ */
+ private YdtAppContext appRootNode;
+
+ /**
+ * Root Node Tag attribute in YANG data tree, kept to maintain the root
+ * tag attributes in YDT.
+ * <p>
+ * First key param of map represent tagName name of tag attribute.
+ * Second param of map represent tagValue value of tag attribute
+ */
+ private Map<String, String> rootTagAttributeMap;
+
+ /*
+ * YANG schema registry reference.
+ */
+ private YangSchemaRegistry registry = null;
+
+ /*
+ * YMS operation type.
+ */
+ private final YmsOperationType ymsOperationType;
+
+ /*
+ * YDT default operation type.
+ */
+ private YdtContextOperationType ydtDefaultOpType;
+
+ /*
+ * Flag to identify data validation need to be done by YDT or not.
+ */
+ private final boolean validate;
+ // TODO validate need to be handle later with interaction type basis in
+ // future when it will be supported
+
+
+ /**
+ * Creates an instance of YANG request work bench which is use to initialize
+ * logical rootNode and and schema registry.
+ *
+ * @param name name of logical container of a protocol
+ * which is a holder of the complete tree
+ * @param namespace namespace of logical container
+ * @param opType type of operation done by using YANG
+ * interface
+ * @param registry Yang schema registry
+ * @param isValidate Flag to identify data validation need to be
+ * done by YDT or not
+ */
+ public YangRequestWorkBench(String name, String namespace,
+ YmsOperationType opType,
+ YangSchemaRegistry registry,
+ boolean isValidate) {
+ YdtNode newNode;
+ YangSchemaNodeIdentifier nodeIdentifier =
+ new YangSchemaNodeIdentifier();
+ nodeIdentifier.setName(name);
+ nodeIdentifier.setNameSpace(namespace);
+ newNode = new YdtSingleInstanceNode(nodeIdentifier);
+ setRootNode(newNode);
+ this.registry = registry;
+ ymsOperationType = opType;
+ validate = isValidate;
+ // Set the logical root node for yang data app tree.
+ DefaultYdtAppContext appNode = getAppContext(true);
+
+ setAppRootNode(appNode);
+ }
+
+ /**
+ * Sets the logical root context information available in YDT node.
+ *
+ * @param node logical root node
+ */
+ private void setRootNode(YdtNode node) {
+ rootNode = node;
+ curNode = node;
+ }
+
+ /**
+ * Sets the app context tree logical root node for ydt application tree.
+ *
+ * @param node application tree's logical root node
+ */
+ private void setAppRootNode(YdtAppContext node) {
+ appRootNode = node;
+ appCurNode = node;
+ }
+
+ /**
+ * Returns the YANG schema registry of Ydt.
+ * This method will be used by ytb.
+ *
+ * @return YANG schema registry
+ */
+ public YangSchemaRegistry getYangSchemaRegistry() {
+ return registry;
+ }
+
+ /**
+ * Returns the app context tree root node for ydt application tree.
+ * This method will be used by yab.
+ *
+ * @return YdtAppContext refers to root node of ydt application tree
+ */
+ public YdtAppContext getAppRootNode() {
+ return appRootNode;
+ }
+
+ /**
+ * Returns the data tree for given node identifier.
+ *
+ * @param id Represents node identifier of YANG data tree node
+ * @param namespace namespace of the application requested by user
+ * @return YANG data tree node
+ */
+ private YdtNode moduleHandler(YangSchemaNodeIdentifier id,
+ String namespace) {
+
+ YangSchemaNode node = registry
+ .getYangSchemaNodeUsingSchemaName(id.getName());
+
+ if (node == null ||
+ namespace != null && !namespace.equals(node.getNameSpace())) {
+ curNode.errorHandler(errorMsg(
+ FMT_NOT_EXIST, id.getName()), rootNode);
+ }
+
+ YdtNode newNode = new YdtSingleInstanceNode(id);
+ newNode.setYangSchemaNode(node);
+ id.setNameSpace(node.getNameSpace());
+ return newNode;
+ }
+
+ @Override
+ public void setRootTagAttributeMap(Map<String, String> attributeTag) {
+ rootTagAttributeMap = attributeTag;
+ }
+
+ @Override
+ public Map<String, String> getRootTagAttributeMap() {
+ if (rootTagAttributeMap != null) {
+ return ImmutableMap.copyOf(rootTagAttributeMap);
+ }
+ return null;
+ }
+
+ @Override
+ public void addChild(String name, String namespace) {
+ addChild(name, namespace, UNKNOWN, null, OTHER);
+ }
+
+ @Override
+ public void addChild(String name, String namespace, YdtType ydtType) {
+ addChild(name, namespace, ydtType, null);
+ }
+
+ @Override
+ public void addChild(String name, String namespace,
+ YdtContextOperationType opType) {
+ addChild(name, namespace, UNKNOWN, opType, OTHER);
+ }
+
+ @Override
+ public void addChild(String name, String namespace, YdtType ydtType,
+ YdtContextOperationType opType) {
+ RequestedCardinality cardinality = null;
+ switch (ydtType) {
+ case MULTI_INSTANCE_NODE:
+ cardinality = MULTI_INSTANCE;
+ break;
+ case SINGLE_INSTANCE_NODE:
+ cardinality = SINGLE_INSTANCE;
+ break;
+ default:
+ curNode.errorHandler(E_USE_ADDLEAF, rootNode);
+ }
+ addChild(name, namespace, cardinality, opType, OTHER);
+ }
+
+ /**
+ * Adds a last child to YANG data tree; this method is to be used by all
+ * protocols internally which are aware or unaware of the nature
+ * (single/multiple) of node.
+ *
+ * @param name name of child to be added
+ * @param namespace namespace of child to be added
+ * @param cardinality type of YANG data tree node operation
+ * @param opType type of requested operation over a node
+ * @param callType to identify the whether its a leaf or other node
+ */
+ private void addChild(String name, String namespace,
+ RequestedCardinality cardinality,
+ YdtContextOperationType opType,
+ RequestedCallType callType) {
+
+ YdtNode childNode;
+ boolean isContextSwitch = false;
+ YangSchemaNode schemaNode = null;
+ YangSchemaNodeContextInfo contextInfo;
+ YangSchemaNode augmentingSchema = null;
+
+ YangSchemaNodeIdentifier id = new YangSchemaNodeIdentifier();
+ id.setName(name);
+
+ // Module/sub-module node handler.
+ if (curNode.equals(rootNode)) {
+ childNode = moduleHandler(id, namespace);
+ } else {
+
+ // If namespace given by user null, then take namespace from parent.
+ if (namespace == null) {
+ namespace = curNode.getYdtNodeIdentifier().getNameSpace();
+ }
+
+ id.setNameSpace(namespace);
+
+ /*
+ * Get the already exiting YDT node in YDT tree with same
+ * nodeIdentifier
+ */
+ childNode = curNode.getCollidingChild(id);
+
+ /*
+ * If colliding child doesn't exist ,
+ * then query yang data model for schema of given node.
+ */
+ if (childNode == null) {
+ /*
+ * Get Yang Schema node context info which is having
+ * YangSchemaNode and ContextSwitchedNode.
+ */
+ contextInfo = curNode.getSchemaNodeContextInfo(id);
+
+ if (contextInfo.getContextSwitchedNode() != null) {
+ augmentingSchema = appCurNode.getAugmentingSchemaNode(
+ id, contextInfo);
+ if (augmentingSchema != null) {
+ /*
+ * As two tree(YDT and YDT Application Tree) are getting
+ * prepared in parallel, So setting context switch
+ * flag it will help ydt to keep the track whether
+ * ydtApp tree also need to be traversed back to parent
+ * or not with YDT tree traverse to parent call.
+ */
+ isContextSwitch = true;
+ }
+ }
+ schemaNode = contextInfo.getSchemaNode();
+ } else {
+ /*
+ * If colliding child exist , then will be leaf-list or list
+ * If its leaf-list then return and add new requested
+ * value/valueSet in same node else take yang data model
+ * information from colliding child.
+ */
+ if (childNode.getYdtType() == MULTI_INSTANCE_LEAF_VALUE_NODE) {
+ curNode = childNode;
+ return;
+ }
+ schemaNode = childNode.getYangSchemaNode();
+ }
+ childNode = YdtNodeFactory.getNode(id, schemaNode, cardinality,
+ callType);
+ }
+
+ opType = getValidOpType(opType, callType, schemaNode);
+
+ childNode.setYdtContextOperationType(opType);
+
+ curNode.addChild(childNode, true);
+
+ // Update parent ydt node map.
+ curNode.updateYdtMap(id, childNode);
+
+ processAppTree(opType, childNode, augmentingSchema, isContextSwitch);
+
+ // Updating the curNode.
+ curNode = childNode;
+ }
+
+ /**
+ * Processes application tree on the bases of requested ydt node.
+ *
+ * @param opType user requested operation type
+ * @param childNode requested ydt node
+ * @param augmentingSchema schema of last augmenting node
+ * @param isContextSwitch true, for module node call; false for modules
+ * sub-node calls
+ */
+ private void processAppTree(
+ YdtContextOperationType opType, YdtNode childNode,
+ YangSchemaNode augmentingSchema, boolean isContextSwitch) {
+
+ if (augmentingSchema != null) {
+ if (!appCurNode.addSchemaToAppSet(augmentingSchema)) {
+ return;
+ }
+ }
+ if (opType == null) {
+ opType = curNode.getYdtContextOperationType();
+ } else {
+ // Updating operation type for parent nodes
+ appCurNode.updateAppOperationType(opType);
+ }
+
+ /*
+ * Create entry of module node in ydt app tree.
+ * Or if context switch happened then also add entry for same ydt
+ * node in the ydt application tree.
+ */
+ if (curNode.equals(rootNode) || isContextSwitch) {
+ addChildInAppTree(childNode, augmentingSchema, opType,
+ isContextSwitch);
+
+ // Setting app tree node operation.
+ appCurNode.setOperationType(getAppOpTypeFromYdtOpType(opType));
+ }
+
+ // Updating the delete operation list in app tree.
+ if (opType == DELETE || opType == REMOVE) {
+ appCurNode.addDeleteNode(childNode);
+ }
+ }
+
+ /**
+ * Returns the valid operation type for requested ydt node after performing
+ * validation.
+ *
+ * @param opType user requested operation type
+ * @param callType to identify the whether its a leaf or other node
+ * @param schemaNode schema node of user requested ydt node
+ * @return operation type
+ */
+ private YdtContextOperationType getValidOpType(
+ YdtContextOperationType opType, RequestedCallType callType,
+ YangSchemaNode schemaNode) {
+
+ // Operation type not supported for leaf node.
+ if (callType == LEAF || (callType == RequestedCallType.MULTI_INSTANCE &&
+ schemaNode.getYangSchemaNodeType() ==
+ YANG_MULTI_INSTANCE_LEAF_NODE)) {
+ return null;
+ }
+
+ // Reference for parent node operation type.
+ YdtContextOperationType parentOpType = curNode
+ .getYdtContextOperationType();
+
+ if (opType != null && parentOpType != null) {
+ validateOperationType(parentOpType, opType);
+ } else if (opType == null) {
+ opType = getOperationType(parentOpType);
+ }
+ return opType;
+ }
+
+ /**
+ * Returns the operation type for non leaf node.
+ * When "operation" attribute for current node is not specified or null,
+ * then the operation applied to the parent data node of the
+ * configuration is used. If no parent data node is available,
+ * then the default-operation'value is used.
+ * If default operation type is not set, merge will be taken as default
+ * operation type.
+ *
+ * @param parentOpType operation type of parent node
+ * @return operation type for current non leaf node
+ */
+ private YdtContextOperationType getOperationType(
+ YdtContextOperationType parentOpType) {
+
+ return parentOpType != null ? parentOpType :
+ (ydtDefaultOpType != null ? ydtDefaultOpType : MERGE);
+ }
+
+ /**
+ * Adds a last child to YANG app data tree.this method is to be used
+ * internally by other ydt interfaces.
+ *
+ * @param childNode node to be added in tree
+ * @param schemaNode last augmenting module node
+ * @param childOpType operation type of node
+ * @param isContextSwitch true, for module node call; false for modules
+ * sub-node calls
+ */
+ private void addChildInAppTree(YdtNode childNode,
+ YangSchemaNode schemaNode,
+ YdtContextOperationType childOpType,
+ boolean isContextSwitch) {
+
+ YdtAppNodeOperationType opType;
+
+ DefaultYdtAppContext appContext = getAppContext(isContextSwitch);
+
+ // Add context switched child in ydt App tree.
+ appCurNode.addChild(appContext);
+ //Updating the curNode.
+ appCurNode = appContext;
+
+ // Get the app tree operation type from ydt operation type.
+ opType = getAppOpTypeFromYdtOpType(childOpType);
+
+ appCurNode.setAppData(childNode, schemaNode);
+
+ appCurNode.setOperationType(opType);
+
+ childNode.setAppContextSwitch();
+ }
+
+ /**
+ * Validates the various combination of operation type.
+ *
+ * @param parentOpType Reference for parent node operation type
+ * @param childOpType type of YANG data tree node operation
+ */
+ private void validateOperationType(YdtContextOperationType parentOpType,
+ YdtContextOperationType childOpType) {
+
+ switch (parentOpType) {
+ case CREATE:
+ // Inside the create operation delete operation should not come.
+ if (childOpType == DELETE) {
+ curNode.errorHandler(E_CREATE, rootNode);
+ }
+ break;
+ case DELETE:
+ // Inside the delete operation create operation should not come.
+ if (childOpType == CREATE) {
+ curNode.errorHandler(E_DEL, rootNode);
+ }
+ break;
+ default:
+ //TODO check all possible scenario.
+ }
+ }
+
+ @Override
+ public void addLeaf(String name, String namespace, String value) {
+ addLeaf(name, namespace, value, null, UNKNOWN);
+ }
+
+ @Override
+ public void addLeaf(String name, String namespace, Set<String> valueSet) {
+ addLeaf(name, namespace, null, valueSet, MULTI_INSTANCE_LEAF);
+ }
+
+ /**
+ * Adds a last leaf with list of values/single value to YANG data tree.
+ * This method is used by all protocols which knows the nature
+ * (single/multiple) or not.
+ * Value of leaf can be null which indicates selection node in get
+ * operation.
+ *
+ * @param name name of child to be added
+ * @param namespace namespace of child to be added, if it's
+ * null, parent's
+ * namespace will be applied to child
+ * @param value value of the child
+ * @param valueSet list of value of the child
+ * @param cardinality type of YANG data tree node operation
+ */
+ private void addLeaf(String name, String namespace, String value,
+ Set<String> valueSet,
+ RequestedCardinality cardinality) {
+ addChild(name, namespace, cardinality, null, LEAF);
+
+ // After successful addition of child node updating the values in same.
+ if (value != null) {
+ curNode.addValue(value);
+ } else if (valueSet != null) {
+ curNode.addValueSet(valueSet);
+ }
+ }
+
+ @Override
+ public void traverseToParent() {
+ // If traverse back to parent for logical root node comes
+ if (curNode.equals(rootNode)) {
+ curNode.errorHandler(E_INVOKE_PARENT, rootNode);
+ }
+
+ // If node is of multiInstanceNode type then check key uniqueness.
+ if (curNode.getYdtType() == MULTI_INSTANCE_NODE) {
+ curNode.createKeyNodeList();
+ }
+
+ /*
+ * Check application switch for curNode if set,
+ * then traverseToParent in YDT application tree.
+ */
+ if (curNode.getParent().equals(rootNode) ||
+ curNode.getAppContextSwitch()) {
+ traverseToAppTreeParent();
+ }
+
+ /*
+ * Validate all multi Instance inside current context,
+ * This is not valid for leaf and leaf-list node.
+ */
+ if (curNode instanceof YdtMultiInstanceNode ||
+ curNode instanceof YdtSingleInstanceNode) {
+ curNode.validateMultiInstanceNode();
+ }
+
+ curNode = curNode.getParent();
+ }
+
+ /**
+ * Traverses up in YANG application tree to the parent node,
+ * This will be used when Ydt current context switch flag is set.
+ */
+ private void traverseToAppTreeParent() {
+ appCurNode = appCurNode.getParent();
+ }
+
+ @Override
+ public YdtContext getCurNode() {
+ return curNode;
+ }
+
+ @Override
+ public void setDefaultEditOperationType(
+ YdtContextOperationType opType) {
+ ydtDefaultOpType = opType;
+ }
+
+ @Override
+ public YdtExtendedContext getRootNode() {
+ return rootNode;
+ }
+
+ @Override
+ public YmsOperationType getYmsOperationType() {
+ return ymsOperationType;
+ }
+
+ @Override
+ public void addMultiInstanceChild(String name, String namespace,
+ List<String> keysValueList,
+ YdtContextOperationType opType) {
+ addChild(name, namespace, UNKNOWN, opType,
+ RequestedCallType.MULTI_INSTANCE);
+ int inputCount = keysValueList.size();
+ int expectedCount;
+ if (curNode.getYdtType() == MULTI_INSTANCE_LEAF_VALUE_NODE) {
+ // After successful addition of child node updating
+ // the values in same.
+ // inputCount = curNode.getValueSet().size() + inputCount;
+ // checkElementCount(expectedCount, inputCount);
+ // TODO check the element count
+ for (String value : keysValueList) {
+ curNode.addValue(value);
+ }
+ } else if (curNode.getYdtType() == MULTI_INSTANCE_NODE) {
+ YangList yangListHolder = (YangList) curNode.getYangSchemaNode();
+ List<String> schemaKeyList = yangListHolder.getKeyList();
+ expectedCount = schemaKeyList.size();
+ checkElementCount(name, expectedCount, inputCount);
+
+ Iterator<String> sklIter = schemaKeyList.iterator();
+ Iterator<String> kvlIter = keysValueList.iterator();
+ String keyEleName;
+ while (kvlIter.hasNext()) {
+ String value = kvlIter.next();
+ keyEleName = sklIter.next();
+ addLeaf(keyEleName, namespace, value);
+ if (kvlIter.hasNext()) {
+ traverseToParentWithoutValidation();
+ }
+ }
+ curNode = curNode.getParent();
+ } else {
+ curNode.errorHandler(E_MULTI_INS, rootNode);
+ }
+ }
+
+ /**
+ * Checks the user supplied list of argument match's the expected value
+ * or not.
+ *
+ * @param name name of the parent list/leaf-list node
+ * @param expected count suppose to be
+ * @param actual user supplied values count
+ */
+ private void checkElementCount(String name, int expected,
+ int actual) {
+ if (expected < actual) {
+ curNode.errorHandler(errorMsg(FMT_TOO_MANY, name, expected, actual),
+ rootNode);
+ } else if (expected > actual) {
+ curNode.errorHandler(errorMsg(FMT_TOO_FEW, name, expected, actual),
+ rootNode);
+ }
+ }
+
+ /**
+ * Adds a last child to YANG data tree, this method is to be used by
+ * YANG object builder sub-calls internally.
+ *
+ * @param opType type of requested operation over a node
+ * @return returns added ydt node in YDT tree
+ */
+ private YdtNode addExtendedChildNode(YdtContextOperationType opType,
+ YangSchemaNode schemaNode) {
+
+ YdtNode childNode;
+ YangSchemaNodeIdentifier id =
+ schemaNode.getYangSchemaNodeIdentifier();
+
+ childNode = YdtNodeFactory
+ .getYangSchemaNodeTypeSpecificContext(
+ id, schemaNode.getYangSchemaNodeType());
+
+ childNode.setId(id);
+
+ childNode.setYangSchemaNode(schemaNode);
+
+ childNode.setYdtContextOperationType(opType);
+
+ curNode.addChild(childNode, true);
+
+ curNode = childNode;
+
+ return childNode;
+ }
+
+ @Override
+ public YdtExtendedContext addChild(YdtContextOperationType opType,
+ YangSchemaNode schemaNode) {
+ return addExtendedChildNode(opType, schemaNode);
+ }
+
+ @Override
+ public YdtExtendedContext addLeafList(Set<String> valueSet,
+ YangSchemaNode schemaNode) {
+ YdtNode childNode = addExtendedChildNode(null, schemaNode);
+
+ // After successful addition of child node updating the values in same.
+ childNode.addValueSetWithoutValidation(valueSet);
+ return childNode;
+ }
+
+ @Override
+ public YdtExtendedContext addLeaf(String value,
+ YangSchemaNode schemaNode) {
+ YdtNode childNode = addExtendedChildNode(null, schemaNode);
+
+ // After successful addition of child node updating the values in same.
+ childNode.addValueWithoutValidation(value);
+ return childNode;
+ }
+
+ @Override
+ public void traverseToParentWithoutValidation() {
+ // If traverse back to parent for logical root node comes
+ if (curNode.equals(rootNode)) {
+ curNode.errorHandler(E_INVOKE_PARENT, rootNode);
+ }
+ curNode = curNode.getParent();
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangResponseWorkBench.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangResponseWorkBench.java
new file mode 100644
index 0000000..99342d7
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YangResponseWorkBench.java
@@ -0,0 +1,98 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtResponse;
+import org.onosproject.yms.ydt.YmsOperationExecutionStatus;
+import org.onosproject.yms.ydt.YmsOperationType;
+
+public class YangResponseWorkBench implements YdtResponse {
+
+ /*
+ * YDT root node context.
+ */
+ private YdtContext rootNode;
+
+ /*
+ * YMS operation execution status.
+ */
+ private YmsOperationExecutionStatus status;
+
+ /*
+ * YMS operation type.
+ */
+ private YmsOperationType ymsOperationType;
+
+ /**
+ * Creates an instance of YangResponseWorkBench which is use to
+ * initialize rootNode and childNode.
+ *
+ * @param ydtContext root node context
+ * @param exeStatus YMS operation execution status
+ * @param opType YMS operation type
+ */
+ public YangResponseWorkBench(YdtContext ydtContext,
+ YmsOperationExecutionStatus exeStatus,
+ YmsOperationType opType) {
+ rootNode = ydtContext;
+ status = exeStatus;
+ ymsOperationType = opType;
+ }
+
+ @Override
+ public YmsOperationExecutionStatus getYmsOperationResult() {
+ return status;
+ }
+
+ @Override
+ public YdtContext getRootNode() {
+ return rootNode;
+ }
+
+ @Override
+ public YmsOperationType getYmsOperationType() {
+ return ymsOperationType;
+ }
+
+ /**
+ * Sets root node.
+ *
+ * @param rootNode root node
+ */
+ public void setRootNode(YdtContext rootNode) {
+ this.rootNode = rootNode;
+ }
+
+ /**
+ * Sets YMS operation execution status.
+ *
+ * @param status YMS operation execution status
+ */
+ public void setStatus(YmsOperationExecutionStatus status) {
+ this.status = status;
+ }
+
+ /**
+ * Sets YMS operation type.
+ *
+ * @param ymsOperationType YMS operation type
+ */
+ public void setYmsOperationType(YmsOperationType ymsOperationType) {
+ this.ymsOperationType = ymsOperationType;
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppContext.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppContext.java
new file mode 100644
index 0000000..c845221
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppContext.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.util.List;
+
+/**
+ * Abstraction of an entity which represents YANG application data tree context
+ * information. This context information will be used by protocol to obtain
+ * the information associated with YDT application node. This is used when
+ * protocol is walking the application data tree in both visitor and listener
+ * mechanism.
+ */
+public interface YdtAppContext {
+
+ /**
+ * Returns the context of parent node.
+ *
+ * @return context of parent node
+ */
+ YdtAppContext getParent();
+
+ /**
+ * Sets the context of parent node.
+ *
+ * @param parent node
+ */
+ void setParent(YdtAppContext parent);
+
+ /**
+ * Returns the context of first child.
+ *
+ * @return context of first child
+ */
+ YdtAppContext getFirstChild();
+
+ /**
+ * Sets the context of first child.
+ *
+ * @param child node
+ */
+ void setChild(YdtAppContext child);
+
+ /**
+ * Returns the context of last child.
+ *
+ * @return context of last child
+ */
+ YdtAppContext getLastChild();
+
+ /**
+ * Sets the context of last child.
+ *
+ * @param child node
+ */
+ void setLastChild(YdtAppContext child);
+
+ /**
+ * Returns the context of next sibling.
+ *
+ * @return context of next sibling
+ */
+ YdtAppContext getNextSibling();
+
+ /**
+ * Sets the context of next sibling.
+ *
+ * @param nextSibling node
+ */
+ void setNextSibling(YdtAppContext nextSibling);
+
+ /**
+ * Returns the context of previous sibling.
+ *
+ * @return context of previous sibling
+ */
+ YdtAppContext getPreviousSibling();
+
+ /**
+ * Sets the context of previous sibling.
+ *
+ * @param preSibling node
+ */
+ void setPreviousSibling(YdtAppContext preSibling);
+
+ /**
+ * Returns the app tree operation type.
+ *
+ * @return app tree operation type
+ */
+ YdtAppNodeOperationType getOperationType();
+
+ /**
+ * Set the app tree operation type.
+ *
+ * @param opType app tree operation type
+ */
+ void setOperationType(YdtAppNodeOperationType opType);
+
+ /**
+ * Returns the list of nodes with operation type delete.
+ *
+ * @return list of nodes with operation type delete
+ */
+ List<YdtContext> getDeleteNodes();
+
+ /**
+ * Adds the ydt node with operation type delete in module delete node list.
+ *
+ * @param node ydt node with operation type delete/remove
+ */
+ void addDeleteNode(YdtNode node);
+
+ /**
+ * Returns application's root ydtContext.
+ *
+ * @return YdtContext of application root node
+ */
+ YdtContext getModuleContext();
+
+ /**
+ * Sets the application's ydtContext.
+ *
+ * @param moduleNode application's ydtContext
+ */
+ void setModuleContext(YdtContext moduleNode);
+
+ /**
+ * Returns the YangSchemaNode of augmenting application.
+ *
+ * @return YangSchemaNode of augmenting application
+ */
+ YangSchemaNode getAugmentingSchemaNode();
+
+ /**
+ * Sets the YangSchemaNode of augmenting application root node.
+ *
+ * @param schemaNode YangSchemaNode of augmenting application module
+ */
+ void setAugmentingSchemaNode(YangSchemaNode schemaNode);
+
+ /**
+ * Adds a last child to ydt application data tree.
+ *
+ * @param newChild name of child to be added
+ */
+ void addChild(YdtAppContext newChild);
+
+ /**
+ * Returns augmenting node module yang schema node.
+ *
+ * @param id schema node identifier
+ * @param contextInfo Yang Schema node context info
+ * which is having YangSchemaNode and
+ * ContextSwitchedNode
+ * @return augmenting node module yang schema node
+ */
+ YangSchemaNode getAugmentingSchemaNode(
+ YangSchemaNodeIdentifier id,
+ YangSchemaNodeContextInfo contextInfo);
+
+ /**
+ * Updates the app tree operation type.
+ * <p>
+ * If earlier operation type was OTHER_EDIT and now operation type came as
+ * DELETE_ONLY or vice-versa, then update operation type to BOTH.
+ *
+ * @param opType ydt current context operation type
+ */
+ void updateAppOperationType(YdtContextOperationType opType);
+
+ /**
+ * Sets the application data for given request. If in requested parameters
+ * schemaNode is not null then appData will be set with
+ * augmentedSchemaData else with moduleSchemaData object.
+ *
+ * @param moduleNode module node of requested app
+ * @param schemaNode augmented schema node of requested context
+ */
+ void setAppData(YdtNode moduleNode, YangSchemaNode schemaNode);
+
+ /**
+ * Returns the app data for current context.
+ *
+ * @return app data
+ */
+ AppData getAppData();
+
+ /**
+ * Returns the yang schema for requested node.
+ *
+ * @return schema node
+ */
+ YangSchemaNode getYangSchemaNode();
+
+ /**
+ * Adds the given schema node in to application set.
+ *
+ * @param schemaNode schema node to be added
+ * @return true for success; false otherwise
+ */
+ boolean addSchemaToAppSet(YangSchemaNode schemaNode);
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppNodeOperationType.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppNodeOperationType.java
new file mode 100644
index 0000000..4880edc
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtAppNodeOperationType.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+/**
+ * Represents type of YANG data tree node operation.
+ */
+public enum YdtAppNodeOperationType {
+
+ /**
+ * Type of YANG application node operation for below action:
+ * The application containing this attribute has edit operation
+ * type as delete/remove in its complete ydtTree.
+ */
+ DELETE_ONLY,
+
+ /**
+ * Type of YANG application node operation for below action:
+ * The application containing this attribute has edit operation
+ * type other than delete/remove in its complete ydtTree.
+ */
+ OTHER_EDIT,
+
+ /**
+ * Type of YANG application node operation for below action:
+ * The application containing this attribute has edit operation
+ * type of combination of any edit operation type in its complete ydtTree.
+ */
+ BOTH
+}
+
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtConstants.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtConstants.java
new file mode 100644
index 0000000..2063093
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtConstants.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+/**
+ * Represents common constant utility for YANG data tree.
+ */
+final class YdtConstants {
+
+ //No instantiation.
+ private YdtConstants() {
+ }
+
+ /**
+ * Error formatting string for duplicate entries found in ydt.
+ */
+ public static final String FMT_DUP_ENTRY = "Duplicate entry with name %s.";
+
+ /**
+ * Returns the error string by filling the parameters in the given
+ * formatted error string.
+ *
+ * @param fmt error format string
+ * @param params parameters to be filled in formatted string
+ * @return error string
+ */
+ public static String errorMsg(String fmt, Object... params) {
+ return String.format(fmt, params);
+ }
+}
\ No newline at end of file
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedBuilder.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedBuilder.java
new file mode 100644
index 0000000..ea9c9f3d
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedBuilder.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yms.ydt.YdtBuilder;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import java.util.Set;
+
+/**
+ * Abstraction of an entity which represents extension of YDT builder
+ * required by internal sub modules.
+ */
+public interface YdtExtendedBuilder extends YdtBuilder {
+
+ /**
+ * Adds a last child to YANG data tree; this method is to be used by
+ * YANG object builder.
+ *
+ * @param yangSchemaNode schema node from YANG metadata
+ * @param opType type of requested operation over a node
+ * @return YDT context
+ */
+ YdtExtendedContext addChild(YdtContextOperationType opType,
+ YangSchemaNode yangSchemaNode);
+
+ /**
+ * Adds a last leaf list to YANG data tree; this method is to be used by
+ * YANG object builder.
+ *
+ * @param valueSet list of value of the child
+ * @param yangSchemaNode schema node from YANG metadata
+ * @return YDT context
+ */
+ YdtExtendedContext addLeafList(Set<String> valueSet,
+ YangSchemaNode yangSchemaNode);
+
+ /**
+ * Adds a last leaf to YANG data tree; this method is to be used by
+ * YANG object builder.
+ *
+ * @param value value of the child
+ * @param yangSchemaNode schema node from YANG metadata
+ * @return YDT context
+ */
+ YdtExtendedContext addLeaf(String value, YangSchemaNode yangSchemaNode);
+
+ /**
+ * Traverses up in YANG data tree to the parent node, it is to be used when
+ * protocol is using extended context type and wanted to traverse
+ * up the tree without doing any validation.
+ */
+ void traverseToParentWithoutValidation();
+
+ @Override
+ YdtExtendedContext getRootNode();
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedContext.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedContext.java
new file mode 100644
index 0000000..3668de8
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedContext.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+/**
+ * Abstraction of an entity which represents application related information
+ * maintained in YDT.
+ */
+public interface YdtExtendedContext extends YdtContext {
+
+ /**
+ * Returns the application stored information. Application type is used to
+ * identify application.
+ *
+ * @param appType application type
+ * @return application information
+ */
+ Object getAppInfo(AppType appType);
+
+ /**
+ * Sets application stored information. Application type is used to
+ * identify application.
+ *
+ * @param appType application type
+ * @param object application information object
+ */
+ void addAppInfo(AppType appType, Object object);
+
+ /**
+ * Returns child schema node context information. It is used by YMS to
+ * obtain the child schema corresponding to data node identifier.
+ *
+ * @param id represents a identifier of YANG data tree node
+ * @return YANG data node context information
+ */
+ YangSchemaNodeContextInfo getSchemaNodeContextInfo(
+ YangSchemaNodeIdentifier id);
+
+ /**
+ * Returns schema node from data model for curNode.
+ *
+ * @return yang schema node
+ */
+ YangSchemaNode getYangSchemaNode();
+
+ /**
+ * Returns YDT current extended context operation type.
+ *
+ * @return operation type
+ */
+ YdtContextOperationType getYdtContextOperationType();
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedListener.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedListener.java
new file mode 100644
index 0000000..333f3ef
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedListener.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+
+import org.onosproject.yms.ydt.YdtListener;
+
+/**
+ * Abstraction of an entity which provide call back methods which are called
+ * by YDT extended walker while walking the YANG data tree.
+ * <p>
+ * This interface needs to be implemented by protocol implementing listener's
+ * based call backs while YDT walk, and update application specific information
+ * in data node.
+ */
+public interface YdtExtendedListener extends YdtListener {
+
+ /**
+ * YANG data tree node's entry, it will be called during a node entry.
+ * <p>
+ * All the related information about the node can be obtain from the YDT
+ * context. Also it can be used to maintain / query application specific
+ * information.
+ *
+ * @param ydtExtendedContext YANG data tree context
+ */
+ void enterYdtNode(YdtExtendedContext ydtExtendedContext);
+
+ /**
+ * YANG data tree node's exit, it will be called during a node exit.
+ * <p>
+ * All the related information about the node can be obtain from the YDT
+ * context. Also it can be used to maintain / query application specific
+ * information.
+ *
+ * @param ydtExtendedContext YANG data tree context
+ */
+ void exitYdtNode(YdtExtendedContext ydtExtendedContext);
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedWalker.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedWalker.java
new file mode 100644
index 0000000..f3bfea3
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtExtendedWalker.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yms.ydt.YdtWalker;
+
+/**
+ * Abstraction of an entity which provides interfaces for YDT extended walker.
+ */
+public interface YdtExtendedWalker extends YdtWalker {
+
+ /**
+ * Walks the YANG data tree. Protocols implements YDT listener service and
+ * walks YDT tree with input as implemented object.
+ * YDT walker provides call backs to implemented methods.
+ *
+ * @param ydtListener YDT listener implemented by the protocol
+ * @param rootNode root node of YDT
+ */
+ void walk(YdtExtendedListener ydtListener, YdtExtendedContext rootNode);
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceLeafNode.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceLeafNode.java
new file mode 100644
index 0000000..955852d
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceLeafNode.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import com.google.common.collect.ImmutableSet;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_LEAF_VALUE_NODE;
+
+/**
+ * Represents YDT multi instance leaf node which can hold multiple values, it
+ * is atomic element and doesn't have any child.
+ */
+class YdtMultiInstanceLeafNode extends YdtNode {
+
+ // ydt formatted error string
+ private static final String FMT_DUP_ENTRY =
+ "Duplicate entry found under %s leaf-list node.";
+
+ /**
+ * Set of values.
+ */
+ private final Set<String> valueSet = new HashSet<>();
+
+ /**
+ * Creates a YANG multi instance leaf node.
+ *
+ * @param id node identifier of YDT multi instance node
+ */
+ protected YdtMultiInstanceLeafNode(YangSchemaNodeIdentifier id) {
+ super(MULTI_INSTANCE_LEAF_VALUE_NODE, id);
+ }
+
+ @Override
+ public Set<String> getValueSet() {
+ return ImmutableSet.copyOf(valueSet);
+ }
+
+ @Override
+ public void addValue(String value) {
+ // check the value against corresponding data-type.
+ try {
+ getYangSchemaNode().isValueValid(value);
+ } catch (Exception e) {
+ errorHandler(e.getLocalizedMessage(), this);
+ }
+ addValueToValueSet(value);
+ }
+
+ /**
+ * Adds value in the current node valueSet, after successful validation of
+ * the value.
+ *
+ * @param value value to be added
+ */
+ private void addValueToValueSet(String value) {
+
+ if (!valueSet.add(value)) {
+ errorHandler(errorMsg(FMT_DUP_ENTRY,
+ getYdtNodeIdentifier().getName()), this);
+ }
+ }
+
+ @Override
+ public void addValueSet(Set valueSet) {
+ String value = null;
+ // Check the value against corresponding data-type.
+ for (Object aValueSet : valueSet) {
+
+ try {
+ value = String.valueOf(aValueSet);
+ getYangSchemaNode().isValueValid(value);
+ } catch (DataModelException e) {
+ errorHandler(e.getLocalizedMessage(), this);
+ }
+ addValueToValueSet(value);
+ }
+ }
+
+ @Override
+ public void addValueWithoutValidation(String value) {
+ valueSet.add(value);
+ }
+
+ @Override
+ public void addValueSetWithoutValidation(Set valueSet) {
+ this.valueSet.clear();
+ this.valueSet.addAll(valueSet);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceNode.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceNode.java
new file mode 100644
index 0000000..a24772b
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtMultiInstanceNode.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import com.google.common.collect.ImmutableList;
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yms.ydt.YdtContext;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+import static org.onosproject.yms.ydt.YdtType.MULTI_INSTANCE_NODE;
+
+
+/**
+ * Represents a multi instance node in YANG data tree.
+ */
+public class YdtMultiInstanceNode extends YdtNode {
+
+ // ydt formatted error string
+ private static final String FMT_MISSING_KEY =
+ "%s is missing some of the keys of %s.";
+
+ /*
+ * Reference for list of key element's ydtContext.
+ */
+ private List<YdtContext> keyNodeList = new ArrayList<>();
+
+ /*
+ * Reference for composite key string for multi Instance Node..
+ */
+ private String compositeKey;
+
+ /**
+ * Creates a YANG multi instance node object.
+ *
+ * @param id node identifier of YDT multi instance node .
+ */
+ protected YdtMultiInstanceNode(YangSchemaNodeIdentifier id) {
+ super(MULTI_INSTANCE_NODE, id);
+ }
+
+ /**
+ * Returns the composite key string for current multi instance node.
+ *
+ * @return composite key string
+ */
+ public String getCompositeKey() {
+ return compositeKey;
+ }
+
+ /**
+ * Returns the list of key element's ydtContext.
+ *
+ * @return list of key element's ydtContext
+ */
+ public List<YdtContext> getKeyNodeList() {
+ return ImmutableList.copyOf(keyNodeList);
+ }
+
+ @Override
+ public void createKeyNodeList() {
+ YangList yangListHolder = (YangList) getYangSchemaNode();
+ List<String> schemaKeyList = yangListHolder.getKeyList();
+
+ /*
+ * If key element not defined in schema or config is false then
+ * return no need to do create key list.
+ */
+ if (schemaKeyList == null || !yangListHolder.isConfig()) {
+ return;
+ }
+
+ StringBuilder ksb = new StringBuilder();
+
+ // Iterator for schema key name list.
+ Iterator<String> sklItr = schemaKeyList.iterator();
+
+ List<YdtContext> nodeList = new ArrayList<>();
+
+ YangSchemaNodeIdentifier id = new YangSchemaNodeIdentifier();
+ id.setNameSpace(getYdtNodeIdentifier().getNameSpace());
+ // This loop should run while schema key list is not finished
+ while (sklItr.hasNext()) {
+ String name = sklItr.next();
+ id.setName(name);
+ List<YdtNode<YdtMultiInstanceNode>> collidingChild =
+ (List<YdtNode<YdtMultiInstanceNode>>) ydtNodeMap.get(id);
+
+ if (collidingChild == null) {
+ errorHandler(errorMsg(FMT_MISSING_KEY,
+ yangListHolder.getParent().getName(),
+ yangListHolder.getName()), this);
+ }
+
+ YdtNode<YdtMultiInstanceNode> ydtNode = collidingChild.get(0);
+ /*
+ * Preparing composite key string by concatenating values of
+ * all the key leaf.
+ */
+ ksb.append(ydtNode.getValue());
+ nodeList.add(ydtNode);
+ }
+ //Setting te key object in List.
+ keyNodeList = nodeList;
+ compositeKey = ksb.toString();
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNode.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNode.java
new file mode 100644
index 0000000..c3d4b87
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNode.java
@@ -0,0 +1,707 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangList;
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeContextInfo;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yms.app.ydt.exceptions.YdtException;
+import org.onosproject.yms.ydt.YdtContext;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+import org.onosproject.yms.ydt.YdtExtendedInfoType;
+import org.onosproject.yms.ydt.YdtType;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+
+/**
+ * Represents implementation of interfaces to build and obtain YANG data tree
+ * which is data (sub)instance representation, abstract of protocol.
+ */
+public abstract class YdtNode<T> implements YdtExtendedContext, Cloneable {
+
+ // ydt formatted error string
+ private static final String FMT_UNI_KEY =
+ "Some of the key elements are not unique in %s.";
+ private static final String FMT_KLIST_STR =
+ "List of key cannot be created for leaf and leaf-list %s node.";
+ private static final String FMT_VAL_N =
+ "Value cannot be set in non leaf %s node.";
+ private static final String FMT_VAL_NS =
+ "ValueSet cannot be set in non leaf-list %s node.";
+ private static final String FMT_VAL_IN =
+ "Value cannot be invoke from non leaf %s node.";
+ private static final String FMT_VAL_INS =
+ "ValueSet cannot be invoke from non leaf-list %s node";
+ private static final String FMT_MANY_INS =
+ "Too many instances of %s. Expected maximum instances %d.";
+ private static final String FMT_FEW_INS =
+ "Too few instances of %s. Expected minimum instances %d.";
+
+ // ydt error string
+ private static final String E_EXIST = "Node is already part of a tree";
+ private static final String E_ATOMIC =
+ "Child to be added is not atomic, it already has a child";
+ private static final String E_SIB =
+ "Child to be added is not atomic, it already has a next sibling";
+ private static final String E_PRE =
+ "Child to be added is not atomic, it already has a previous " +
+ "sibling";
+ private static final String E_SUPPORT = "Requested node type not supported";
+
+ /*
+ * Parent reference.
+ */
+ private YdtNode parent;
+
+ /*
+ * First child reference.
+ */
+ private YdtNode child;
+
+ /*
+ * Next sibling reference.
+ */
+ private YdtNode nextSibling;
+
+ /*
+ * Previous sibling reference.
+ */
+ private YdtNode previousSibling;
+
+ /*
+ * Last child reference.
+ */
+ private YdtNode lastChild;
+
+ /*
+ * Type of node.
+ */
+ private YdtType ydtType;
+
+ /*
+ * Flag to keep the track of context switch,
+ * if set then traverse back to parent in YDT app tree else no need.
+ */
+ private boolean isContextSwitch;
+
+ /*
+ * YDT extended information.
+ */
+ private T ydtExtendedInfo;
+
+ /*
+ * YDT extended information type.
+ */
+ private YdtExtendedInfoType ydtExtendedInfoType;
+
+ /*
+ * Ydt map to keep the track of node added in YDT.
+ */
+ final Map<YangSchemaNodeIdentifier, List<YdtNode<T>>> ydtNodeMap =
+ new HashMap<>();
+
+ /*
+ * Reference for data-model schema node.
+ */
+ private YangSchemaNode yangSchemaNode;
+
+ /*
+ * Reference for ydt node operation type.
+ */
+ private YdtContextOperationType ydtContextOperationType;
+
+ /*
+ * Key object for ydtNodeMap.
+ */
+ private YangSchemaNodeIdentifier id;
+
+ /*
+ * Ydt map to keep the track of application information object
+ * with respective type.
+ */
+ private final Map<AppType, Object> ydtAppInfoMap = new HashMap<>();
+
+ private YdtContext clonedNode;
+
+ /**
+ * Returns the cloned ydt node.
+ *
+ * @return clonedNode cloned ydt node
+ */
+ public YdtContext getClonedNode() {
+ return clonedNode;
+ }
+
+ /**
+ * Sets the cloned node.
+ *
+ * @param clonedNode cloned ydt node
+ */
+ public void setClonedNode(YdtContext clonedNode) {
+ this.clonedNode = clonedNode;
+ }
+
+ @Override
+ public String getName() {
+ return id.getName();
+ }
+
+ @Override
+ public String getNamespace() {
+ return id.getNameSpace();
+ }
+
+ @Override
+ public <T> T getYdtContextExtendedInfo() {
+ return (T) ydtExtendedInfo;
+ }
+
+ @Override
+ public YdtExtendedInfoType getYdtExtendedInfoType() {
+ return ydtExtendedInfoType;
+ }
+
+ @Override
+ public YdtType getYdtType() {
+ return ydtType;
+ }
+
+ @Override
+ public YdtNode getParent() {
+ return parent;
+ }
+
+ @Override
+ public YdtNode getFirstChild() {
+ return child;
+ }
+
+ @Override
+ public YdtNode getNextSibling() {
+ return nextSibling;
+ }
+
+ public YangSchemaNode getYangSchemaNode() {
+ return yangSchemaNode;
+ }
+
+ @Override
+ public YdtNode getLastChild() {
+ return lastChild;
+ }
+
+ @Override
+ public Object getAppInfo(AppType appType) {
+ return ydtAppInfoMap.get(appType);
+ }
+
+ @Override
+ public void addAppInfo(AppType appType, Object object) {
+ ydtAppInfoMap.put(appType, object);
+ }
+
+ @Override
+ public YangSchemaNodeContextInfo getSchemaNodeContextInfo(
+ YangSchemaNodeIdentifier id) {
+ try {
+ return getYangSchemaNode().getChildSchema(id);
+ } catch (DataModelException e) {
+ errorHandler(e.getLocalizedMessage(), this);
+ }
+ return null;
+ }
+
+ /**
+ * Adds the given value to the non single instance leaf node.
+ * <p>
+ * This default implementation throws an exception stating that
+ * the value cannot be added. Subclasses may override this method
+ * to provide the correct behavior for their specific implementation.
+ *
+ * @param value value in a single instance node
+ */
+ public void addValue(String value) {
+ errorHandler(
+ errorMsg(FMT_VAL_N, getYdtNodeIdentifier().getName()), this);
+ }
+
+ /**
+ * Creates the list of key element's of multi instance node.
+ * this will not be applicable on leaf and leaf-list node.
+ */
+ public void createKeyNodeList() {
+ errorHandler(errorMsg(
+ FMT_KLIST_STR, getYdtNodeIdentifier().getName()), this);
+ }
+
+ /**
+ * Adds the given value to the non single instance leaf node.
+ * <p>
+ * This default implementation throws an exception stating that
+ * the value cannot be added. Subclasses may override this method
+ * to provide the correct behavior for their specific implementation.
+ * This will be applicable in case of call from SBI so no need
+ * to validate the value.
+ *
+ * @param value value in a single instance leaf node
+ */
+ public void addValueWithoutValidation(String value) {
+ errorHandler(
+ errorMsg(FMT_VAL_N, getYdtNodeIdentifier().getName()), this);
+ }
+
+ /**
+ * Adds the given valueSet to the non multi instance leaf node.
+ * <p>
+ * This default implementation throws an exception stating that
+ * the value cannot be added. Subclasses may override this method
+ * to provide the correct behavior for their specific implementation.
+ *
+ * @param valueSet valueSet in a multi instance leaf node
+ */
+ public void addValueSet(Set<String> valueSet) {
+ errorHandler(
+ errorMsg(FMT_VAL_NS, getYdtNodeIdentifier().getName()), this);
+ }
+
+ /**
+ * Adds the given valueSet to the non multi instance leaf node.
+ * <p>
+ * This default implementation throws an exception stating that
+ * the value cannot be added. Subclasses may override this method
+ * to provide the correct behavior for their specific implementation.
+ * This will be applicable in case of call from SBI so no need
+ * to validate the value.
+ *
+ * @param valueSet valueSet in a multi instance leaf node
+ */
+ public void addValueSetWithoutValidation(Set<String> valueSet) {
+ errorHandler(
+ errorMsg(FMT_VAL_NS, getYdtNodeIdentifier().getName()), this);
+ }
+
+ /**
+ * Validates requested node allowed to have duplicate entry or not.
+ * <p>
+ * This default implementation throws an exception stating that
+ * the duplicate entry found. Subclasses may override this method
+ * to provide the correct behavior for their specific implementation.
+ */
+ public void validDuplicateEntryProcessing() {
+ }
+
+ /**
+ * Returns already existing YdtNode in Ydt tree with same nodeIdentifier.
+ *
+ * @param id represents a identifier of YANG data tree node
+ * @return YDT node
+ */
+ public YdtNode getCollidingChild(YangSchemaNodeIdentifier id) {
+
+ // Find the key in YDT map for getting the colliding node.
+ List<YdtNode<T>> collidingChild = ydtNodeMap.get(id);
+
+ /*
+ * If colliding child exist then process colliding node in respective
+ * YDT node type.
+ */
+ if (collidingChild != null) {
+ collidingChild.get(0).validDuplicateEntryProcessing();
+ return collidingChild.get(0);
+ }
+
+ return null;
+ }
+
+ /**
+ * Creates a specific type of node.
+ *
+ * @param type of YDT node
+ * @param id node identifier of the YDT node
+ */
+ YdtNode(YdtType type, YangSchemaNodeIdentifier id) {
+ ydtType = type;
+ setId(id);
+ }
+
+ /**
+ * Sets the parent of node.
+ *
+ * @param parent node
+ */
+ public void setParent(YdtNode parent) {
+ this.parent = parent;
+ }
+
+ /**
+ * Sets the first instance of a child node.
+ *
+ * @param child is only child to be set
+ */
+ public void setChild(YdtNode child) {
+ this.child = child;
+ }
+
+ /**
+ * Sets the next sibling of node.
+ *
+ * @param sibling YANG node
+ */
+ public void setNextSibling(YdtNode sibling) {
+ nextSibling = sibling;
+ }
+
+ /**
+ * Returns the previous sibling of a node.
+ *
+ * @return previous sibling of a node
+ */
+ public YdtNode getPreviousSibling() {
+ return previousSibling;
+ }
+
+ /**
+ * Sets the previous sibling.
+ *
+ * @param previousSibling points to predecessor sibling
+ */
+ public void setPreviousSibling(YdtNode previousSibling) {
+ this.previousSibling = previousSibling;
+ }
+
+ @Override
+ public String getValue() {
+ errorHandler(
+ errorMsg(FMT_VAL_IN, getYdtNodeIdentifier().getName()), this);
+ return null;
+ }
+
+ @Override
+ public Set<String> getValueSet() {
+ errorHandler(
+ errorMsg(FMT_VAL_INS, getYdtNodeIdentifier().getName()), this);
+ return null;
+ }
+
+ /**
+ * Sets the data-model node reference for of a given node.
+ *
+ * @param yangSchemaNode YANG data node
+ */
+ public void setYangSchemaNode(YangSchemaNode yangSchemaNode) {
+ this.yangSchemaNode = yangSchemaNode;
+ }
+
+ /**
+ * Sets the last instance of a child node.
+ *
+ * @param child is last child to be set
+ */
+ public void setLastChild(YdtNode child) {
+ lastChild = child;
+ }
+
+ /**
+ * Returns object node identifier.
+ *
+ * @return node identifier
+ */
+ public YangSchemaNodeIdentifier getYdtNodeIdentifier() {
+ return id;
+ }
+
+ /**
+ * Sets object node identifier.
+ *
+ * @param id node identifier
+ */
+ public void setId(YangSchemaNodeIdentifier id) {
+ this.id = id;
+ }
+
+ /**
+ * Adds a child node.
+ * The children sibling list will be sorted based on node
+ * type. This will add single child or sub-tree based on isAtomic flag.
+ *
+ * @param newChild refers to a new child to be added
+ * @param isAtomic boolean flag to maintain atomicity of the current node
+ * @throws YdtException in case of violation of any YDT rule
+ */
+ public void addChild(YdtContext newChild, boolean isAtomic)
+ throws YdtException {
+
+ if (!(newChild instanceof YdtNode)) {
+ errorHandler(errorMsg(E_SUPPORT), this);
+ }
+
+ YdtNode node = (YdtNode) newChild;
+
+ if (node.getParent() == null) {
+ node.setParent(this);
+ } else if (!node.getParent().equals(this)) {
+ errorHandler(errorMsg(E_EXIST), this);
+ }
+
+ if (node.getFirstChild() != null && isAtomic) {
+ errorHandler(errorMsg(E_ATOMIC), this);
+ }
+
+ if (node.getNextSibling() != null) {
+ errorHandler(errorMsg(E_SIB), this);
+ }
+
+ if (node.getPreviousSibling() != null) {
+ errorHandler(errorMsg(E_PRE), this);
+ }
+
+ // If new node needs to be added as first child.
+ if (getFirstChild() == null) {
+ setChild(node);
+ setLastChild(node);
+ return;
+ }
+
+ // If new node needs to be added as last child.
+ YdtNode curNode = getLastChild();
+ curNode.setNextSibling(node);
+ node.setPreviousSibling(curNode);
+ setLastChild(node);
+ }
+
+ @Override
+ public YdtContextOperationType getYdtContextOperationType() {
+ return ydtContextOperationType;
+ }
+
+ /**
+ * Sets type of yang data tree node operation.
+ *
+ * @param opType type of yang data tree node operation
+ */
+ public void setYdtContextOperationType(YdtContextOperationType opType) {
+ ydtContextOperationType = opType;
+ }
+
+ /**
+ * Updates ydt map of current context parent node.
+ *
+ * @param id object node identifier
+ * @param node ydt node for which map need to be updated
+ */
+ public void updateYdtMap(YangSchemaNodeIdentifier id, YdtNode node) {
+ List<YdtNode<T>> list = ydtNodeMap.get(id);
+ if (list == null) {
+ list = new ArrayList<>();
+ ydtNodeMap.put(id, list);
+ }
+ list.add(node);
+ }
+
+ /**
+ * Returns the flag for node if context switch.
+ *
+ * @return isContextSwitch flag of a node
+ */
+ public boolean getAppContextSwitch() {
+ return isContextSwitch;
+ }
+
+ /**
+ * Sets the flag to keep the track of context switch.
+ * If it is set then when YDT get traverToParent then
+ * traverse back to parent in YDT application tree.
+ */
+ public void setAppContextSwitch() {
+ isContextSwitch = true;
+ }
+
+ /**
+ * Validates all multi Instance inside current context.
+ */
+ public void validateMultiInstanceNode() {
+
+ // Set for checking whether input string is unique or not.
+ Set<String> keyStringSet = new HashSet<>();
+
+ // Iterating over values in map and find multi instance node list only.
+ for (List<YdtNode<T>> ydtNodeList : ydtNodeMap.values()) {
+ validateInstances(keyStringSet, ydtNodeList);
+ }
+ }
+
+ /**
+ * Checks for any duplicate list entries.
+ *
+ * @param keyStringSet set to validate the composite key of an instance
+ * @param ydtNodeList list of entries
+ */
+ private void validateInstances(Set<String> keyStringSet,
+ List<YdtNode<T>> ydtNodeList) {
+ // Clearing the set.
+ keyStringSet.clear();
+
+ if (ydtNodeList.get(0) instanceof YdtMultiInstanceNode) {
+
+ // Storing the number of multiInstance node for number
+ // if instance validation.
+ int instanceCount = ydtNodeList.size();
+
+ YangList list = (YangList) ydtNodeList.get(0).getYangSchemaNode();
+ int minElement;
+ int maxElement;
+ if (list.getMinElements() != null) {
+ minElement = list.getMinElements().getMinElement();
+ if (instanceCount < minElement) {
+ errorHandler(errorMsg(FMT_FEW_INS, list.getName(),
+ minElement), this);
+ }
+ }
+
+ if (list.getMaxElements() != null) {
+ maxElement = list.getMaxElements().getMaxElement();
+ if (instanceCount > maxElement) {
+ errorHandler(errorMsg(FMT_MANY_INS, list.getName(),
+ maxElement), this);
+ }
+ }
+
+ if (list.isConfig() && instanceCount > 1) {
+ // Iterating over values in ydtNodeList of
+ // multiInstanceNode and compare the key string.
+ for (YdtNode ydtNode : ydtNodeList) {
+ if (!keyStringSet.add(((YdtMultiInstanceNode) ydtNode)
+ .getCompositeKey())) {
+ errorHandler(errorMsg(
+ FMT_UNI_KEY, ydtNode.getYdtNodeIdentifier()
+ .getName()), this);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Walks in whole Ydt Tree and de-reference all the tree node.
+ * This will be called only when any exception occurs while processing
+ * the node in Ydt tree.
+ *
+ * @param node ydt node
+ */
+ public void freeRestResources(YdtNode node) {
+ // Traversing to logical rootNode.
+ YdtNode rootNode = node;
+ while (rootNode.getParent() != null) {
+ rootNode = rootNode.getParent();
+ }
+ YdtNode currentNode = rootNode;
+ while (currentNode != null) {
+
+ // Move down to first child
+ YdtNode nextNode = currentNode.getFirstChild();
+ if (nextNode != null) {
+ currentNode = nextNode;
+ continue;
+ }
+
+ // No child nodes, so walk tree
+ while (currentNode != null) {
+ // To keep the track of last sibling.
+ YdtNode lastSibling = currentNode;
+
+ // Move to sibling if possible.
+ nextNode = currentNode.getNextSibling();
+
+ // free currentNode resources
+ free(lastSibling);
+
+ lastSibling.getNamespace();
+ if (nextNode != null) {
+ currentNode = nextNode;
+ break;
+ }
+
+ // Move up
+ if (currentNode.equals(rootNode)) {
+ currentNode = null;
+ } else {
+ currentNode = currentNode.getParent();
+ lastSibling.setParent(null);
+ }
+ }
+ }
+ }
+
+ /**
+ * Free the give YDT node by de-referencing it to null.
+ *
+ * @param node node to be freed
+ */
+ private void free(YdtNode node) {
+ if (node.getParent() != null) {
+ YdtNode parent = node.getParent();
+ parent.setChild(null);
+ parent.setLastChild(null);
+ if (node.getNextSibling() != null) {
+ parent.setChild(node.getNextSibling());
+ }
+ }
+ YdtNode parentRef = node.getParent();
+ node = new YdtSingleInstanceNode(null);
+ node.ydtType = null;
+ node.setParent(parentRef);
+ }
+
+ /**
+ * Clones the current node contents and create a new node.
+ *
+ * @return cloned node
+ * @throws CloneNotSupportedException clone is not supported
+ * by the referred node
+ */
+ public YdtNode clone() throws CloneNotSupportedException {
+ YdtNode clonedNode = (YdtNode) super.clone();
+ clonedNode.setPreviousSibling(null);
+ clonedNode.setNextSibling(null);
+ clonedNode.setParent(null);
+ clonedNode.setChild(null);
+ clonedNode.setLastChild(null);
+ return clonedNode;
+ }
+
+ /**
+ * Handles an error scenario, freeing allocated resources for the given YTD
+ * node before throwing an exception with the specified error message.
+ *
+ * @param error error message
+ * @param curNode ydt node
+ * @throws YdtException with the specified error message
+ */
+ public void errorHandler(String error, YdtNode curNode) {
+ curNode.freeRestResources(curNode);
+ throw new YdtException(error);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNodeFactory.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNodeFactory.java
new file mode 100644
index 0000000..43680da
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtNodeFactory.java
@@ -0,0 +1,256 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNode;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+import org.onosproject.yangutils.datamodel.YangSchemaNodeType;
+import org.onosproject.yms.app.ydt.exceptions.YdtException;
+import org.onosproject.yms.ydt.YdtContextOperationType;
+
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_MULTI_INSTANCE_LEAF_NODE;
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_MULTI_INSTANCE_NODE;
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_LEAF_NODE;
+import static org.onosproject.yangutils.datamodel.YangSchemaNodeType.YANG_SINGLE_INSTANCE_NODE;
+import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.DELETE_ONLY;
+import static org.onosproject.yms.app.ydt.YdtAppNodeOperationType.OTHER_EDIT;
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+
+/**
+ * Represents an YANG node factory to create different types of YANG data tree
+ * node.
+ */
+final class YdtNodeFactory {
+
+ // ydt formatted error string
+ private static final String FMT_NOT_EXIST =
+ "Schema node with name %s doesn't exist.";
+
+ // No instantiation
+ private YdtNodeFactory() {
+ }
+
+ /**
+ * Returns a YANG data tree node for a given name, set of values and
+ * instance type.
+ *
+ * @param id dataNodeIdentifier of data tree node
+ * @param schemaNode data node as per YANG schema metadata
+ * @param cardinality requested cardinality of node
+ * @param callType identify the call type
+ * @return YANG data tree node
+ */
+ protected static YdtNode getNode(YangSchemaNodeIdentifier id,
+ YangSchemaNode schemaNode,
+ RequestedCardinality cardinality,
+ RequestedCallType callType) {
+
+ YdtNode newNode = null;
+ YangSchemaNodeType nodeType = schemaNode.getYangSchemaNodeType();
+
+ switch (cardinality) {
+
+ case UNKNOWN:
+ /*
+ * if requested node type is UNKNOWN, check corresponding
+ * yang data node type and create respective type node.
+ */
+ newNode = getYangSchemaNodeTypeSpecificContext(id, nodeType,
+ callType);
+ break;
+
+ /*
+ * if requested node type is specified and it exist as node of some
+ * other type in data model then throw exception
+ */
+ case SINGLE_INSTANCE:
+ validateNodeType(id, nodeType, YANG_SINGLE_INSTANCE_NODE);
+ newNode = new YdtSingleInstanceNode(id);
+ break;
+
+ case MULTI_INSTANCE:
+
+ validateNodeType(id, nodeType, YANG_MULTI_INSTANCE_NODE);
+ newNode = new YdtMultiInstanceNode(id);
+ break;
+
+ case SINGLE_INSTANCE_LEAF:
+
+ validateNodeType(id, nodeType, YANG_SINGLE_INSTANCE_LEAF_NODE);
+ newNode = new YdtSingleInstanceLeafNode(id);
+ break;
+
+ case MULTI_INSTANCE_LEAF:
+
+ validateNodeType(id, nodeType, YANG_MULTI_INSTANCE_LEAF_NODE);
+ newNode = new YdtMultiInstanceLeafNode(id);
+ break;
+
+ default:
+ throwNotExistError(id);
+ }
+
+ // set reference of yang data node in the requested node.
+ newNode.setYangSchemaNode(schemaNode);
+
+ return newNode;
+ }
+
+ /**
+ * Validates the requested ydt node type against the schema node type,
+ * if it is not equal then it will throw warning.
+ *
+ * @param id dataNodeIdentifier of data tree node
+ * @param nodeType actual node type
+ * @param requestedType user requested node type
+ */
+ private static void validateNodeType(YangSchemaNodeIdentifier id,
+ YangSchemaNodeType nodeType,
+ YangSchemaNodeType requestedType) {
+ if (nodeType != requestedType) {
+ throwNotExistError(id);
+ }
+ }
+
+ /**
+ * Creates Yang data tree node of YangSchemaNode type specific for
+ * requestedCardinality of type UNKNOWN and returns the same.
+ *
+ * @param id node identifier of data tree node
+ * @param nodeType schema node type as per YANG schema metadata
+ * @param callType identify the call type
+ * @return YANG data tree node
+ */
+ private static YdtNode getYangSchemaNodeTypeSpecificContext(
+ YangSchemaNodeIdentifier id,
+ YangSchemaNodeType nodeType,
+ RequestedCallType callType) {
+ switch (callType) {
+ case LEAF:
+ switch (nodeType) {
+
+ case YANG_SINGLE_INSTANCE_LEAF_NODE:
+ return new YdtSingleInstanceLeafNode(id);
+
+ case YANG_MULTI_INSTANCE_LEAF_NODE:
+ return new YdtMultiInstanceLeafNode(id);
+
+ default:
+ throwNotExistError(id);
+ }
+
+ case OTHER:
+ switch (nodeType) {
+
+ case YANG_SINGLE_INSTANCE_NODE:
+ return new YdtSingleInstanceNode(id);
+
+ case YANG_MULTI_INSTANCE_NODE:
+ return new YdtMultiInstanceNode(id);
+
+ default:
+ throwNotExistError(id);
+ }
+
+ case MULTI_INSTANCE:
+ switch (nodeType) {
+
+ case YANG_MULTI_INSTANCE_LEAF_NODE:
+ return new YdtMultiInstanceLeafNode(id);
+
+ case YANG_MULTI_INSTANCE_NODE:
+ return new YdtMultiInstanceNode(id);
+
+ default:
+ throwNotExistError(id);
+ }
+
+ default:
+ throwNotExistError(id);
+ }
+
+ return null;
+ }
+
+ /**
+ * Create Yang data tree node of YangSchemaNode type specific and
+ * returns the same.
+ *
+ * @param id node identifier of data tree node
+ * @param nodeType schema node type as per YANG schema metadata
+ * @return YANG data tree node
+ */
+ protected static YdtNode getYangSchemaNodeTypeSpecificContext(
+ YangSchemaNodeIdentifier id,
+ YangSchemaNodeType nodeType) {
+
+ switch (nodeType) {
+
+ case YANG_SINGLE_INSTANCE_LEAF_NODE:
+ return new YdtSingleInstanceLeafNode(id);
+
+ case YANG_MULTI_INSTANCE_LEAF_NODE:
+ return new YdtMultiInstanceLeafNode(id);
+
+ case YANG_SINGLE_INSTANCE_NODE:
+ return new YdtSingleInstanceNode(id);
+
+ case YANG_MULTI_INSTANCE_NODE:
+ return new YdtMultiInstanceNode(id);
+
+ default:
+ throwNotExistError(id);
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the app tree operation type with the help of YdtOperation type.
+ *
+ * @param opType ydt operation type
+ * @return app tree operation type
+ */
+ protected static YdtAppNodeOperationType getAppOpTypeFromYdtOpType(
+ YdtContextOperationType opType) {
+ // Get the app tree operation type.
+ switch (opType) {
+ case CREATE:
+ case MERGE:
+ case REPLACE:
+ return OTHER_EDIT;
+
+ case DELETE:
+ case REMOVE:
+ return DELETE_ONLY;
+
+ default:
+ return null;
+ //TODO handle the default data type.
+ }
+ }
+
+ /**
+ * Throws exception for requested ydt node by preparing error message with
+ * given node identifier.
+ *
+ * @param id node identifier
+ */
+ private static void throwNotExistError(YangSchemaNodeIdentifier id) {
+ throw new YdtException(errorMsg(FMT_NOT_EXIST, id.getName()));
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceLeafNode.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceLeafNode.java
new file mode 100644
index 0000000..0bd7036
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceLeafNode.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+
+import static org.onosproject.yms.app.ydt.YdtConstants.FMT_DUP_ENTRY;
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_LEAF_VALUE_NODE;
+
+/**
+ * Represents YDT single instance leaf node which is an atomic element
+ * and doesn't have any child.
+ */
+class YdtSingleInstanceLeafNode extends YdtNode {
+
+ /*
+ * Value of the leaf.
+ */
+ private String value;
+
+ /**
+ * Creates a YANG single instance leaf node.
+ *
+ * @param id node identifier of YDT single instance leaf node
+ */
+ protected YdtSingleInstanceLeafNode(YangSchemaNodeIdentifier id) {
+ super(SINGLE_INSTANCE_LEAF_VALUE_NODE, id);
+ }
+
+ @Override
+ public String getValue() {
+ return value;
+ }
+
+ @Override
+ public void addValue(String value) {
+ // Check the value against corresponding data-type.
+ try {
+ getYangSchemaNode().isValueValid(value);
+ } catch (Exception e) {
+ errorHandler(e.getLocalizedMessage(), this);
+ }
+
+ // After validation is successful then add value to node.
+ this.value = value;
+ }
+
+
+ @Override
+ public void addValueWithoutValidation(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public void validDuplicateEntryProcessing() {
+ errorHandler(errorMsg(FMT_DUP_ENTRY, getYdtNodeIdentifier().getName()),
+ this);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceNode.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceNode.java
new file mode 100644
index 0000000..b7f84b5
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/YdtSingleInstanceNode.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt;
+
+import org.onosproject.yangutils.datamodel.YangSchemaNodeIdentifier;
+
+import static org.onosproject.yms.app.ydt.YdtConstants.FMT_DUP_ENTRY;
+import static org.onosproject.yms.app.ydt.YdtConstants.errorMsg;
+import static org.onosproject.yms.ydt.YdtType.SINGLE_INSTANCE_NODE;
+
+/**
+ * Represents a single instance YANG data tree node.
+ */
+class YdtSingleInstanceNode extends YdtNode {
+
+ /**
+ * Creates a YANG single instance node object.
+ *
+ * @param id node identifier of YDT single instance node
+ */
+ protected YdtSingleInstanceNode(YangSchemaNodeIdentifier id) {
+ super(SINGLE_INSTANCE_NODE, id);
+ }
+
+ @Override
+ public void validDuplicateEntryProcessing() {
+ errorHandler(errorMsg(FMT_DUP_ENTRY, getYdtNodeIdentifier().getName()),
+ this);
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/YdtException.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/YdtException.java
new file mode 100644
index 0000000..db21976
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/YdtException.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2016-present 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.yms.app.ydt.exceptions;
+
+/**
+ * Represents base class for exceptions in YDT operations.
+ */
+public class YdtException extends RuntimeException {
+
+ private static final long serialVersionUID = 20160211L;
+
+ /**
+ * Creates a new YDT exception with given message.
+ *
+ * @param message the detail of exception in string
+ */
+ public YdtException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new YDT exception from given message and cause.
+ *
+ * @param message the detail of exception in string
+ * @param cause underlying cause of the error
+ */
+ public YdtException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new YDT exception from cause.
+ *
+ * @param cause underlying cause of the error
+ */
+ public YdtException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Creates a new YDT exception from given parameters.
+ *
+ * @param keyword identify error scenario whether it is many or few
+ * @param name name of the node
+ * @param count supported count value
+ */
+ public YdtException(String keyword, String name, int count) {
+ super("Too " + keyword + " key parameter in " + name + ". Expected " +
+ "count " + count + ".");
+ }
+}
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/package-info.java
new file mode 100644
index 0000000..20da849
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/exceptions/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016-present 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.
+ */
+
+/**
+ * YANG data tree exceptions.
+ */
+package org.onosproject.yms.app.ydt.exceptions;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/package-info.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/package-info.java
new file mode 100644
index 0000000..2ed1950
--- /dev/null
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ydt/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2016-present 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.
+ */
+
+/**
+ * Provides implementation of build and obtain YANG data tree which is data
+ * (sub)instance representation, abstract of protocol.
+ */
+package org.onosproject.yms.app.ydt;
diff --git a/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java b/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
index f4030ce..b9ea3a8 100644
--- a/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
+++ b/apps/yms/app/src/main/java/org/onosproject/yms/app/ymsm/YmsManager.java
@@ -25,6 +25,8 @@
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.core.IdGenerator;
+import org.onosproject.yms.app.ydt.DefaultYdtWalker;
+import org.onosproject.yms.app.ydt.YangRequestWorkBench;
import org.onosproject.yms.app.ynh.YangNotificationExtendedService;
import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry;
import org.onosproject.yms.app.ysr.YangSchemaRegistry;
@@ -97,7 +99,8 @@
public YdtBuilder getYdtBuilder(String logicalRootName,
String rootNamespace,
YmsOperationType operationType) {
- return null;
+ return new YangRequestWorkBench(logicalRootName, rootNamespace,
+ operationType, schemaRegistry, true);
}
@Override
@@ -105,12 +108,20 @@
String rootNamespace,
YmsOperationType operationType,
Object schemaRegistryForYdt) {
- return null;
+ if (schemaRegistryForYdt != null) {
+ return new YangRequestWorkBench(logicalRootName, rootNamespace,
+ operationType,
+ (YangSchemaRegistry)
+ schemaRegistryForYdt,
+ false);
+ }
+ return new YangRequestWorkBench(logicalRootName, rootNamespace,
+ operationType, schemaRegistry, true);
}
@Override
public YdtWalker getYdtWalker() {
- return null;
+ return new DefaultYdtWalker();
}
@Override
@@ -177,5 +188,4 @@
public YangSchemaRegistry getSchemaRegistry() {
return schemaRegistry;
}
-
}