Home Search Center Intelligent Model Selection IP Encyclopedia

What Is YANG?

YANG is a data modeling language. The YANG model defines a hierarchical data structure, which can be used for operations based on network configuration management protocols (such as NETCONF/RESTCONF). The operations include configuration, status data, remote procedure calls (RPCs), and notifications. Compared with the SNMP model MIB, YANG is more hierarchical, can distinguish between configurations and status, and provides high extensibility.

Overview of the YANG Model

Positioned as a next-generation modeling language, YANG is used to build data models.

It is used to model the configuration data, status data, RPCs, and notifications used by network configuration management protocols (such as NETCONF and RESTCONF). YANG generates YANG models (also called YANG files) by describing data structures, data integrity constraints, and data operations.

YANG is defined in the following RFC standards:

  • RFC 6020: In 2010, the Internet Engineering Task Force (IETF) defined YANG for the first time. YANG is a data modeling language for NETCONF.
  • RFC 6021: In 2010, the IETF defined various data types commonly used in network communication technologies. This allows us to import and use predefined network data types without redefining them when building YANG models.
  • RFC 6991: In 2013, the IETF added data types to the YANG model on the basis of RFC 6021.
  • RFC 7950: In 2016, the IETF released YANG1.1 to correct ambiguity and defects in the initial version (RFC 6020).

Through ongoing standardization, YANG is gradually becoming a mainstream data description specification in the industry. Standards organizations, vendors, carriers, and OTTs all define their own YANG models. As shown in the following figure, the YANG model is integrated on the devices, which function as the servers. Network administrators can use NETCONF or RESTCONF to centrally manage, configure, and monitor various YANG-capable network devices, simplifying network O&M and reducing O&M costs.

Network management architecture based on NETCONF/RESTCONF and YANG
Network management architecture based on NETCONF/RESTCONF and YANG

Why Do We Use YANG?

In 2002, the Internet Architecture Board (IAB) called attention to SNMP's disadvantages in configuration management, triggering the emergence of NETCONF. Although the NETCONF protocol is standardized, the data content is not. As a result, a better modeling language — YANG — was developed, making the data model simpler and easier to understand.

Compared with the SNMP model MIB, YANG is more hierarchical, can distinguish between configurations and status, and provides high extensibility.

