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 storessync-enxtension {
…
prefix booksync-storeex;
…
   extension sync-flag{
     description
           “This is a sample extension statement description“
      argument "value";
   }
container bookstore { 
        leaf bookstore-name {
            type string;
        }
….
}



Code Block
languageyml
titleextended-stores model
linenumberstrue
module extended-stores {
    yang-version 1.1;
	...
    import storessync-extension{
	    prefix booksync-storeex;
	}

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

    container bookstore {
        book-store:sync-flag "on";
    ...
	}
}
   




extension Statement

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

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


  • Usage

see example from 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 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
titleYIN-extended-stores model
linenumberstrue
<?xml version="1.0" encoding="UTF-8"?>
<module name="extended-stores"
        xmlns="urn:ietf:params:xml:ns:yang:yin:1"
        xmlns:ext-book-store="org:onap:ccsdk:sampleExtended"
        xmlns:book-store="org:onap:ccsdk:sample">
  <namespace uri="org:onap:ccsdk:sampleExtended"/>
  <prefix value="ext-book-store"/>
  <revision date="2020-09-15">
    <description>
      <text>Sample Extended Model</text>
    </description>
  </revision>
  <import module="stores">
    <prefix value="book-store"/>
  </import>
  <typedef name="year">
    <type name="uint16">
      <range value="1000..9999"/>
    </type>
  </typedef>
  <container name="bookstore">
    <book-store:sync-flag value="on"/>
    <leaf name="bookstore-name">
      <type name="string"/>
    </leaf>
	...
  </container>
</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


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>
      ...




...