...
- 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 (stores.yang) | Statements and Description |
---|
Code Block |
---|
language | text |
---|
linenumbers | true |
---|
| 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 - 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:
see examples from Lines 2-16 - yang-version statement
- namespace statement prefix statement
- revision statements
typedef Statement see example from Line 12 - a statement that allows a new type to be defined based on a base type which is a YANG built-in type
container Statement see example from Line 18 - defines interior (container node) in the schema tree
- only contains child nodes, has no value
- child nodes can be a leaf, lists, containers and leaf-lists
leaf Statement see example from Line 27 - defines a leaf node in the schema tree
- its only one argument is the identifier
- has no child nodes, has one value of a particular type
- 'type statement' is mandatory
- See optional substatements available in (Section 7.6 https://www.hjp.at/doc/rfc/rfc6020.html#sec_1)
list Statement see example from Line 35 - defines an interior data node (list node) in the schema tree
- its only one argument is the identifier
- follows a block of substatements:
- mandatory substatements:
leaf-list Statement see example from Line 41 - array of leaf nodes
- one value of a particular type per leaf
- its only one argument is the identifier
|
...
Code Block |
---|
language | xml |
---|
title | 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 |
---|
Code Block |
---|
language | yml |
---|
linenumbers | true |
---|
| 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;
}
….
} |
| extension Statement Code Block |
---|
| extension <keyword/identifier>{
<extension substatements...>
} |
|
![](https://lf-onap.atlassian.net/wiki/download/thumbnails/16494855/image2022-1-19_8-41-6.png?version=1&modificationDate=1642581659000&cacheVersion=1&api=v2&width=900)
![](https://lf-onap.atlassian.net/wiki/download/thumbnails/16494855/image2022-1-19_8-42-5.png?version=1&modificationDate=1642581718000&cacheVersion=1&api=v2&width=900)
** the YIN version and Schema trees above are generated by YANG validator 'pyang'
...
- Contains interface which has methods to access data of a YANG extension statement