You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Overview

The following study describes extending YANG language statements to allow customization of models.

References:

YANG Language

  • The YANG language provides us the ability to define and model configurations and state data by defining YANG modules
    • Modules contain a sequence of statements
      • Statement syntax is either of the following :
        • statement = keyword [argument] ;
        • statement = keyword [argument] { <substatement(s)..> } ;

* argument can be zero or one depending on the statement

* argument is a string

  • An XML-based equivalent version of YANG is called YIN
  • YANG uses a tree to define the hierarchy of data wherein each ‘node’ has a value or/and a set of child nodes
    • 4 types of nodes
      • container nodes
      • list nodes 
      • leaf nodes
      • leaf-list nodes
Sample YANG (store.yang)Statements and Description
module stores {
    yang-version 1.1;
    namespace "org:onap:ccsdk:sample";

    prefix book-store;

    revision "2020-09-15" {
        description
        "Sample Model";
    }

    typedef year {
        type uint16 {
            range "1000..9999";
        }
    }

    container bookstore { 

        leaf bookstore-name {
            type string;
        }
    list categories {

        key "code";

        leaf code {	
            type string;
        }

        leaf name {
            type string;
        }

        list books {
            key title;

            leaf title {
                type string;
            }
            leaf-list authors {
                type string; 
            }
        }
    }
    }
}

module Statement

  • YANG language defines models with modules and submodules
  • Takes one argument (module name) which is the identifier
  • Groups all statements that belong to the module
  • This module example contains the following statements for header information:
    • yang-version statement
    • namespace statement
    • prefix statement
    • revision statements






Figure 1.1 Schema tree of module 'stores'

Schema tree of module stores
 

stores module schema tree


YANG extension Statement

** the YIN version and Schema trees above are generated by YANG validator 'pyang'

Expected tree diagram for example-module based on RFC8340 (https://datatracker.ietf.org/doc/html/rfc8340):

Diagram 6



Existing YANG parser

(Please see https://wiki.onap.org/display/DW/Existing+Yang+Parser)

OpenDayLight Yang tools recognises YANG extensions

  • Contains interface which has methods to access data of a YANG extension statement
    • package org.opendaylight.yangtools.yang.model.api;
      import org.opendaylight.yangtools.yang.model.api.stmt.ExtensionEffectiveStatement;
      public interface ExtensionDefinition extends SchemaNode, EffectiveStatementEquivalent<ExtensionEffectiveStatement> {
      String getArgument();
      boolean isYinElement();
      }
      • Implementing Class
        • Class






  • No labels