Versions Compared

Key

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

...

Sample YANG

(stores.yang with extension)

Statements and Description
  • stores model
Code Block
languageyml
linenumberstrue
module stores {
…
prefix book-store;
…
   extension sampleExtension{
     description
           “This is a sample extension statement description“
      argument name {
          yin-element true;
     }
   }
container bookstore { 
        leaf bookstore-name {
            type string;
        }
….
}


  • example-module2 model
Code Block
languageyml
linenumberstrue
module example-module2{
…
     import stores {
       prefix book-store;
     }

     book-store:sampleExtension locations {
       list address {
         key "state";
         leaf state {
           type string;
           description "State name"{
               book-store:sampleExtension-b "b-sample-name";
           }
         }
         leaf city {
           type string;
           description "City name"{
               book-store:sampleExtension-c "c-sample-name";
           }
….
   }





extension Statement

see example from Lines 5-11 on stores model

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


  • Usage

see example from Lines 

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 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
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<module name="example-module2"
        xmlns="urn:ietf:params:xml:ns:yang:yin:1"
        xmlns:em="org:onap:ccsdk:sample2"
        xmlns:book-store="org:onap:ccsdk:sample">
  <yang-version value="1.1"/>
  <namespace uri="org:onap:ccsdk:sample2"/>
  <prefix value="em"/>
  <import module="stores">
    <prefix value="book-store"/>
  </import>
  <book-store:sampleExtension>
    <book-store:name>locations</book-store:name>
    <list name="address">
      <key value="state"/>
      <leaf name="state">
        <type name="string"/>
        <description>
          <text>State name</text>
          <book-store:sampleExtension-b name="b-sample-name"/>
        </description>
      </leaf>
      <leaf name="city">
        <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>
  </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 

Image Removed

Image Removed

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


Code Block

...

language

...

text
sampleExtension locations:
     +-- address* [state]
        +-- state string
        +-- city? string

...



Existing YANG parser

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

...