[ONOS-5793] YANG model and model registry definition
Change-Id: I7b7113e0018b687d328ee43c452b982d4f34c48b
diff --git a/runtime/api/pom.xml b/runtime/api/pom.xml
new file mode 100644
index 0000000..462eb3a
--- /dev/null
+++ b/runtime/api/pom.xml
@@ -0,0 +1,63 @@
+<!--
+ ~ Copyright 2017-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-runtime</artifactId>
+ <version>1.12-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>onos-yang-runtime-api</artifactId>
+ <packaging>jar</packaging>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-model</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onosproject</groupId>
+ <artifactId>onos-yang-compiler-api</artifactId>
+ <version>1.12-SNAPSHOT</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/api/src/main/java/org/onosproject/yang/runtime/api/AppModuleInfo.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/AppModuleInfo.java
new file mode 100644
index 0000000..f75f119
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/AppModuleInfo.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017-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.api;
+
+import java.util.List;
+
+/**
+ * Representation of an entity which defines additional information about the
+ * module required for the model registration.
+ */
+public interface AppModuleInfo {
+
+ /**
+ * Returns the module class which will be required by YANG runtime to
+ * obtain the class loader.
+ *
+ * @return module JAVA class
+ */
+ Class<?> getModuleClass();
+
+ /**
+ * Sets module class.
+ *
+ * @param moduleClass module class
+ */
+ void setModuleClass(Class<?> moduleClass);
+
+ /**
+ * Reference RFC 7895
+ * Retrieves the list of YANG feature names from this module that are
+ * supported by the server, regardless of whether they are
+ * defined in the module or any included submodule.
+ *
+ * @return list of YANG features
+ */
+ List<String> getFeatureList();
+
+ /**
+ * Adds supported feature.
+ *
+ * @param feature supported feature
+ */
+ void addFeature(String feature);
+}
diff --git a/runtime/api/src/main/java/org/onosproject/yang/runtime/api/DataFormat.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/DataFormat.java
new file mode 100644
index 0000000..1ba26fb
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/DataFormat.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017-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.api;
+
+/**
+ * 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/api/src/main/java/org/onosproject/yang/runtime/api/ModelRegistrationParam.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/ModelRegistrationParam.java
new file mode 100644
index 0000000..c1d2bf5
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/ModelRegistrationParam.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2017-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.api;
+
+import org.onosproject.yang.YangModel;
+import org.onosproject.yang.YangModuleId;
+
+/**
+ * Representation of model registration parameters.
+ */
+public interface ModelRegistrationParam {
+
+ /**
+ * Returns YANG model.
+ *
+ * @return YANG model
+ */
+ YangModel getYangModel();
+
+ /**
+ * Sets YANG model.
+ *
+ * @param model YANG model
+ */
+ void setYangModel(YangModel model);
+
+ /**
+ * Returns extended app related information of a module/sub-module.
+ *
+ * @param id YANG module identifier
+ * @return application module information
+ */
+ AppModuleInfo getAppModuleInfo(YangModuleId id);
+
+ /**
+ * Adds application module information associated with module identifier.
+ * It's expected that application should provide information for all the
+ * YANG modules.
+ *
+ * @param id YANG module identifier
+ * @param info application information associated with module identifier
+ */
+ void addAppModuleInfo(YangModuleId id, AppModuleInfo info);
+}
diff --git a/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangModelRegistry.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangModelRegistry.java
new file mode 100644
index 0000000..036c399
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangModelRegistry.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2017-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.api;
+
+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 param parameters having model to be registered with additional
+ * informations provided by app
+ */
+ void registerModel(ModelRegistrationParam param);
+
+ /**
+ * Unregisters the specified model.
+ *
+ * @param param parameters having model to be registered with additional
+ * informations provided by app
+ */
+ void unregisterModel(ModelRegistrationParam param);
+
+ /**
+ * Returns collection of all registered models.
+ *
+ * @return collection of models
+ */
+ Set<YangModel> getModels();
+}
diff --git a/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangRuntimeService.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangRuntimeService.java
new file mode 100644
index 0000000..745eaf5
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangRuntimeService.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2017-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.api;
+
+import org.onosproject.yang.model.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/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializer.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializer.java
new file mode 100644
index 0000000..3409d0b
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializer.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright 2017-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.api;
+
+import org.onosproject.yang.model.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/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerContext.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerContext.java
new file mode 100644
index 0000000..dbc543e
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerContext.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2017-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.api;
+
+/**
+ * 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/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerRegistry.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerRegistry.java
new file mode 100644
index 0000000..1d1b335
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/YangSerializerRegistry.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2017-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.api;
+
+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/api/src/main/java/org/onosproject/yang/runtime/api/package-info.java b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/package-info.java
new file mode 100644
index 0000000..5a0f954
--- /dev/null
+++ b/runtime/api/src/main/java/org/onosproject/yang/runtime/api/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2017-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.api;
\ No newline at end of file