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.

  ifEntry OBJECT-TYPE
       SYNTAX      IfEntry
       MAX-ACCESS  not-accessible
       STATUS      current
       DESCRIPTION
               "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

Element

Description

module

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

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

prefix

Abbreviation of a namespace, which must be unique.

organization

Name of the organization to which YANG belongs.

contact

Contact information of the YANG module developer.

description

Functions of the YANG module.

revision

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

container

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

list

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

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;
  }
  organization
    "Huawei Technologies Co., Ltd.";
  contact
    "Huawei Industrial Base
     Bantian, Longgang
     Shenzhen 518129
     People's Republic of China
     Website: https://www.huawei.com
     Email: support@huawei.com";
  description
    "Common interface management, which includes the public configuration of interfaces.";
  revision 2020-06-10 {
    description
      "Add units attribute.";
    reference
      "Huawei private.";
  }
  container auto-recovery-times {
    description
      "List of automatic recovery time configuration.";
    list auto-recovery-time {
      key "error-down-type";
      description
      "Configure automatic recovery time.";
      leaf error-down-type {
        type error-down-type;
        description
          "Cause of the error-down event.";
      leaf time-value {
        type uint32 {
          range "30..86400";
        }
        units "s";
        mandatory true;
        description
          "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.

YANG and YIN

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">
      <get>
        <filter type="subtree">
          <ifm:ifm xmlns:ifm="urn:huawei:yang:huawei-ifm">
            <ifm:interfaces>
              <ifm:interface/>
            </ifm:interfaces>
          </ifm:ifm>
        </filter>
      </get>
    </rpc>
  • 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">
        <interfaces>
          <interface>
            <name>10GE1/0/1</name>
            <index>4</index>
            <class>main-interface</class>
            <type>10GE</type>
            <position>0/0/0</position>
            <number>1/0/1</number>
            <admin-status>up</admin-status>
            <link-protocol>ethernet</link-protocol>
            <statistic-enable>true</statistic-enable>
            <mtu>1500</mtu>
            <spread-mtu-flag>false</spread-mtu-flag>
            <vrf-name>_public_</vrf-name>
            <dynamic>
              <oper-status>up</oper-status>
              <physical-status>up</physical-status>
              <link-status>up</link-status>
              <mtu>1500</mtu>
              <bandwidth>100000000</bandwidth>
              <ipv4-status>up</ipv4-status>
              <ipv6-status>down</ipv6-status>
              <is-control-flap-damp>false</is-control-flap-damp>
              <mac-address>00e0-fc12-3456</mac-address>
              <line-protocol-up-time>2019-05-25T02:33:46Z</line-protocol-up-time>
              <is-offline>false</is-offline>
              <link-quality-grade>good</link-quality-grade>
            </dynamic>
            <mib-statistics>
              <receive-byte>0</receive-byte>
              <send-byte>0</send-byte>
              <receive-packet>363175</receive-packet>
              <send-packet>61660</send-packet>
              <receive-unicast-packet>66334</receive-unicast-packet>
              <receive-multicast-packet>169727</receive-multicast-packet>
              <receive-broad-packet>127122</receive-broad-packet>
              <send-unicast-packet>61363</send-unicast-packet>
              <send-multicast-packet>0</send-multicast-packet>
              <send-broad-packet>299</send-broad-packet>
              <receive-error-packet>0</receive-error-packet>
              <receive-drop-packet>0</receive-drop-packet>
              <send-error-packet>0</send-error-packet>
              <send-drop-packet>0</send-drop-packet>
            </mib-statistics>
            <common-statistics>
              <stati-interval>300</stati-interval>
              <in-byte-rate>40</in-byte-rate>
              <in-bit-rate>320</in-bit-rate>
              <in-packet-rate>2</in-packet-rate>
              <in-use-rate>0.01%</in-use-rate>
              <out-byte-rate>0</out-byte-rate>
              <out-bit-rate>0</out-bit-rate>
              <out-packet-rate>0</out-packet-rate>
              <out-use-rate>0.00%</out-use-rate>
              <receive-byte>0</receive-byte>
              <send-byte>0</send-byte>
              <receive-packet>363183</receive-packet>
              <send-packet>61662</send-packet>
              <receive-unicast-packet>66334</receive-unicast-packet>
              <receive-multicast-packet>169727</receive-multicast-packet>
              <receive-broad-packet>127122</receive-broad-packet>
              <send-unicast-packet>61363</send-unicast-packet>
              <send-multicast-packet>0</send-multicast-packet>
              <send-broad-packet>299</send-broad-packet>
              <receive-error-packet>0</receive-error-packet>
              <receive-drop-packet>0</receive-drop-packet>
              <send-error-packet>0</send-error-packet>
              <send-drop-packet>0</send-drop-packet>
              <send-unicast-bit>0</send-unicast-bit>
              <receive-unicast-bit>0</receive-unicast-bit>
              <send-multicast-bit>0</send-multicast-bit>
              <receive-multicast-bit>0</receive-multicast-bit>
              <send-broad-bit>0</send-broad-bit>
              <receive-broad-bit>0</receive-broad-bit>
              <send-unicast-bit-rate>0</send-unicast-bit-rate>
              <receive-unicast-bit-rate>0</receive-unicast-bit-rate>
              <send-multicast-bit-rate>0</send-multicast-bit-rate>
              <receive-multicast-bit-rate>0</receive-multicast-bit-rate>
              <send-broad-bit-rate>0</send-broad-bit-rate>
              <receive-broad-bit-rate>0</receive-broad-bit-rate>
              <send-unicast-packet-rate>0</send-unicast-packet-rate>
              <receive-unicast-packet-rate>0</receive-unicast-packet-rate>
              <send-multicast-packet-rate>0</send-multicast-packet-rate>
              <receive-multicast-packet-rate>0</receive-multicast-packet-rate>
              <send-broadcast-packet-rate>0</send-broadcast-packet-rate>
              <receive-broadcast-packet-rate>0</receive-broadcast-packet-rate>
            </common-statistics>
          </interface>
      </ifm>
    </data>

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: 2024-02-27
  • Views: 33425
  • Average rating:
Share link to