Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Addresses: 

Jira
serverONAP JIRA
serverId425b2b0a-557c-3c0c-b515-579789cceedb
keyCPS-287

YANG

...

schema mount mechanism overview

The YANG schema mount mechanism is described in RFC-8528.

In opposite to standard YANG's "use" and "augment" the schema mount mechanism allows the model modification at runtime. 
While parent (extendable) module require to define the mount point(s) any already defined (legacy) module (including standard)
can be used as a mounted model.

draw.io Diagram
borderfalse
diagramNamecps-schema-mount-simplified-diagram
simpleViewerfalse
width
linksauto
tbstyleinline
diagramDisplayName
lboxfalse
diagramWidth481
revision5

The ietf-yang-schema-mount module defined in RFC-8528 defines structures for following entities:

...

Below is example of simple mount-point definition within a YANG module

Code Block
themeMidnight
titletest-mount.yang
module test-mount {
    yang-version 1.1;
    namespace "org:onap:cps:test-mount";
    prefix tmount;
    revision "2020-02-02";

    import ietf-yang-schema-mount {
         prefix yangmnt;
    }

    container root-element {
        yangmnt:mount-point "root-mp";
	}
}

...

Below is example of schema-mount data set JSON referencing model to be taken from a library:

Code Block
titleschema-mount.json
{
  "ietf-yang-schema-mount:schema-mounts": {
    "mount-point": [{
        "module": "test-mount",
        "label": "root-mp",
        "shared-schema": {}
       }]
  }
}


Addressing mounted modules

Mounted model can be addressed the one of the following ways:

...

Code Block
titleyang-library-exaample.json
{ 
  "ietf-yang-library:yang-library": {
     "content-id": "14e2ab5dc325f6d86f743e8d3ade233f1a61a899some-id",
     "module-set": [
        {
          "name": "module-set",
          "module": [
              {
                "name": "mounted-module",
                "revision": "2020-02-02",
                "namespace": "urn:org:onap:cps:test:mounted-module"
              },
              // other modules 
           ]
         }
      ]
     // other modules                          ]                  }          }}

...

}
}

So the data on model dependencies will be as shown on diagram

draw.io Diagram
borderfalse
diagramNamecps-yang-mount-dependencies-diagram
simpleViewerfalse
linksauto
tbstyleinline
lboxfalse
diagramWidth631
revision2


Inline (data embedded) reference

The reference to mounted module could be embedded directly into mount point and delivered together with a data.
The mounted module reference is expected to be described as ietf-yang-library component

Code Block
titleschema-mount.json
{
  "ietf-yang-schema-mount:schema-mounts": {
    "mount-point": [{
        "module": "test-mount",
        "label": "root-mp",
        "inline": {}
       }]
  }
}

The data then will look like below

Code Block
titledata-referencing-mounted-module-inline.json
{
  "test-mount:root-element": { 
    "root-mp": { // mount point
	   "ietf-yang-library:modules-state": { // mounted module (and dependencies) descriptor
          "module-set-id": "some-id",
          "module": [{
               "name": "mounted-module",
               "revision": "2020-02-02",
               "namespace": "urn:org:onap:cps:test:mounted-module",
               "conformance-type": "import"
            }
            // other modules
            ]
	    },
        "mounted-module:mounted-container": { // actual mounted module data
			// data associated to mounted module
		}
    }
  }
}


Reference by xpath

If the parent (extendable) module already contains references to mountable modules (i.e. other module imports) 
then the required module(s) can be mounted via xpath reference.

Code Block
themeMidnight
titletest-mount.yang
module test-mount {
    yang-version 1.1;
    namespace "org:onap:cps:test-mount";
    prefix tmount;
    revision "2020-02-02";

    import ietf-yang-schema-mount {
         prefix yangmnt;
    }
	import mounted-module {
		prefix mntm;
    }

    container root-element {
        yangmnt:mount-point "root-mp";
	}
}

The schema-mount  

Code Block
titleschema-mount.json
{
  "ietf-yang-schema-mount:schema-mounts": {
	 "namespace": [{
        "prefix": "mntm",
        "uri": "urn:org:onap:cps:test:mounted-module"
     }],
     "mount-point": [{
        "module": "test-mount",
        "label": "root-mp",
        "shared-schema": {
             "parent-reference": ["/mntm:mounted-container"]
         }
     }]
   }
}


Other examples

The examples of schema mounts can be also found  on following resources


Schema mount support in a context of CPS

The abilities of CPS regarding YANG model and associated data parsing is heavily dependent on
features provided by ODL YangTools library.

In current implementation following yangtools components are involved:

  • YANG Parser (Reactor) - builds a SchemaContext object, which holds a static model definitions
  • Data Parser (JSON) - converts incoming data into structured tree object using SchemaContext instance as a dictionary

Yang Parser

YANG parser already supports the mount-point definition. Minimal changes are required on CPS side in order to support
mount-point to accept it as a valid statement:

Code Block
languagejava
titleYangTextSchemaSourceSetBuilder
 import org.opendaylight.yangtools.rfc8528.parser.MountPointStatementSupport;
 // ...
 
 private static SchemaContext generateSchemaContext(final Map<String, String> yangResourceNameToContent) {
        final CrossSourceStatementReactor.BuildAction reactor = RFC7950Reactors.vanillaReactorBuilder()
            .addStatementSupport(ModelProcessingPhase.FULL_DECLARATION, MountPointStatementSupport.getInstance())
            .build().newBuild();
 //...
        return reactor.buildEffective();
 //...
 }

Taken from MountPointTest @ git.opendaylight.org

Data Parser

There is no issue parsing the actual schema-mounts JSON. It just treats the JSON as data and converts it into NormalizedNode instance.
The problem is the schema-mount JSON is not a data, it's an instruction to server to modify the model it holds runtime. Unfortunately
taking into account the context (separating a treating differently the actual data from the instruction) in not fully implemented yet.

Currently the ODL Yangtools library supports schema-mount for XML parser only (not JSON one). The schema-mount instruction require to
be pre-processed into a MountPointContext object and passed to the parser as a context to be taken into account.

See XmlParserStream @ git.opendaylight.org

It means the MountPointContext is not a part of SchemaContext which holds a static information on YANG resources involved, but a 
runtime context used on data parsing. 

Schema mount support for JSON parser was requested via https://jira.opendaylight.org/browse/YANGTOOLS-1267


Analysis summary

  • While schema-mounts is only supported by XML data parser for now it will require either awaiting (request) for similar functionality
    to be implemented in JSON parser or to provide own JSON parser which supports it (significant extra effort).
  • CPS requires additional logic and persistence layer update in order to support YANG schema/library management requests like
    data implementing ietf-yang-schema-mount and/or ietf-yang-library
  • CPS requires mechanism to store and retrieve on data parse the MountPointContext based on schema-mounts updates.