YANG model design to define data node for usage in YANG store and YANG runtime
Change-Id: I38cb20716fb03067f875b8a8f1ce44c94673ebdf
diff --git a/model/pom.xml b/model/pom.xml
new file mode 100644
index 0000000..02789b3
--- /dev/null
+++ b/model/pom.xml
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-utils</artifactId>
+ <version>1.10-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-yang-model</artifactId>
+ <version>1.10-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.21</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.0.2</version>
+ <configuration>
+ <skipIfEmpty>true</skipIfEmpty>
+ </configuration>
+ <executions>
+ <execution>
+ <id>default</id>
+ <goals>
+ <goal>test-jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/model/src/main/java/org/onosproject/yang/model/DataNode.java b/model/src/main/java/org/onosproject/yang/model/DataNode.java
new file mode 100644
index 0000000..257b5de
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/DataNode.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.yang.model;
+
+/**
+ * Abstraction of an entity which represents data tree node. Information
+ * exchange between YANG runtime, protocol and store will be based on this
+ * node, agnostic of schema.
+ */
+public interface DataNode {
+
+ /**
+ * Returns the node schema identifier.
+ *
+ * @return node schema identifier
+ */
+ SchemaIdentifier identifier();
+
+ /**
+ * Returns the type of node.
+ *
+ * @return node type
+ */
+ Type type();
+
+ /**
+ * Returns the key to identify a branching node.
+ *
+ * @return key to identify a branching node
+ */
+ NodeKey key();
+
+ /**
+ * Represents type of node in data store.
+ */
+ enum Type {
+
+ /**
+ * Single instance node.
+ */
+ SINGLE_INSTANCE_NODE,
+
+ /**
+ * Multi instance node.
+ */
+ MULTI_INSTANCE_NODE,
+
+ /**
+ * Single instance leaf node.
+ */
+ SINGLE_INSTANCE_LEAF_VALUE_NODE,
+
+ /**
+ * Multi instance leaf node.
+ */
+ MULTI_INSTANCE_LEAF_VALUE_NODE
+ }
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/InnerNode.java b/model/src/main/java/org/onosproject/yang/model/InnerNode.java
new file mode 100644
index 0000000..c4db08f
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/InnerNode.java
@@ -0,0 +1,36 @@
+/*
+ * 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.yang.model;
+
+import java.util.LinkedHashMap;
+
+/**
+ * Abstraction of an entity which represents an inner node in data store.
+ */
+public interface InnerNode extends DataNode {
+
+ /**
+ * Returns the children nodes to the current node.
+ * <p>
+ * Children nodes are identified based on the node key
+ *
+ * @return read only linked map of children nodes
+ */
+ LinkedHashMap<NodeKey, DataNode> childNodes();
+
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/LeafNode.java b/model/src/main/java/org/onosproject/yang/model/LeafNode.java
new file mode 100644
index 0000000..e6af9d2
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/LeafNode.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.yang.model;
+
+/**
+ * Abstraction of an entity which represents leaf data tree node.
+ */
+public interface LeafNode extends DataNode {
+
+ /**
+ * Returns value contained in leaf node.
+ *
+ * @return value contained in leaf node
+ */
+ Object value();
+
+ /**
+ * Returns value as string, for usage in serializers.
+ *
+ * @return string representation of value
+ */
+ String asString();
+
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
new file mode 100644
index 0000000..8be8bbe
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/MultiInstanceLeafKey.java
@@ -0,0 +1,38 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Abstraction of an entity which identifies a uniquely branching leaf
+ * corresponding to a multi instance leaf schema.
+ */
+public interface MultiInstanceLeafKey extends NodeKey {
+
+ /**
+ * Returns value of node, this is only valid for multi-instance leaf, node.
+ *
+ * @return value maintained in the node
+ */
+ Object value();
+
+ /**
+ * Returns value as string, for usage in serializers.
+ *
+ * @return string representation of value
+ */
+ String asString();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
new file mode 100644
index 0000000..5677891
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/MultiInstanceNodeKey.java
@@ -0,0 +1,36 @@
+/*
+ * 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.yang.model;
+
+import java.util.List;
+
+/**
+ * Abstraction of an entity which identifies a unique branching node
+ * corresponding to a multi instance schema definition.
+ */
+public interface MultiInstanceNodeKey extends NodeKey {
+
+ /**
+ * Returns the list of key leaf nodes of a multi instance node, which
+ * uniquely identifies the branching node entry corresponding to a multi
+ * instance schema definition.
+ *
+ * @return List of key leaf nodes
+ */
+ List<LeafNode> keyLeafs();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/NodeKey.java b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
new file mode 100644
index 0000000..1f6dbfe
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/NodeKey.java
@@ -0,0 +1,33 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Abstraction of an entity which identifies a node uniquely among its
+ * siblings.
+ */
+public interface NodeKey extends Comparable<NodeKey> {
+
+ /**
+ * Returns the schema identifier as minimal key required to identify a
+ * branching node.
+ *
+ * @return schema identifier of a key
+ */
+ SchemaIdentifier identifier();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java b/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
new file mode 100644
index 0000000..fb40c48
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/ResourceIdentifier.java
@@ -0,0 +1,95 @@
+/*
+ * 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.yang.model;
+
+/**
+ * Abstraction of an entity which identifies a resource in the logical tree
+ * data store. It is a recursive approach to locate a resource in the
+ * instance tree.
+ */
+
+ /*-- Assume the below schema
+ * container node1{
+ * list node2{
+ * key node3;
+ * leaf node3{
+ * type string;
+ * }
+ * leaf-list node4{
+ * type string
+ * }
+ * }
+ * }
+ * Assume an instance tree as below
+ * node1
+ * |----node2
+ * | |----node3
+ * | | |----"val1"
+ * | |----node4
+ * | | |----"val2"
+ * | | |----"val3"
+ * |----node2
+ * | |----node3
+ * | | |----"val4"
+ * | |----node4
+ * | | |----"val5"
+ * | | |----"val6"
+ * <p>
+ *
+ * Assume a resource identifier variable a is pointing to node4 with val3,
+ * then its value is as follows
+ *
+ * //identifies node1
+ * NodeKey containerKey = a.nodeKey();
+ * SchemaIdentifier schemaId = containerKey.identifier();//"node1"
+ *
+ * //identifies a specific entry of list node2
+ * MultiInstanceNodeKey listKey;
+ * listKey = (MultiInstanceNodeKey) a.descendentIdentifier().nodeKey();
+ * schemaId = listKey.identifier();//"node2"
+ * List<LeafNode> keyLeaves = listKey.keyLeafs();
+ * LeafNode key = keyLeaves.get(0);
+ * schemaId = key.identifier();//"node3"
+ * String keyVal = key.asString();//"val1"
+ *
+ * //identifiers a specific entry of leaf-list node4
+ * MultiInstanceLeafKey leafKey;
+ * leafKey = (MultiInstanceLeafKey) a.descendentIdentifier().
+ * descendentIdentifier().nodeKey();
+ * schemaId = leafKey.identifier();//"node4"
+ * keyVal = leafKey.asString();//val3
+ *
+ * ResourceIdentifier termination = a.descendentIdentifier().descendentIdentifier().
+ * descendentIdentifier(); //null
+ *
+ */
+public interface ResourceIdentifier {
+ /**
+ * Returns the node key used to uniquely identify the branch in the
+ * logical tree.
+ *
+ * @return node key uniquely identifying the branch
+ */
+ NodeKey nodeKey();
+
+ /**
+ * Returns the descendent resource identifier.
+ *
+ * @return descendent resource identifier
+ */
+ ResourceIdentifier descendentIdentifier();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java b/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.java
new file mode 100644
index 0000000..a180afb
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/SchemaIdentifier.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.yang.model;
+
+/**
+ * Abstraction of an entity which identifies a schema node in the schema / data
+ * tree.
+ */
+public interface SchemaIdentifier {
+ /**
+ * Returns node schema name. This is mandatory to identify node according
+ * to schema.
+ *
+ * @return node name
+ */
+ String name();
+
+ /**
+ * Returns node's namespace. This is mandatory serializers must translate
+ * any implicit namespace to explicit namespace.
+ *
+ * @return node's namespace
+ */
+ String namespace();
+}
diff --git a/model/src/main/java/org/onosproject/yang/model/package-info.java b/model/src/main/java/org/onosproject/yang/model/package-info.java
new file mode 100644
index 0000000..dcd19fe
--- /dev/null
+++ b/model/src/main/java/org/onosproject/yang/model/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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.
+ */
+
+/**
+ * Core of hierarchical data organization. Supports traversal of tree data
+ * while being agnostic of specific schemas.
+ * Supports database operation on logical hierarchical data store.
+ */
+package org.onosproject.yang.model;