This document describes YANG mechanisms for defining abstract data structures with YANG.
There is a need for standard mechanisms to allow the definition of abstract data that is not intended to be implemented as configuration or operational state. The “yang-data” extension statement from RFC 8040 ^RFC8040^ was defined for this purpose but it is limited in its functionality.
The intended use of the “yang-data” extension was to model all or part of a protocol message, such as the “errors” definition in the YANG module “ietf-restconf” ^RFC8040^, or the contents of a file. However, protocols are often layered such that the header or payload portions of the message can be extended by external documents. The YANG statements that model a protocol need to support this extensibility that is already found in that protocol.
This document defines a new YANG extension statement called “structure”, which is similar to but more flexible than the “yang-data” extension from ^RFC8040^. There is no assumption that a YANG data structure can only be used as a top-level abstraction, and it may also be nested within some other data structure.
This document also defines a new YANG extension statement called “augment-structure”, which allows abstract data structures to be augmented from external modules, similarly to the existing YANG “augment” statement. Note that “augment” cannot be used to augment a YANG data structure since a YANG compiler or other tool is not required to understand the “structure” extension.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “NOT RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in BCP 14 ^RFC2119^ ^RFC8174^ when, and only when, they appear in all capitals, as shown here.
The following terms are used within this document:
- YANG data structure: A data structure defined with the “structure” statement.
The following terms are defined in the Network Management Datastore Architecture (NMDA) ^RFC8342^, and are not redefined here:
- configuration
- operational state
The following terms are defined in ^RFC7950^:
- absolute-schema-nodeid
- container
- data definition statement
- data node
- leaf
- leaf-list
- list
A YANG data structure is defined with the “structure” extension statement, defined in the YANG module “ietf-yang-structure-ext”. The argument to the “structure” extension statement is the name of the data structure. The data structures are considered to be in the same identifier namespace as defined in section 6.2.1 of ^RFC7950^. In particular, bullet 7:
All leafs, leaf-lists, lists, containers, choices, rpcs, actions, notifications, anydatas, and anyxmls defined (directly or through a “uses” statement) within a parent node or at the top level of the module or its submodules share the same identifier namespace.
This means that data structures defined with the “structure” statement cannot have the same name as sibling nodes from regular YANG data definition statements or other “structure” statements in the same YANG module.
This does not mean a YANG data structure, once defined, has to be used as a top-level protocol message or other top-level data structure.
A YANG data structure is encoded in the same way as an “anydata” node. This means that the name of the structure is encoded as a “container”, with the instantiated children encoded as child nodes to this node. For example, this structure:
module example-errors { …
sx:structure my-error { leaf error-number { type int; } } }
can be encoded in JSON as:
“example-errors:my-error”: { “error-number”: 131 }
A YANG data structure can be printed in a YANG Tree Diagram ^RFC8340^. This document updates RFC 8340 by defining two new sections in the tree diagram for a module:
- YANG data structures, offset by two spaces and identified by the keyword “structure” followed by the name of the YANG data structure and a colon (“:”) character.
- YANG data structure augmentations, offset by 2 spaces and identified by the keyword “augment-structure” followed by the augment target structure name and a colon (“:”) character.
The new sections, including spaces conventions is:
structure <structure-name>: +–<node> +–<node>
+–<node> |
+–<node> structure <structure-name>: +–<node>
augment-structure <structure-name>: +–<node> +–<node>
+–<node> |
+–<node> augment-structure <structure-name>: +–<node>
Nodes in YANG data structures are printed according to the rules defined in section 2.6 in ^RFC8340^.
RFC Ed.: update the date below with the date of RFC publication and remove this note.
!! include-figure ietf-yang-structure-ext.yang extract-to=”[email protected]”
This document registers one URI as a namespace in the “IETF XML Registry” ^RFC3688^:
URI: urn:ietf:params:xml:ns:yang:ietf-yang-structure-ext Registrant Contact: The IESG. XML: N/A; the requested URI is an XML namespace.
This document registers one YANG module in the “YANG Module Names” registry ^RFC6020^:
name: ietf-yang-structure-ext namespace: urn:ietf:params:xml:ns:yang:ietf-yang-structure-ext prefix: sx // RFC Ed.: replace XXXX with RFC number and remove this note reference: RFC XXXX
This document defines YANG extensions that are used to define conceptual YANG data structures. It does not introduce any new vulnerabilities beyond those specified in YANG 1.1 ^RFC7950^.
*! start-appendix
This example shows a simple address book that could be stored as an artifact.
!! include-figure example-module.yang
Below is the tree diagram of this module.
!! include-figure example-module.tree
This example adds “county” and “zipcode” leafs to the address book:
!! include-figure example-module-aug.yang
Below is the tree diagram of this module.
!! include-figure example-module-aug.tree
This example shows how an address book can be encoded in XML:
!! include-figure ex-address-book.load
This example shows how an address book can be encoded in JSON:
!! include-figure ex-address-book.json
The following example defines a data structure with error information, that can be included in an <error-info> element in an <rpc-error>.
!! include-figure example-error-info.yang
The example below shows how this structure can be used in an <rpc-error>.
!! include-figure example-error-info.xml
{{document: name ; ipr trust200902; category std; updates 8340; references references.xml; title “YANG Data Structure Extensions”; abbreviation “YANG Structure”; contributor “author:Andy Bierman:YumaWorks:[email protected]”; contributor “author:Martin Bjorklund:Cisco:[email protected]”; contributor “author:Kent Watsen:Watsen Networks:[email protected]”; }}