Professional Documents
Culture Documents
Mgmt Application
YANG modules
Devices
YANG is ….
Standard Proprietary
Models Models
containers
leafs
types
YANG ....
Semantic
World YANG
Syntactic
XML Schema Relax-NG Anything Else
World
Out
Legacy tools
Validation going
XML
YANG values ....
import "yang-types" {
prefix yang;
}
include "acme-system";
revision 2007-06-09 {
description "Initial revision.";
}
…
}
The "leaf" Statement
A leaf has
one value
no children
YANG Example:
one instance
leaf host-name {
type string;
mandatory true;
config true;
description "Hostname for this system";
}
NETCONF XML Encoding:
<host-name>my.example.com</host-name>
The "leaf-list" Statement
A leaf-list has
one value
YANG Example: no children
leaf-list domain-search {
multiple instances
type string;
ordered-by user;
description "List of domain names to search";
}
<domain-search>high.example.com</domain-search>
<domain-search>low.example.com</domain-search>
<domain-search>everywhere.example.com</domain-search>
The "container" Statement
A container has
YANG Example:
no value
container system {
container services { holds related children
container ssh { one instance
presence "Enables SSH";
description "SSH service specific configuration";
// more leafs, containers and stuff here...
}
}
} May have specific meaning
NETCONF XML Encoding: (presence)
<system>
Or may simply contain
<services> other nodes
<ssh/>
</services>
</system>
The "must" Statement
Constrains nodes by
container timeout {
XPath expression
leaf access-timeout {
description "Maximum time without server response";
units seconds;
mandatory true;
type uint32;
}
leaf retry-timer {
description "Period to retry operation";
units seconds;
type uint32;
must "$this < ../access-timeout" {
error-app-tag retry-timer-invalid;
error-message "The retry timer must be "
+ "less than the access timeout";
}
}
}
The "list" Statement A list is
uniquely identified
by key(s)
YANG Example:
holds related
children
list user { no value
key name; NETCONF XML Encoding:
multiple instances
leaf name {
type string; <user>
} <name>glocks</name>
leaf uid { <full-name>Goldie</full-name>
type uint32; <class>intruder</class>
} </user>
leaf full-name { <user>
type string; <name>snowey</name>
} <full-name>Snow</full-name>
leaf class { <class>free-loader</class>
type string; </user>
default viewer; <user>
} <name>rzull</name>
} <full-name>Repun</full-name>
</user>
The "augment" Statement
Extends data model
YANG Example: Current or imported
modules
augment system/login/user {
leaf expire { Inserts nodes
type yang:date-and-time;
Into an existing hierarchy
}
} Nodes appear in current
module's namespace
Original (augmented)
module is unchanged
NETCONF XML Encoding:
<user>
<name>alicew</name>
<class>drop-out</class>
<other:expire>2112-04-01T12:00:00</other:expire>
</user>
The "when" Statement
YANG Example:
Makes sparse
augment system/login/user { augmentation
when "class = wheel";
leaf shell {
Nodes are only
type string; added when
} condition is true
} "when" is XPath
expression
NETCONF XML Encoding:
<user>
<name>alicew</name>
<class>wheel</class>
<other:shell>/bin/tcsh</other:shell>
</user>
Built-in types
Category Types
Integral {,u}int{8,16,32,64}
String string, enumeration, boolean
Binary Data binary
Bit fields bits
References instance-identifier, keyref
Other empty
Derived types
YANG Example:
Constraints
typedef percent {
range
type uint16 {
range "0 .. 100"; length
} pattern
description "Percentage";
} • regex
A modules may use
leaf completed {
type percent; types imported from
}
NETCONF XML Encoding:
other modules
<completed>20</completed>
The "union" type
YANG Example: Allows a leaf to
leaf limit {
contain a
description "Number to allow"; superset of
type union {
type uint16 { types
range "0 .. 100";
}
type enumeration {
enum none {
NETCONF XML Encoding:
description "No limit";
}
<limit>none</limit>
}
}
} NETCONF XML Encoding:
<limit>20</limit>
The "grouping" Statement
Defines a reusable
YANG Example collection of nodes
grouping target { Use multiple times
leaf address { A modules may use
type inet:ip-address; groupings imported
description "Target IP address";
from other modules
}
leaf port { Refinement
type inet:ip-port;
description "Target port number"; Use as structure,
} record, or object
}
container peer { NETCONF XML Encoding:
container destination {
uses target; <peer>
} <destination>
} <address>192.0.2.1</address>
<port>22</port>
</destination>
</peer>
The "choice" Statement
Allow only one member
of the choice to exist in a
YANG Example:
valid config datastore
choice transfer-method {
leaf transfer-interval {
description "Frequency at which file transfer happens";
type uint {
range "15 .. 2880";
}
units minutes;
}
leaf transfer-on-commit {
description "Transfer after each commit";
type empty;
NETCONF XML Encoding:
}
}
<transfer-on-commit/>
The "anyxml" Statement
YANG Example: Allows arbitrary
anyxml software-version {
XML content to be
description "Number to allow"; carried in YANG-
}
based models
Opaque
Limited operations
NETCONF XML Encoding:
• Bulk only
<software-version>
<base>A10.2</base>
<routing>B4.2</routing>
<snmp>C87.12</snmp>
</software-version>
The "rpc" Statement
rpc activate-software-image {
input { Defines RPC
leaf image-name { method names
type string;
} input parameters
} output parameters
output {
leaf status {
type string;
}
}
<rpc xmlns="urn:mumble">
}
<activate-software-image>
<image-name>image.tgz</image-name>
</activate-software-image>
</rpc>
The "notification" Statement
Defines notification
YANG Example: Name
Content
notification link-failure {
description "A link failure has been detected";
leaf if-index {
type int32 { range "1 .. max"; }
}
leaf if-name {
type keyref {
path "/interfaces/interface/name";
}
}
}
Semantic Differentiators
pyang (python)
Validates YANG
Translates between YANG and YIN (XML)
Generates XSD
yangto (binary)
Validates YANG
Generates XSD, dependencies, etc
libsmi
Translates SMI/SMIv2 MIBs to YANG
Other goodies
Emacs mode
What can you do to help?