Help us improve your experience.

Let us know what you think.

Do you have time for a two-minute survey?

 

YANG Modules Overview

 

YANG data models comprise modules and submodules and can define configuration and state data, notifications, and RPCs for use by NETCONF-based operations. A YANG module defines a data model through its data, and the hierarchical organization of and constraints on that data. Each module is uniquely identified by a namespace URI.

A module defines a single data model. However, a module can reference definitions in other modules and submodules by using the import statement to import external modules or the include statement to include one or more submodules. Additionally, a module can augment another data model by using the augment statement to define the placement of the new nodes in the data model hierarchy and the when statement to define the conditions under which the new nodes are valid. A module uses the feature statement to specify parts of a module that are conditional and the deviation statement to specify where the device’s implementation might deviate from the original definition.

When you import an external module, you define a prefix that is used when referencing definitions in the imported module. We recommend that you use the same prefix as that defined in the imported module to avoid conflicts.

YANG models data using a hierarchical, tree-based structure with nodes. YANG defines four nodes types. Each node has a name, and depending on the node type, the node might either define a value or contain a set of child nodes. The nodes types are:

  • leaf node—Contains a single value of a specific type

  • leaf-list node—Contains a sequence of leaf nodes

  • container node—Contains a grouping of related nodes containing only child nodes, which can be any of the four node types

  • list node—Contains a sequence of list entries, each of which is uniquely identified by one or more key leafs

In YANG, each leaf and leaf-list node includes the type statement to identify the data type for valid data for that node. YANG defines a set of built-in types and also provides the typedef statement for defining a derived type from a base type, which can be either a built-in type or another derived type.

By default, a node defines configuration data. A node defines state data if it is tagged as config false. Configuration data is returned using the NETCONF <get-config> operation, and state data is returned using the NETCONF <get> operation.