The following uses part of the if-mib file as an example. The MIB is a tiled table, in which all elements of an IfEntry are arranged side by side. This makes it impossible to distinguish between configuration data and status data.

       SYNTAX      IfEntry
       MAX-ACCESS  not-accessible
       STATUS      current
               "An entry containing management information applicable
               to a particular interface."
       INDEX   { ifIndex }

       ::= { ifTable 1 }

   IfEntry ::=
       SEQUENCE {
           ifIndex                 InterfaceIndex,
           ifDescr                 DisplayString,
           ifType                  IANAifType,
           ifMtu                   Integer32,
           ifSpeed                 Gauge32,
           ifPhysAddress           PhysAddress,
           ifAdminStatus           INTEGER,
           ifOperStatus            INTEGER,
           ifLastChange            TimeTicks,
           ifInOctets              Counter32,
           ifInUcastPkts           Counter32,
           ifInNUcastPkts          Counter32,  -- deprecated
           ifInDiscards            Counter32,
           ifInErrors              Counter32,
           ifInUnknownProtos       Counter32,
           ifOutOctets             Counter32,
           ifOutUcastPkts          Counter32,
           ifOutNUcastPkts         Counter32,  -- deprecated
           ifOutDiscards           Counter32,
           ifOutErrors             Counter32,
           ifOutQLen               Gauge32,    -- deprecated
           ifSpecific              OBJECT IDENTIFIER -- deprecated

The following briefly introduces the composition of the YANG model based on part of the huawei-ifm.yang content. The first part of the model describes the basic information about huawei-ifm.yang. For details about the fields, see the following table. Container, list, and leaf are YANG-defined model node types, which can be used to clearly divide layers.

Table 1-1 Elements of the YANG model




YANG constructs a data model as a module. The module name is the same as the YANG file name.

A module can import data from other modules and reference data from submodules.

Import of external modules ("import" and "include"): The "include" statement enables a module or submodule to reference materials in submodules, and the "import" statement enables references to materials defined in other modules.


Namespace of the module, which is a globally unique URI. Namespaces are used during XML encoding of data.


Abbreviation of a namespace, which must be unique.


Name of the organization to which YANG belongs.


Contact information of the YANG module developer.


Functions of the YANG module.


Version information of the YANG module, providing the version editing history of the module.


Container node, used to group related nodes into a subtree.


List node, used to define a sequence of list entries. Each entry is similar to a structure or record instance, and is uniquely identified by the values of its key leaf nodes (key values).


Leaf node, which contains simple data such as an integer or a character string.

YANG model example:

module huawei-ifm {
  namespace "urn:huawei:yang:huawei-ifm";
  prefix ifm;
  import huawei-pub-type {
    prefix pub-type;
    "Huawei Technologies Co., Ltd.";
    "Huawei Industrial Base
     Bantian, Longgang
     Shenzhen 518129
     People's Republic of China
     Website: http://www.huawei.com
     Email: support@huawei.com";
    "Common interface management, which includes the public configuration of interfaces.";
  revision 2020-06-10 {
      "Add units attribute.";
      "Huawei private.";
  container auto-recovery-times {
      "List of automatic recovery time configuration.";
    list auto-recovery-time {
      key "error-down-type";
      "Configure automatic recovery time.";
      leaf error-down-type {
        type error-down-type;
          "Cause of the error-down event.";
      leaf time-value {
        type uint32 {
          range "30..86400";
        units "s";
        mandatory true;
          "Delay for the status transition from down to up.";

You can use the pyang tool to convert a YANG model into the YANG tree view. In this view, the entire YANG model is displayed as a tree. In the tree, rw represents status data, and ro represents configuration data.

module: huawei-ifm
  +--rw ifm
     +--rw auto-recovery-times
     |  +--rw auto-recovery-time* [error-down-type]
     |     +--rw error-down-type    error-down-type
     |     +--rw time-value         uint32
     +--ro static-dimension-ranges
     |  +--ro static-dimension-range* [type]
     |     +--ro type             port-type
     |     +--ro chassis-range?   string
     |     +--ro slot-range?      string
     |     +--ro card-range?      string
     |     +--ro port-range?      string

From the preceding information, we can conclude that YANG has many advantages, such as it being easy to understand, hierarchical, modular, reusable, and extensible.


A device uses the YANG Independent Notation (YIN) model file to parse models. YIN is YANG expressed in XML format. YIN and YANG use different representation methods but contain equivalent information.

Conversion between YANG and YIN
Conversion between YANG and YIN

YIN is used to leverage existing tools such as XML parsers in various programming languages. These tools can be used to filter and verify data and automatically generate code and files or other tasks, improving the efficiency of parsing YANG models.

Example of a Simple YANG Message

The following example shows how to query an interface configuration of the IFM feature in the configuration database and return the interface information in an RPC reply message.

  • RPC request

    <?xml version="1.0" encoding="utf-8"?>
    <rpc xmlns="urn:ietf:params:xml:ns:netconf:base:1.0" message-id="831">
        <filter type="subtree">
          <ifm:ifm xmlns:ifm="urn:huawei:yang:huawei-ifm">
  • RPC reply: The configuration of 10GE1/0/1 is queried and returned.

    <?xml version="1.0" encoding="utf-8"?>
    <data xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
      <ifm xmlns="urn:huawei:yang:huawei-ifm">

Obtaining Huawei YANG

Currently, Huawei devices support the following YANG models:

  • HUAWEI-YANG: Huawei proprietary YANG model. The model name starts with huawei.
  • IETF-YANG: public YANG model defined by the IETF. Generally, the model name starts with ietf, but some exceptions exist.
  • OPENCONFIG-YANG: public YANG model (also called OC YANG) defined by the standards organization OpenConfig. The model name starts with openconfig.

You can log in to the Huawei technical support website to obtain the YANG model:

  • For carrier users, log in to https://support.huawei.com and browse or search for the product name. On the Software tab page, select the required version and download the YANG file. Generally, the YANG file is named in the format ProductName VersionNumber yang.
  • For enterprise users, log in to https://support.huawei.com/enterprise/ and browse or search for the product name. On the Software Download tab page, select the required version and download the YANG file. Generally, the YANG file is named in the format ProductName VersionNumber yang.
About This Topic
  • Author: Huang Gang
  • Updated on: 2021-09-30
  • Views: 20803
  • Average rating:
Share link to