Versions Compared

Key

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

Status
subtletrue
colourYellow
titleWork in Progress

This page documents the existing Yang Parser used in ONAP and OpenDayLight and will investigate if they can be used for the C&PS.

Resources

*Although this documentation link is to the latest ODL doc revision, it is very outdated and the code examples need significant updates, see findings in Mini-PoC below (bug reported: https://jira.opendaylight.org/browse/DOCS-126)

Overview

The Yang parser used in ONAP (CCSDK / SDNC) was developed (and still is) a OpenDayLight Library.

There are 2 different usage patterns within CCSDK, though.

Most of CCSDK/SDNC is using Yang primarily to define their northbound interfaces. In that context, there’s a maven plugin (org.opendaylight.yangtools:yang-maven-plugin) that is used to generate source code from the Yang model. Our application code in that case doesn’t really do anything directly with the Yang, since all of the that is handled for us by the generated code.

In ccsdk/sli/plugins, there is a plugin called restconf-client which was contributed by Huawei. That code uses the yangtool parser more directly so that it can interpret the results being returned when it calls a restconf interface. 

Mini-PoC

To help this evaluation I will create a small sample project with the goal to pare a yang file using the ODL Yang Tools. I will report my findings here

Maven dependency

The documentation mentioned above lists many modules but the code examples do not clarify which exactly are needed to parse a Yang file in java code.

  • To be able to use yangtools teh project needs to use the mdsal 'binding-parent' pom
  • The module yang-parser-impl contains all code required to parse yang files
  • SLF4J has been added as the implementation requires a logger enabled
Code Block
languagexml
themeMidnight
titlepom.xml
collapsetrue
    <parent>
        <groupId>org.opendaylight.mdsal</groupId>
        <artifactId>binding-parent</artifactId>
        <version>3.0.8</version>
        <relativePath/>
    </parent>
	:
    <dependencies>
        <dependency>
            <groupId>org.opendaylight.yangtools</groupId>
            <artifactId>yang-parser-impl</artifactId>
            <version>5.0.3</version>
        </dependency>
        <!-- SLF4J API -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
        </dependency>
        <!-- LOG4J -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
        </dependency>
    </dependencies>

Documentation Code Updates

The sample code provided in the documentation is faulty (using == for assigning?!) and is using some long deprecated and even removed classes and methods.

Bug reported: https://jira.opendaylight.org/browse/DOCS-126

Code Block
languagejava
themeMidnight
titleCorrected Code
linenumberstrue
collapsetrue
        YangTextSchemaSource source = YangTextSchemaSource.forFile(new File("/example.yang"));
        StatementStreamSource yangModuleSource = YangStatementStreamSource.create(source);

        CrossSourceStatementReactor.BuildAction reactor = defaultReactor().newBuild();
        reactor.addSource(yangModuleSource);

        SchemaContext schemaContext = reactor.buildEffective();

        Set<Module> modules = schemaContext.getModules();
        Set<DataSchemaNode> dataSchemaNodes = schemaContext.getDataDefinitions();

This is the kind of object (module) that gets created:

Image Modified

Generated Java Object Structures per Yang concept

Object Structure

The SchemaContext object generated by the Yang Parser from a list of Yang files provided by the developer contains 1 or more Module, with 1 or more Grouping with one or more ChildNode (leaf)

Gliffy
macroId8eafa348-6609-4eae-a733-beb5a2766488
nameYang Parser Java Object View
pagePin1

Datatypes and constraints

DescriptionYangJava Object ViewNotes
Basic String

leaf response-code

...

{
  type string;
}

Image Added


Limited String leaf pnf-name

...

{
  type string {
    length "0..256";

...


}

...

Code Block
modules[]
+groupings[]
 +childNodes[,]
  +value
   +type = RestrictedStringType

Image Added

Specialized class to hold length limitation

Extensions