Versions Compared

Key

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

...

Sample YANG

(stores.yang with extension)

Statements and Description


Code Block
languageyml
titlestores model with extension
linenumberstrue
module stores {
…
prefix book-store;
…
   extension sampleExtensionsync-flag{
     description
           “This is a sample extension statement description“
      argument name {
          yin-element true"value";
     }

  }
container bookstore { 
        leaf bookstore-name {
            type string;
        }
….
}



Code Block
languageyml
titleexampleextended-module2 stores model
linenumberstrue
module example-module2{
…
     import extended-stores {
       prefix book-store;
yang-version 1.1;
	...
    }import stores{
	    prefix book-store:sampleExtension locations {
       list address {
         key "state";
;
	}

    typedef   leaf stateyear {

          type string;
           description "State name"uint16 {
               book-store:sampleExtension-b "b-sample-name";
  range "1000..9999";
        }
    
    }

    container bookstore   leaf city {
           type string;
           description "City name"{
               book-store:sampleExtensionsync-cflag "c-sample-nameon";
           }
….
   ...
	}
}
 
 




extension Statement

see example from Lines 5-11 9 on stores model with extension

  • Syntax
Code Block
languagetext
extension <keyword/identifier>{
     <extension substatements...>
}


  • Usage

see example from Lines Line 15 on extended-stores model

Code Block
languagetext
<module prefix>:<extension keyword> "argument";


  • to be used to define new statements
  • available to be imported and used by other modules just like a normal YANG statement
      • by use of 'import statement' to import the module where the extension is defined
  • statements that do not have any substatements can have extensions defined if wanted
  • its only one argument is the identifier and keyword for the extension
  • Optional substatements:
      • argument Statement
      • description Statement
      • reference Statement
      • defined extension Statements








argument Statement

see examples from Lines Line 6 on stores model

  • takes a string argument which is the name of the argument to the keyword
  • Optional substatement
      • yin-element Statement




Code Block
languagexml
themeMidnight
titleexampleYIN-extended-model2 stores model (YIN version)
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<module name="exampleextended-module2stores"
        xmlns="urn:ietf:params:xml:ns:yang:yin:1"
        xmlns:emext-book-store="org:onap:ccsdk:sample2sampleExtended"
        xmlns:book-store="org:onap:ccsdk:sample">
  <yang-version value="1.1"/>
  <namespace uri="org:onap:ccsdk:sample2sampleExtended"/>
  <prefix value="emext-book-store"/>
  <import<revision moduledate="stores2020-09-15">
    <description>
 <prefix value="book-store"/>   </import> <text>Sample  <book-store:sampleExtension>Extended Model</text>
    <book-store:name>locations</book-store:name></description>
  </revision>
  <list<import namemodule="addressstores">
      <key<prefix value="statebook-store"/>
  </import>
   <leaf<typedef name="stateyear">
   
    <type name="stringuint16"/>
      <range  <description>value="1000..9999"/>
    </type>
      <text>State name</text></typedef>
     <container name="bookstore">
    <book-store:sampleExtensionsync-bflag namevalue="b-sample-nameon"/>
        </description>
      </leaf>
 
    <leaf name="citybookstore-name">
        <type name="string"/>
        <description>
          <text>City name</text>
          <book-store:sampleExtension-c>
            <book-store:name>c-sample-name</book-store:name>
          </book-store:sampleExtension-c>
   
    </description>
      </leaf>
 	...
  </list>container>
  </book-store:sampleExtension>
</module>


yin-element Statement

  • takes a string argument which is true or false
  • yin-element is 'false' by default
  • if the argument is 'true' it indicates that the argument is mapped to an XML element in YIN or to an XML attribute
  1. Line 

** 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):

...

languagetext
titleSchema tree for sampleExtension

...


Notes

  1. Line 22 on YIN-extended-stores model
    1. result of using the argument without specifying the yin-element value
      1. yin-element is 'false'
      2. the argument 'value' is only an XML attribute
  2. if argument statement (Line 6 on stores model) contains yin-element substatement YIN-extend-stores model would result to the following:
    1. extension statement will produce a child node

      Code Block
      themeMidnight
      titleYIN-extended-stores model where yin-element is 'true'
      ...
        <container name="bookstore">
          <book-store:sync-flag>
            <book-store:value>on</book-store:value>
          </book-store:sync-flag>
      ...
        </container>
      ...




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

Existing YANG parser in CPS

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

OpenDayLight Yang tools recognises recognise YANG extensions

  • Contains interface which has methods to access data of a YANG extension statement

    Code Block
    languagejava
    themeEclipse
    titleYang tools ExtensionDefinition Interface
    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 ClassClass