Octet

What is YANG, and what are containers, lists and leafs?

Show the answer

Say this first

YANG is a data modeling language (RFC 6020, version 1.1 in RFC 7950). It defines the structure, types and rules of configuration and state data, so a client knows exactly what a device accepts. It is not a protocol and not an encoding: NETCONF, RESTCONF and gNMI carry YANG-modeled data as XML, JSON or protobuf. A container groups nodes, a list holds entries identified by a key, a leaf holds one typed value and a leaf-list holds several values.

Go deeper

A small model

Output
module example-vlans {
  namespace "urn:example:vlans";
  prefix exv;

  container vlans {
    list vlan {
      key "id";
      leaf id {
        type uint16 {
          range "1..4094";
        }
      }
      leaf name {
        type string;
      }
      leaf-list tagged-ports {
        type string;
      }
    }
  }
}

The building blocks

StatementWhat it is
moduleThe file-level unit, with a namespace and prefix
containerA grouping node with no value of its own (interfaces)
listRepeating entries, each identified by key (interface keyed by name)
leafOne value with a type (description, mtu)
leaf-listMany values of one type (DNS servers)
typedef, grouping, usesReusable types and blocks
augmentAdds nodes into another module's tree (how vendors extend IETF models)
config falseMarks operational state (counters, oper-status), read-only
rpc, action, notificationOperations and events

Why engineers care

The model tells you the path and type before you send anything. The device validates input against it, so id: 5000 fails cleanly instead of half applying. And the same model works over NETCONF, RESTCONF and gNMI.

Traps

  • Saying YANG is XML. YANG has its own syntax; XML and JSON are encodings of data that follows the model.
  • Confusing YANG with SNMP MIBs. Both are models, but MIBs (SMIv2) are mostly read-only and tied to SNMP.
How did you do?Book 9.3 Infrastructure Applications