YANG Module
A YANG module defines a data model through the data of the router, and the hierarchical organization and constraints on that data. Each module is uniquely identified by a namespace URL. The YANG models describe the configuration and operational data, perform actions, remote procedure calls, and notifications for network devices.
The YANG models must be obtained from the router. The models define a valid structure for the data that is exchanged between the router and the client. The models are used by NETCONF and gRPC-enabled applications.
-
Cisco-specific models: For a list of supported models and their representation, see Github.
-
Common models: These models are industry-wide standard YANG models from standard bodies, such as IETF and IEEE. These models are also called Open Config (OC) models. Like synthesized models, the OC models have separate YANG models defined for configuration data and operational data, and actions.
For more details about YANG, refer RFC 6020 and 6087.
Components of a YANG Module
-
import imports external modules
-
include includes one or more sub-modules
-
augment provides augmentations to another module, and defines the placement of new nodes in the data model hierarchy
-
when defines conditions under which new nodes are valid
-
prefix references definitions in an imported module
The YANG models configure a feature, retrieve the operational state of the router, and perform actions.
Note |
The gRPC YANG path or JSON data is based on YANG module name and not YANG namespace. |
Example: Configuration YANG Model for AAA
(snippet)
module Cisco-IOS-XR-aaa-locald-cfg {
/*** NAMESPACE / PREFIX DEFINITION ***/
namespace "http://cisco.com/ns/yang/Cisco-IOS-XR-aaa-locald-cfg";
prefix "aaa-locald-cfg";
/*** LINKAGE (IMPORTS / INCLUDES) ***/
import Cisco-IOS-XR-types { prefix "xr"; }
import Cisco-IOS-XR-aaa-lib-cfg { prefix "a1"; }
/*** META INFORMATION ***/
organization "Cisco Systems, Inc.";
.........................
......................... (truncated)
Example: Operational YANG Model for AAA
(snippet)
module Cisco-IOS-XR-aaa-locald-oper {
/*** NAMESPACE / PREFIX DEFINITION ***/
namespace "http://cisco.com/ns/yang/Cisco-IOS-XR-aaa-locald-oper";
prefix "aaa-locald-oper";
/*** LINKAGE (IMPORTS / INCLUDES) ***/
import Cisco-IOS-XR-types { prefix "xr"; }
include Cisco-IOS-XR-aaa-locald-oper-sub1 {
revision-date 2015-01-07;
}
/*** META INFORMATION ***/
organization "Cisco Systems, Inc.";
........................
........................ (truncated)
Note |
A module can include any number of sub-modules; each sub-module belongs to only one module. The names of all standard modules and sub-modules must be unique. |
Example: NETCONF Action for OSPFv3
(snippet)
clear ospfv3 1 vrf vrf1 statistics neighbor 2.2.2.2
RPC message based on the new ospfv3 yang model-
<rpc message-id="101" xmlns="urn:ietf:params:xml:ns:netconf:base:1.0">
<act-ospfv3-instance-vrf xmlns="http://cisco.com/ns/yang/Cisco-IOS-XR-ipv6-ospfv3-act">
<instance>
<instance-identifier>1</instance-identifier>
<vrf>
<vrf-name>vrf1</vrf-name>
<stats>
<neighbor>
<neighbor-id>2.2.2.2</neighbor-id>
</neighbor>
</stats>
</vrf>
</instance>
</act-ospfv3-instance-vrf>
</rpc>
Structure of YANG Models
YANG data models can be represented in a hierarchical, tree-based structure with nodes. This representation makes the models easy to understand.
Each feature has a defined YANG model, which is synthesized from schemas. A model in a tree format includes:
-
Top level nodes and their subtrees
-
Subtrees that augment nodes in other YANG models
-
Custom RPCs
-
leaf node - contains a single value of a specific type
-
leaf-list node - contains a sequence of leaf nodes
-
list node - contains a sequence of leaf-list entries, each of which is uniquely identified by one or more key leaves
-
container node - contains a grouping of related nodes that have only child nodes, which can be any of the four node types
Example: Structure of CDP Data Model
Cisco Discovery Protocol (CDP) configuration has an inherent augmented model (interface-configuration). The augmentation indicates that CDP can be configured at both the global configuration level and the interface configuration level. The data model for CDP interface manager in tree structure is:
module: Cisco-IOS-XR-cdp-cfg
+--rw cdp
+--rw timer? uint32
+--rw advertise-v1-only? empty
+--rw enable? boolean
+--rw hold-time? uint32
+--rw log-adjacency? empty
augment /a1:interface-configurations/a1:interface-configuration:
+--rw cdp
+--rw enable? empty
augment "/a1:interface-configurations/a1:interface-configuration" {
container cdp {
description "Interface specific CDP configuration";
leaf enable {
type empty;
description "Enable or disable CDP on an interface";
}
}
description
"This augment extends the configuration data of
'Cisco-IOS-XR-ifmgr-cfg'";
}
module: Cisco-IOS-XR-cdp-oper
+--ro cdp
+--ro nodes
+--ro node* [node-name]
+--ro neighbors
| +--ro details
| | +--ro detail*
| | +--ro interface-name? xr:Interface-name
| | +--ro device-id? string
| | +--ro cdp-neighbor*
| | +--ro detail
| | | +--ro network-addresses
| | | | +--ro cdp-addr-entry*
| | | | +--ro address
| | | | +--ro address-type? Cdp-l3-addr-protocol
| | | | +--ro ipv4-address? inet:ipv4-address
| | | | +--ro ipv6-address? In6-addr
| | | +--ro protocol-hello-list
| | | | +--ro cdp-prot-hello-entry*
| | | | +--ro hello-message? yang:hex-string
| | | +--ro version? string
| | | +--ro vtp-domain? string
| | | +--ro native-vlan? uint32
| | | +--ro duplex? Cdp-duplex
| | | +--ro system-name? string
| | +--ro receiving-interface-name? xr:Interface-name
| | +--ro device-id? string
| | +--ro port-id? string
| | +--ro header-version? uint8
| | +--ro hold-time? uint16
| | +--ro capabilities? string
| | +--ro platform? string
............................................... (truncated)
Usability Enhancements for ACL YANG Models
This feature addresses some of the issues identified with native ACL YANG models that affect usability of the YANG model. It improves user-friendliness and standards compliance in the following native ACL YANG models:
-
Cisco-IOS-XR-es-acl-cfg
-
Cisco-IOS-XR-ipv4-acl-cfg
-
Cisco-IOS-XR-ipv6-acl-cfg
The following issues are addressed as part of this enhancement:
-
Lack of revision dates and descriptions
Problem: When the revision changed on an ACL-model YANG file, the changes associated with the new revision were not accurately described.
Solution: Includes description for the changes made in each subsequent version without removing the information for the previous versions.
Example from Cisco-IOS-XR-ipv4-acl-cfg.yang :
revision "2018-04-03" { description "6.5.1 revision. Correct enum value for Next-hop-type."; } revision "2018-03-23" { description "6.5.1 revision. Removing none-next-type."; }
-
Unconstrained use of strings
Problem: ACL native models use leaves defined as string type; however, the string length is undefined or incorrect.
Solution: Pattern and length checking is added to leaves using string types. This allows NETCONF to control these checks, rather than relying on ACL verifier at commit time.
In the following example, the length of the string is limited to 255 characters and only alphanumeric characters are allowed.
typedef my-base-str-type { type string { length "1..255"; pattern "[0-9a-fA-F]*"; } }
-
Lack of good description statements
Problem: Most leaves in the native ACL models had description fields that did not have good description, which impacts the ease of use and understanding of the YANG model.
Solution: Leaf description fields are updated to provide useful information.
-
Lack of verification and inconsistent behavior across ACL-range leaves
Problem: YANG model supports different combinations of leaves for containers with upper value, lower value and operator leaves. As a result, some of the configurations can be invalid from the CLI perspective.
Solution: The native ACL models are improved to include various combinations of leaves that are supported by the YANG model. Also, the parsing behavior across all ACL-range leaves are aligned to remain consistent.
-
Inconsistency between protocol-operator input and output
Problem: NETCONF output should be consistent with user input.
Solution: The protocol-operator leaf is made as non-mandatory, and need not be set to equal.