Merge "Initial sketch of YANG runtime API."
diff --git a/pom.xml b/pom.xml
index 0376c03..4134f92 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
         <module>generator</module>
         <module>parser</module>
         <module>plugin</module>
+        <module>runtime</module>
     </modules>
 
     <!-- FIXME this can be removed if/when buck-api is released -->
diff --git a/runtime/pom.xml b/runtime/pom.xml
new file mode 100644
index 0000000..9398f49
--- /dev/null
+++ b/runtime/pom.xml
@@ -0,0 +1,69 @@
+<!--
+  ~ 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-runtime</artifactId>
+    <version>1.10-SNAPSHOT</version>
+    <packaging>jar</packaging>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-yang-datamodel</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <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/runtime/src/main/java/org/onosproject/yang/ContainerDataNode.java b/runtime/src/main/java/org/onosproject/yang/ContainerDataNode.java
new file mode 100644
index 0000000..16d8e42
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/ContainerDataNode.java
@@ -0,0 +1,32 @@
+/*
+ * 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;
+
+import java.util.List;
+
+/**
+ * Representation of a container data node capable of containing children nodes.
+ */
+public interface ContainerDataNode extends DataNode {
+
+    // List of children
+    List<DataNode> children();
+
+    // Child with specific identifier
+    DataNode child(String identifier); // TODO: Use NodeIdentifier instead of String
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/DataNode.java b/runtime/src/main/java/org/onosproject/yang/DataNode.java
new file mode 100644
index 0000000..97ce1c6
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/DataNode.java
@@ -0,0 +1,31 @@
+/*
+ * 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;
+
+/**
+ * Representation of a configuration data node capable of either carrying data
+ * or conveying the configuration tree structure.
+ */
+public interface DataNode {
+
+    // TODO: specify generic nature of holding data and/or tree structure
+    // TODO: determine whether there should be subclasses for leaf, container, etc.
+    // identifier
+    // type
+    // no parent!
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/LeafDataNode.java b/runtime/src/main/java/org/onosproject/yang/LeafDataNode.java
new file mode 100644
index 0000000..69b1bb0
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/LeafDataNode.java
@@ -0,0 +1,27 @@
+/*
+ * 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;
+
+/**
+ * Representation of a leaf data node capable of holding a value.
+ */
+public interface LeafDataNode extends DataNode {
+
+    // String, Number or Boolean primitive values
+    Object value();
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/YangModel.java b/runtime/src/main/java/org/onosproject/yang/YangModel.java
new file mode 100644
index 0000000..dbfcfee
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/YangModel.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;
+
+import java.io.InputStream;
+import java.util.Set;
+
+/**
+ * Representation of a compiled YANG model.
+ */
+public interface YangModel {
+
+    // name
+    // schema meta-data!!!
+
+    // set of source yang files (names & streams)
+    Set<String> getYangFiles();
+
+    InputStream getYangSource(String name);
+
+    // set of generated model classes
+    Set<String> getJavaModelClasses();
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/package-info.java b/runtime/src/main/java/org/onosproject/yang/package-info.java
new file mode 100644
index 0000000..e1a76c3
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/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.
+ */
+
+/**
+ * Basic constructs for compiling and working with YANG models.
+ */
+package org.onosproject.yang;
\ No newline at end of file
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/DataFormat.java b/runtime/src/main/java/org/onosproject/yang/runtime/DataFormat.java
new file mode 100644
index 0000000..3902362
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/DataFormat.java
@@ -0,0 +1,27 @@
+/*
+ * 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.runtime;
+
+/**
+ * Abstraction of configuration data-format descriptor.
+ */
+public interface DataFormat {
+
+    // TODO: should this be an enum instead with choices fixed at compile-time?
+    // name, e.g. "XML", "JSON"
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangModelRegistry.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangModelRegistry.java
new file mode 100644
index 0000000..6048c11
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangModelRegistry.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.yang.runtime;
+
+import org.onosproject.yang.YangModel;
+
+import java.util.Set;
+
+/**
+ * Registry of YANG models known to YANG runtime.
+ */
+public interface YangModelRegistry {
+
+    /**
+     * Registers a new model.
+     *
+     * @param model model to be registered
+     */
+    void registerModel(YangModel model);
+
+    /**
+     * Unregisters the specified model.
+     *
+     * @param model model to be unregistered
+     */
+    void unregisterModel(YangModel model);
+
+    /**
+     * Returns collection of all registered models.
+     *
+     * @return collection of models
+     */
+    Set<YangModel> getModels();
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java
new file mode 100644
index 0000000..6c69507
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangRuntimeService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.runtime;
+
+import org.onosproject.yang.DataNode;
+
+import java.io.InputStream;
+
+/**
+ * Service for encoding and decoding between internal and external model
+ * representations.
+ */
+public interface YangRuntimeService {
+
+    /**
+     * Decodes the external representation of a configuration model from the
+     * specified input stream and into an in-memory representation.
+     *
+     * @param external input stream carrying external representation of
+     *                 configuration data
+     * @param format   data format of the provided external representation
+     * @return in-memory representation of configuration data
+     */
+    DataNode decode(InputStream external, DataFormat format);
+
+    /**
+     * Encodes the internal in-memory representation of a configuration model
+     * to an external representation consumable from the resulting input stream.
+     *
+     * @param internal in-memory representation of configuration data
+     * @param format   expected data format of the external representation
+     * @return input stream carrying external representation of
+     * configuration data
+     */
+    InputStream encode(DataNode internal, DataFormat format);
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializer.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializer.java
new file mode 100644
index 0000000..0ce4308
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializer.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.yang.runtime;
+
+import org.onosproject.yang.DataNode;
+
+import java.io.InputStream;
+
+/**
+ * Abstraction of entity capable of encoding and decoding arbitrary
+ * {@link DataNode} structures, which are in-memory representations of
+ * YANG models, to and from various external representations, e.g. XML, JSON.
+ * <p>
+ * This interface is not intended for use by applications, but rather only
+ * by the YANG runtime implementation.
+ * </p>
+ */
+public interface YangSerializer {
+
+    /**
+     * Returns the data format supported by this  serializer.
+     *
+     * @return supported data format
+     */
+    DataFormat supportsFormat();
+
+    /**
+     * Decodes the external representation of a configuration model from the
+     * specified input stream and into an in-memory representation.
+     *
+     * @param external input stream carrying external representation of
+     *                 configuration data
+     * @param context  serialization context containing information required
+     *                 for the serializer, e.g. access to model schemas
+     * @return in-memory representation of configuration data
+     */
+    DataNode decode(InputStream external, YangSerializerContext context);
+
+    /**
+     * Encodes the internal in-memory representation of a configuration model
+     * to an external representation consumable from the resulting input stream.
+     *
+     * @param internal in-memory representation of configuration data
+     * @param context  serialization context containing information required
+     *                 for the serializer, e.g. access to model schemas
+     * @return input stream carrying external representation of
+     * configuration data
+     */
+    InputStream encode(DataNode internal, YangSerializerContext context);
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java
new file mode 100644
index 0000000..e2b2cbf
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerContext.java
@@ -0,0 +1,27 @@
+/*
+ * 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.runtime;
+
+/**
+ * Representation of a context for encoding and decoding YANG models via
+ * serializers.
+ */
+public interface YangSerializerContext {
+
+    // any required facilitites for serialization go here
+    //
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerRegistry.java b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerRegistry.java
new file mode 100644
index 0000000..13aae92
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/YangSerializerRegistry.java
@@ -0,0 +1,47 @@
+/*
+ * 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.runtime;
+
+import java.util.Set;
+
+/**
+ * Registry of YANG serializers available as part of YANG runtime.
+ */
+public interface YangSerializerRegistry {
+
+    /**
+     * Registers a new serializer.
+     *
+     * @param serializer serializer to be registered
+     */
+    void registerSerializer(YangSerializer serializer);
+
+    /**
+     * Unregisters the specified serializer.
+     *
+     * @param serializer serializer to be unregistered
+     */
+    void unregisterSerializer(YangSerializer serializer);
+
+    /**
+     * Returns collection of all registered serializers.
+     *
+     * @return collection of serializers
+     */
+    Set<YangSerializer> getSerializers();
+
+}
diff --git a/runtime/src/main/java/org/onosproject/yang/runtime/package-info.java b/runtime/src/main/java/org/onosproject/yang/runtime/package-info.java
new file mode 100644
index 0000000..6b8a685
--- /dev/null
+++ b/runtime/src/main/java/org/onosproject/yang/runtime/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.
+ */
+
+/**
+ * Set of facilities for processing and working with compiled YANG models.
+ */
+package org.onosproject.yang.runtime;
\ No newline at end of file