Overview
The following study describes extending YANG language statements to allow customization of models.
References:
- - CPS-735Getting issue details... STATUS
- https://datatracker.ietf.org/doc/rfc8526/
- https://www.rfc-editor.org/rfc/rfc6095.html
- https://www.hjp.at/doc/rfc/rfc6020.html#sec_6.3.1
- https://docs.opendaylight.org/en/latest/release-notes/upgrade-process.html?highlight=extension%20annotation#unrecognized-yang-statement-handling
- https://datatracker.ietf.org/doc/html/rfc6110#section-9.4
- https://datatracker.ietf.org/doc/html/rfc8791
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)..> } ;
- Statement syntax is either of the following :
- Modules contain a sequence of statements
* 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
- 4 types of nodes
Sample YANG (stores.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 see example from Line 1
see examples from Lines 2-16
typedef Statement see example from Line 12
container Statement see example from Line 18
leaf Statement see example from Line 27
list Statement see example from Line 35
leaf-list Statement see example from Line 41
|
Figure 1.1 Schema tree of module 'stores'
module: stores +--rw bookstore +--rw bookstore-name? string +--rw categories* [code] +--rw code string +--rw name? string +--rw books* [title] +--rw title string +--rw lang? string +--rw authors* string +--rw pub_year? year +--rw price? uint64
YANG extension Statement
Sample YANG (stores.yang with extension) | Statements and Description |
---|---|
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; } …. }
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
extension <keyword/identifier>{ <extension substatements...> }
see example from Lines <module prefix>:<extension keyword> "argument";
argument Statement see examples from Lines on stores model
|
<?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
|
** 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):
sampleExtension locations: +-- address* [state] +-- state string +-- city? string
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
- Implementing Class