YANG Data Structure Extensions
YumaWorks
andy@yumaworks.com
Cisco
mbj+ietf@4668.se
Watsen Networks
kent+ietf@watsen.net
This document describes YANG mechanisms for
defining abstract data structures with YANG.
Introduction
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 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" , 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 .
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&nbhy;structure", which allows abstract data structures to be
augmented from external modules and is similar 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.
Terminology
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 when, and only when, they appear in all
capitals, as shown here.
The following term is used within this document:
- YANG data structure:
- A data structure defined with the "structure"
statement.
NMDA
The following terms are defined in the
Network Management Datastore Architecture
(NMDA)
and are not redefined here:
- configuration
- operational state
YANG
The following terms are defined in and are not redefined here:
- absolute-schema-nodeid
- container
- data definition statement
- data node
- leaf
- leaf-list
- list
Definitions
A YANG data structure is defined with the "structure" extension
statement, which is 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 . In particular, the seventh bullet states:
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:
can be encoded in JSON as:
YANG Data Structures in YANG Tree Diagrams
A YANG data structure can be printed in a YANG tree diagram .
This document updates RFC 8340 by defining
two new sections in the
tree diagram for a module:
- YANG data structures, which are 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, which are offset by 2 spaces and identified by
the keyword "augment&nbhy;structure" followed by the augment target structure
name and a colon (":") character.
The new sections, including spaces conventions, appear as follows:
:
+--
+--
| +--
+--
structure :
+--
augment-structure :
+--
+--
| +--
+--
augment-structure :
+--
]]>
Nodes in YANG data structures are printed according to the rules defined in
. The nodes in YANG
data structures do not have any <flags>.
YANG Data Structure Extensions Module
WG List:
Author: Andy Bierman
Author: Martin Bjorklund
Author: Kent Watsen
";
description
"This module contains conceptual YANG specifications for defining
abstract data structures.
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 (RFC 2119) (RFC 8174) when, and only when,
they appear in all capitals, as shown here.
Copyright (c) 2020 IETF Trust and the persons identified as
authors of the code. All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, is permitted pursuant to, and subject to
the license terms contained in, the Simplified BSD License set
forth in Section 4.c of the IETF Trust's Legal Provisions
Relating to IETF Documents
(http://trustee.ietf.org/license-info).
This version of this YANG module is part of RFC 8791
(https://www.rfc-editor.org/info/rfc8791); see the RFC itself
for full legal notices.";
revision 2020-06-17 {
description
"Initial revision.";
reference
"RFC 8791: YANG Data Structure Extensions.";
}
extension structure {
argument name {
yin-element true;
}
description
"This extension is used to specify a YANG data structure that
represents conceptual data defined in YANG. It is intended to
describe hierarchical data independent of protocol context or
specific message encoding format. Data definition statements
within a 'structure' extension statement specify the generic
syntax for the specific YANG data structure, whose name is the
argument of the 'structure' extension statement.
Note that this extension does not define a media type. A
specification using this extension MUST specify the message
encoding rules, including the content media type, if
applicable.
The mandatory 'name' parameter value identifies the YANG data
structure that is being defined.
This extension is only valid as a top-level statement, i.e.,
given as a substatement to 'module' or 'submodule'.
The substatements of this extension MUST follow the ABNF
rules below, where the rules are defined in RFC 7950:
*must-stmt
[status-stmt]
[description-stmt]
[reference-stmt]
*(typedef-stmt / grouping-stmt)
*data-def-stmt
A YANG data structure defined with this extension statement 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 child statements encoded as child nodes
to this node.
The module name and namespace value for the YANG module using
the extension statement are assigned to each of the data
definition statements resulting from the YANG data structure.
The XPath document element is the extension statement itself,
such that the child nodes of the document element are
represented by the data-def-stmt substatements within this
extension. This conceptual document is the context for the
following YANG statements:
- must-stmt
- when-stmt
- path-stmt
- min-elements-stmt
- max-elements-stmt
- mandatory-stmt
- unique-stmt
- ordered-by
- instance-identifier data type
The following data-def-stmt substatements are constrained
when used within a 'structure' extension statement.
- The list-stmt is not required to have a key-stmt defined.
- The config-stmt is ignored if present.
";
}
extension augment-structure {
argument path {
yin-element true;
}
description
"This extension is used to specify an augmentation to a YANG
data structure defined with the 'structure' statement. It is
intended to describe hierarchical data independent of protocol
context or specific message encoding format.
This statement has almost the same structure as the
'augment-stmt'. Data definition statements within this
statement specify the semantics and generic syntax for the
additional data to be added to the specific YANG data
structure, identified by the 'path' argument.
The mandatory 'path' parameter value identifies the YANG
conceptual data node that is being augmented and is
represented as an absolute-schema-nodeid string, where the
first node in the absolute-schema-nodeid string identifies the
YANG data structure to augment, and the rest of the nodes in
the string identifies the node within the YANG structure to
augment.
This extension is only valid as a top-level statement, i.e.,
given as a substatement to 'module' or 'submodule'.
The substatements of this extension MUST follow the ABNF
rules below, where the rules are defined in RFC 7950:
[status-stmt]
[description-stmt]
[reference-stmt]
1*(data-def-stmt / case-stmt)
The module name and namespace value for the YANG module using
the extension statement are assigned to instance document data
conforming to the data definition statements within this
extension.
The XPath document element is the augmented extension
statement itself, such that the child nodes of the document
element are represented by the data-def-stmt substatements
within the augmented 'structure' statement.
The context node of the 'augment-structure' statement is
derived in the same way as the 'augment' statement, as defined
in Section 6.4.1 of [RFC7950]. This conceptual node is
considered the context node for the following YANG statements:
- must-stmt
- when-stmt
- path-stmt
- min-elements-stmt
- max-elements-stmt
- mandatory-stmt
- unique-stmt
- ordered-by
- instance-identifier data type
The following data-def-stmt substatements are constrained
when used within an 'augment-structure' extension statement.
- The list-stmt is not required to have a key-stmt defined.
- The config-stmt is ignored if present.
Example:
module foo {
import ietf-yang-structure-ext { prefix sx; }
sx:structure foo-data {
container foo-con { }
}
}
module bar {
import ietf-yang-structure-ext { prefix sx; }
import foo { prefix foo; }
sx:augment-structure /foo:foo-data/foo:foo-con {
leaf add-leaf1 { type int32; }
leaf add-leaf2 { type string; }
}
}
";
}
}
]]>
IANA Considerations
YANG Module Registry
IANA has registered the following URI in the "ns" subregistry within the "IETF
XML Registry" :
- 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.
IANA has registered the following YANG module in the "YANG Module Names" subregistry
within the "YANG Parameters" registry:
- Name:
- ietf-yang-structure-ext
- Namespace:
- urn:ietf:params:xml:ns:yang:ietf-yang-structure-ext
- Prefix:
- sx
- Reference:
- RFC 8791
Security Considerations
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 .
References
Normative References
Extensible Markup Language (XML) 1.0 (Fifth Edition)
Informative References
Examples
"structure" Example
This example shows a simple address book that could be stored as an
artifact:
Below is the tree diagram of this module:
"augment&nbhy;structure" Example
This example adds "county" and "zipcode" leafs to the address book:
Below is the tree diagram of this module:
XML Encoding Example
This example shows how an address book can be encoded in XML :
Flintstone
Fred
301 Cobblestone Way
Bedrock
70777
Root
Charlie
4711 Cobblestone Way
Bedrock
70777
]]>
JSON Encoding Example
This example shows how an address book can be encoded in JSON:
"structure" Example That Defines a Non-top-level Structure
The following example defines a data structure with error information
that can be included in an <error&nbhy;info> element in an
<rpc&nbhy;error>:
The example below shows how this structure can be used in an
<rpc&nbhy;error>:
protocol
operation-failed
error
42
]]>