NETMOD Working Group | L. Lhotka |
Internet-Draft | CZ.NIC |
Intended status: Standards Track | September 11, 2014 |
Expires: March 15, 2015 |
Defining and Using Metadata with YANG
draft-lhotka-netmod-yang-metadata-00
This document defines a YANG extension statement that allows for defining metadata annotions in YANG modules. The document also specifies the encoding of annotations and rules for annotating instances of YANG data nodes.
This Internet-Draft is submitted in full conformance with the provisions of BCP 78 and BCP 79.
Internet-Drafts are working documents of the Internet Engineering Task Force (IETF). Note that other groups may also distribute working documents as Internet-Drafts. The list of current Internet-Drafts is at http://datatracker.ietf.org/drafts/current/.
Internet-Drafts are draft documents valid for a maximum of six months and may be updated, replaced, or obsoleted by other documents at any time. It is inappropriate to use Internet-Drafts as reference material or to cite them other than as "work in progress."
This Internet-Draft will expire on March 15, 2015.
Copyright (c) 2014 IETF Trust and the persons identified as the document authors. All rights reserved.
This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (http://trustee.ietf.org/license-info) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.
There is a need to be able to annotate instances of YANG [3] data nodes with various metadata. Typical use cases are:
However, metadata annotations could potentially lead to interoperability problems if they are used in an ad hoc way by different organizations and/or without proper documentation. A sound metadata framework for YANG should therefore satisfy these requirements:
This document proposes a systematic way for defining and using metadata annotations that satisfies the above requirements. For this purpose, YANG extension statement "annotation" is defined in the module "ietf-yang-metadata" (Section 6). Other YANG modules importing this module can use the "annotation" statement for defining one or more annotations.
The benefits of defining metadata annotations in a YANG module are as follows:
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in [1].
The following terms are defined in [5]:
The following terms are defined in [3]:
The following terms are defined in [8]:
The following terms are defined in [6]:
XML element names and YANG extension statements are always written with explicit namespace prefixes that are assumed to be bound to URI references as shown in Table 1.
Prefix | URI Reference |
---|---|
rng | http://relaxng.org/ns/structure/1.0 |
md | urn:ietf:params:xml:ns:yang:ietf-yang-metadata |
ein | http://example.org/example-inactive |
Metadata annotations are defined with YANG extension statement "md:annotation". This YANG language extension is defined in the module "ietf-yang-metadata" (Section 6).
Substatements of "md:annotation" are shown in Table 2. They are all core YANG statements, and the numbers in the second column refer to the corresponding sections in RFC 6020 [3] where each statement is described.
substatement | RFC 6020 section | cardinality |
---|---|---|
description | 7.19.3 | 0..1 |
reference | 7.19.4 | 0..1 |
status | 7.19.2 | 0..1 |
type | 7.6.3 | 0..1 |
units | 7.3.3 | 0..1 |
Using the "type" statement, a type may be specified for the annotation value according to the same rules as for YANG leaf or leaf-list types. However, the "type" statement is optional as a substatement of "md:annotation" statement. If it is not present, the built-in "string" type is the default.
For example, the following module defines the "inactive" annotation:
module example-inactive { namespace "http://example.org/example-inactive"; prefix "ein"; import ietf-yang-metadata { prefix "md"; } md:annotation inactive { type boolean; description "If this annotation is attached to a configuration data node, and its value is 'true', then the server MUST behave as if the data subtree rooted at this node was not present."; } }
Metadata annotations defined with the "md:annotation" statement may be attached to any valid instance of a data node, i.e., container, leaf, list, leaf-list or anyxml, throughout the data model. Metadata annotations are always optional.
XML attributes are a natural choice for encoding metadata in XML instance documents. For JSON [6], there is no generally established method for encoding metadata. This document thus introduces a special encoding method that is consistent with the JSON encoding of YANG data node instances as defined in [7].
Metadata annotations are added to XML-encoded instances of YANG data nodes as XML attributes according to these rules:
For example, the "inactive" annotation as defined in Section 3 may be encoded as follows:
<foo xmlns:ein="http://example.org/example-inactive" ein:inactive="true"> ... </foo>
The metadata encoding defined in this section has the following properties:
All metadata annotations assigned to a YANG data node instance are encoded as members (name/value pairs) of a single JSON object, henceforth denoted as the metadata object. The placement and name of this object depends on the type of the data node as specified in the following subsections.
MODULE_NAME:LOCAL_NAME
The name of a metadata annotation (member of the metadata object) SHALL be of the following form:
Note that unlike YANG data node instances, for annotations the explicit namespace identifier (MODULE_NAME) must always be used.
The value of a metadata annotation SHALL be encoded in exactly the same way as the value of a YANG leaf node having the same type as the annotation.
For an instance that is translated to a JSON object (i.e., a container, anyxml or list entry), the metadata object is added as a new member of that object with the name "@".
"cask": { "@": { "example-inactive:inactive": true }, ... }
"seq": [ { "@": { "example-inactive:inactive": true }, "name": "one", ... }, { "name": "two", ... } ]
Examples:
For a leaf instance, the metadata object is added as a sibling name/value pair whose the name is the symbol "@" concatenated with the identifier of the leaf.
"flag": true, "@flag": { "example-inactive:inactive": true }
For example, if "flag" is a leaf node:
For a leaf-list instance, which is represented as a JSON array with values of a primitive type, annotations may be assigned to one or more entries by adding a name/array pair as a sibling the leaf-list instance, where the name is the symbol "@" concatenated with the identifier of the leaf-list, and the value is a JSON array whose i-th element is the metadata object with annotations assigned to the i-th entry of the leaf-list instance, or null if the i-th entry has no annotations.
Trailing null values in the array, i.e., those following the last non-null metadata object, MAY be omitted.
"folio": [6, 3, 7, 8], "@folio": [ null, {"example-inactive:inactive": true}, {"example-inactive:inactive": true} ]
For example, in the following leaf-list instance with four entries, the "inactive" annotation is added to the second and third entry in the following way:
RFC 6110 [4] defines a standard mapping of YANG data models to Document Schema Definition Languages (DSDL) [9]. This section specifies the mapping for the extension statement "md:annotation" (Section 6), which enables validation of XML instance documents containing metadata annotations.
md:annotation ARGUMENT;
md:annotation ARGUMENT { ... }
<rng:attribute name="PREFIX:ARGUMENT"> ... </rng:attribute>
The first step of the DSDL mapping procedure, i.e., the transformation of the YANG data model to the hybrid schema (see sec. 6 in [4]), is modified as follows:
For example, the named pattern definition (item 1), when constructed only for the "inactive" annotation, will have the following form:
<rng:define name="__yang_metadata__"> <rng:attribute name="ein:inactive"> <rng:choice> <rng:value>true</rng:value> <rng:value>false</rng:value> </rng:choice> </rng:attribute> </rng:define>
Every "rng:element" pattern that corresponds to a container, leaf, list or leaf-list data node will then contain a reference to the above named pattern, for example
<rng:element name="foo:bar"> <rng:ref name="__yang_metadata__"/> ... </rng:element>
Note that it is not necessary to use such a reference for "rng:element" patterns corresponding to anyxml data nodes because they already permit any XML attributes to be attached to their instances.
The second step of the DSDL mapping procedure, i.e., the transformation of the hybrid schema to RELAX NG, Schematron and DSRL schemas, is unaffected by the inclusion of "md:annotation".
RFC Ed.: In this section, replace all occurrences of 'XXXX' with the actual RFC number and all occurrences of the revision date below with the date of RFC publication (and remove this note).
<CODE BEGINS> file "yang-metadata@2014-09-11.yang" module ietf-yang-metadata { namespace "urn:ietf:params:xml:ns:yang:ietf-yang-metadata"; prefix "md"; organization "IETF NETMOD (NETCONF Data Modeling Language) Working Group"; contact "Editor: Ladislav Lhotka <mailto:lhotka@nic.cz>"; description "This YANG module defines an extension statement that allows for defining metadata annotations."; revision 2014-09-11 { description "Initial revision."; reference "RFC XXXX: Defining and Using Metadata with YANG"; } extension annotation { argument name; description "This extension allows for defining metadata annotations in YANG modules. The 'md:annotation' statement can appear only at the top level of a YANG module. An annotation defined with this extension statement inherits the namespace and other context from the YANG module in which it is defined. Other properties of the annotation and documentation may be specified using the following standard YANG substatements (all are optional and may appear only once): 'type', 'description', 'reference', 'status' and 'units'. If the 'type' statement is not present, the built-in 'string' type is used by default. A server announces support for a particular annotation by including the module in which the annotation is defined among the advertised YANG modules (e.g. in NETCONF hello message). Depending on the prescribed usage patterns, the annotation then may be attached by the server and/or client to any valid instance of a data node defined by the server's data model. XML and JSON encoding of annotations is defined in RFC XXXX."; } } <CODE ENDS>
RFC Ed.: In this section, replace all occurrences of 'XXXX' with the actual RFC number (and remove this note).
This document registers the following namespace URI in the IETF XML registry [2]:
---------------------------------------------------------- URI: urn:ietf:params:xml:ns:yang:ietf-yang-metadata Registrant Contact: The IESG. XML: N/A, the requested URI is an XML namespace. ----------------------------------------------------------
This document registers the following YANG module in the YANG Module Names registry [3]:
------------------------------------------------------------------- name: ietf-yang-metadata namespace: urn:ietf:params:xml:ns:yang:ietf-yang-metadata prefix: md reference: RFC XXXX -------------------------------------------------------------------
This document introduces a mechanism for defining metadata annotations in YANG modules and using them with instances of YANG data nodes. By itself, this mechanism represents no security threat. Security implications of a particular annotation defined using this mechanism have to be duly considered and documented.
[1] | Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, March 1997. |
[2] | Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688, January 2004. |
[3] | Bjorklund, M., "YANG - A Data Modeling Language for the Network Configuration Protocol (NETCONF)", RFC 6020, October 2010. |
[4] | Lhotka, L., "Mapping YANG to Document Schema Definition Languages and Validating NETCONF Content", RFC 6110, February 2011. |
[5] | Enns, R., Bjorklund, M., Schoenwaelder, J. and A. Bierman, "Network Configuration Protocol (NETCONF)", RFC 6241, June 2011. |
[6] | Bray, T., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 7159, March 2014. |
[7] | Lhotka, L., "JSON Encoding of Data Modeled with YANG", Internet-Draft draft-ietf-netmod-yang-json-00, April 2014. |
[8] | Cowan, J. and R. Tobin, "XML Information Set (Second Edition)", World Wide Web Consortium Recommendation REC-xml-infoset-20040204, February 2004. |
[9] | International Organization for Standardization, "Document Schema Definition Languages (DSDL) - Part 1: Overview", ISO/IEC 19757-1, November 2004. |
[10] | Bierman, A., Bjorklund, M., Watsen, K. and R. Fernando, "RESTCONF Protocol", Internet-Draft draft-ietf-netconf-restconf-01, July 2014. |