Interpret basic YANG models

📘Cisco DevNet Associate (200-901 DEVASC)


1. What is YANG?

  • YANG stands for Yet Another Next Generation.
  • It is a data modeling language used to describe network device configurations and state data in a structured way.
  • Think of it as a blueprint or schema that defines what data a network device can store and how it is organized.
  • YANG is mainly used with NETCONF and RESTCONF to automate network management.

Key idea: YANG is not the actual data, it describes the structure of the data that can be sent to or received from network devices.


2. Why YANG is Important in Networking

  • Allows automation tools (like Python scripts, Ansible, or Cisco DNA Center) to understand what data they can configure or read from a device.
  • Provides consistency in how devices represent data.
  • Makes it easier to validate and check network configurations automatically.

Example in IT: A YANG model can define the exact structure for a router interface configuration:

  • Interface name
  • IP address
  • Subnet mask
  • Status (up/down)

Automation tools will read the YANG model to know exactly what fields are required and what data is allowed.


3. YANG Data Model Structure

YANG models define data in a hierarchical (tree-like) structure, similar to folders and files on a computer.

Key Components of a YANG Model

  1. Module
    • A YANG file starts with a module.
    • The module gives a name and version for the set of configurations it defines.
    • Example: module cisco-interfaces { ... }
  2. Container
    • A container groups related data together (like a folder for related settings).
    • Example: interfaces container holds all interface configurations.
  3. Leaf
    • A leaf is an individual piece of data (like a file in a folder).
    • Example: name, ip-address, description.
  4. Leaf-list
    • A list of multiple leaves with the same type.
    • Example: multiple DNS server IP addresses for a router.
  5. List
    • A list contains multiple containers of the same type.
    • Example: a list of interfaces, where each interface has name, IP, and status.
  6. Choice and Case
    • Provides optional alternatives.
    • Example: an interface can have either a static IP configuration or a DHCP configuration.
  7. Type
    • Defines the data type for a leaf or leaf-list.
    • Examples: string, int32, boolean, enumeration.
  8. Augment
    • Allows extending existing models with additional data.
    • Useful when you need extra configurations not originally defined.

4. Understanding YANG through a Device Configuration Example

Imagine you want to configure interfaces on a network switch.

YANG Model (simplified):

module cisco-interfaces {
container interfaces {
list interface {
leaf name { type string; }
leaf ip-address { type string; }
leaf status { type enumeration { enum up; enum down; } }
}
}
}
  • Module: cisco-interfaces → defines interface settings.
  • Container: interfaces → groups all interfaces.
  • List: interface → multiple interfaces allowed.
  • Leaf: name, ip-address, status → actual settings for each interface.
  • Type: string or enumeration → defines allowed values.

Automation tools can read this model and know:

  1. You must provide a name for the interface.
  2. Status can only be up or down.
  3. Multiple interfaces can be configured in a list.

5. Key YANG Concepts for the Exam

ConceptWhat it MeansExample in IT
ModuleA YANG file containing a set of configurationscisco-interfaces
ContainerGroups related configurationsinterfaces container
LeafSingle data elementip-address
Leaf-listMultiple entries of the same typeMultiple DNS servers
ListA collection of containersMultiple router interfaces
TypeDefines data typestring, boolean, enumeration
Choice/CaseOptional alternativesStatic IP OR DHCP
AugmentExtending an existing modelAdding extra QoS settings

6. How YANG is Used in IT Automation

  • NETCONF and RESTCONF use YANG models to interact with devices.
  • Automation tools read YANG models to:
    • Know which fields are required.
    • Validate configuration data.
    • Ensure the data format is correct before sending it to the device.

Example workflow:

  1. RESTCONF request is made to configure an interface.
  2. YANG model defines which data is allowed (name, ip-address, status).
  3. Automation tool checks data against YANG model.
  4. Configuration is applied if valid, or rejected if invalid.

7. Tips for the Exam

  • Remember: YANG describes data structure, not actual configuration.
  • Know common YANG statements: module, container, list, leaf, type.
  • Understand hierarchical structure of YANG models.
  • Be able to interpret small YANG snippets to identify what data is defined and required.
  • Focus on interfaces, IP addresses, and status fields — these are commonly used examples in the exam.

Summary:

  • YANG is the blueprint for network configurations.
  • It helps automation tools understand and validate device data.
  • Key elements: module, container, list, leaf, leaf-list, type, choice, augment.
  • Being able to read and interpret YANG models is essential for automation and network programmability tasks.
Buy Me a Coffee