Internet Engineering Task Force (IETF) L. Lhotka Request for Comments: 7952 CZ.NIC Updates: 6110 August 2016 Category: Standards Track ISSN: 2070-1721
Internet Engineering Task Force (IETF) L. Lhotka Request for Comments: 7952 CZ.NIC Updates: 6110 August 2016 Category: Standards Track ISSN: 2070-1721
Defining and Using Metadata with YANG
使用YANG定义和使用元数据
Abstract
摘要
This document defines a YANG extension that allows for defining metadata annotations in YANG modules. The document also specifies XML and JSON encoding of annotations and other rules for annotating instances of YANG data nodes.
本文档定义了一个YANG扩展,该扩展允许在YANG模块中定义元数据注释。该文档还指定注释的XML和JSON编码以及用于注释数据节点实例的其他规则。
Status of This Memo
关于下段备忘
This is an Internet Standards Track document.
这是一份互联网标准跟踪文件。
This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in Section 2 of RFC 7841.
本文件是互联网工程任务组(IETF)的产品。它代表了IETF社区的共识。它已经接受了公众审查,并已被互联网工程指导小组(IESG)批准出版。有关互联网标准的更多信息,请参见RFC 7841第2节。
Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at http://www.rfc-editor.org/info/rfc7952.
有关本文件当前状态、任何勘误表以及如何提供反馈的信息,请访问http://www.rfc-editor.org/info/rfc7952.
Copyright Notice
版权公告
Copyright (c) 2016 IETF Trust and the persons identified as the document authors. All rights reserved.
版权所有(c)2016 IETF信托基金和确定为文件作者的人员。版权所有。
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.
本文件受BCP 78和IETF信托有关IETF文件的法律规定的约束(http://trustee.ietf.org/license-info)自本文件出版之日起生效。请仔细阅读这些文件,因为它们描述了您对本文件的权利和限制。从本文件中提取的代码组件必须包括信托法律条款第4.e节中所述的简化BSD许可证文本,并提供简化BSD许可证中所述的无担保。
Table of Contents
目录
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1. Key Words . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2. Terms Defined in Other Documents . . . . . . . . . . . . 5 2.3. Namespaces and Prefixes . . . . . . . . . . . . . . . . . 7 2.4. Definitions of New Terms . . . . . . . . . . . . . . . . 7 3. Defining Annotations in YANG . . . . . . . . . . . . . . . . 8 3.1. Example Definition . . . . . . . . . . . . . . . . . . . 9 4. Using Annotations . . . . . . . . . . . . . . . . . . . . . . 9 5. The Encoding of Annotations . . . . . . . . . . . . . . . . . 10 5.1. XML Encoding . . . . . . . . . . . . . . . . . . . . . . 10 5.2. JSON Encoding . . . . . . . . . . . . . . . . . . . . . . 11 5.2.1. Metadata Object and Annotations . . . . . . . . . . . 11 5.2.2. Adding Annotations to anydata, container, and list Entries . . . . . . . . . . . . . . . . . . . . . . . 12 5.2.3. Adding Annotations to anyxml and leaf Instances . . . 12 5.2.4. Adding Annotations to leaf-list Entries . . . . . . . 13 6. Representing Annotations in DSDL Schemas . . . . . . . . . . 14 7. Metadata YANG Module . . . . . . . . . . . . . . . . . . . . 16 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 18 9. Security Considerations . . . . . . . . . . . . . . . . . . . 18 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 19 10.1. Normative References . . . . . . . . . . . . . . . . . . 19 10.2. Informative References . . . . . . . . . . . . . . . . . 20 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 21 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 21
1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 2. Terminology . . . . . . . . . . . . . . . . . . . . . . . . . 5 2.1. Key Words . . . . . . . . . . . . . . . . . . . . . . . . 5 2.2. Terms Defined in Other Documents . . . . . . . . . . . . 5 2.3. Namespaces and Prefixes . . . . . . . . . . . . . . . . . 7 2.4. Definitions of New Terms . . . . . . . . . . . . . . . . 7 3. Defining Annotations in YANG . . . . . . . . . . . . . . . . 8 3.1. Example Definition . . . . . . . . . . . . . . . . . . . 9 4. Using Annotations . . . . . . . . . . . . . . . . . . . . . . 9 5. The Encoding of Annotations . . . . . . . . . . . . . . . . . 10 5.1. XML Encoding . . . . . . . . . . . . . . . . . . . . . . 10 5.2. JSON Encoding . . . . . . . . . . . . . . . . . . . . . . 11 5.2.1. Metadata Object and Annotations . . . . . . . . . . . 11 5.2.2. Adding Annotations to anydata, container, and list Entries . . . . . . . . . . . . . . . . . . . . . . . 12 5.2.3. Adding Annotations to anyxml and leaf Instances . . . 12 5.2.4. Adding Annotations to leaf-list Entries . . . . . . . 13 6. Representing Annotations in DSDL Schemas . . . . . . . . . . 14 7. Metadata YANG Module . . . . . . . . . . . . . . . . . . . . 16 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 18 9. Security Considerations . . . . . . . . . . . . . . . . . . . 18 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 19 10.1. Normative References . . . . . . . . . . . . . . . . . . 19 10.2. Informative References . . . . . . . . . . . . . . . . . 20 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 21 Author's Address . . . . . . . . . . . . . . . . . . . . . . . . 21
There is a need to be able to annotate instances of YANG [RFC7950] data nodes with metadata. Typical use cases are as follows:
需要能够用元数据注释YANG[RFC7950]数据节点的实例。典型用例如下所示:
o Complementing regular data model information with instance-specific metadata, comments, etc.
o 使用特定于实例的元数据、注释等补充常规数据模型信息。
o Providing information about the rendering of data in user interfaces.
o 提供有关在用户界面中呈现数据的信息。
o Deactivating a subtree in a configuration datastore while keeping the data in place.
o 在保留数据的同时停用配置数据存储中的子树。
o Network management protocols often use metadata annotations for various purposes in both operation requests and responses. For example, the <edit-config> operation in the Network Configuration Protocol (NETCONF) (see Section 7.2 of [RFC6241]) uses annotations in the form of XML attributes for identifying the location in a configuration datastore and the type of the operation.
o 网络管理协议通常在操作请求和响应中出于各种目的使用元数据注释。例如,网络配置协议(NETCONF)中的<edit config>操作(参见[RFC6241]第7.2节)使用XML属性形式的注释来标识配置数据存储中的位置和操作类型。
However, metadata annotations could potentially lead to interoperability problems if they are used in an ad hoc fashion by different parties and/or without proper documentation. A sound metadata framework for YANG should therefore satisfy these requirements:
但是,如果元数据注释被不同的方以特殊方式使用和/或没有适当的文档,则可能会导致互操作性问题。因此,YANG的良好元数据框架应满足以下要求:
1. The set of annotations must be extensible in a decentralized manner so as to allow for defining new annotations without running the risk of collisions with annotations defined and used by others.
1. 注释集必须以分散的方式进行扩展,以便允许定义新的注释,而不会与其他人定义和使用的注释发生冲突。
2. The syntax and semantics of annotations must be documented, and the documentation must be easily accessible.
2. 必须记录注释的语法和语义,并且文档必须易于访问。
3. Clients of network management protocols such as NETCONF [RFC6241] or RESTCONF [RESTCONF] must be able to discover all annotations supported by a given server and identify each of them correctly.
3. 网络管理协议(如NETCONF[RFC6241]或RESTCONF[RESTCONF])的客户端必须能够发现给定服务器支持的所有注释,并正确识别它们中的每一个。
4. Annotations sent by a server should not break clients that don't support them.
4. 服务器发送的注释不应破坏不支持它们的客户端。
This document proposes a systematic way to define metadata annotations. For this purpose, the YANG extension "annotation" is defined in the module "ietf-yang-metadata" (Section 7). Other YANG modules importing this module can use the "annotation" statement for defining one or more annotations.
本文档提出了一种定义元数据注释的系统方法。为此,模块“ietf YANG元数据”(第7节)中定义了YANG扩展“注释”。导入此模块的其他模块可以使用“annotation”语句定义一个或多个注释。
The benefits of defining the metadata annotations in a YANG module are the following:
在模块中定义元数据注释的好处如下:
o Each annotation is bound to a YANG module name and namespace URI. This makes its encoding in instance documents (both XML and JSON) straightforward and consistent with the encoding of YANG data node instances.
o 每个注释都绑定到一个模块名和名称空间URI。这使得它在实例文档(XML和JSON)中的编码简单明了,并且与数据节点实例的编码一致。
o Annotations defined in IETF Standards Track documents are indirectly registered through IANA in the "YANG Module Names" registry [RFC6020].
o IETF标准跟踪文件中定义的注释通过IANA间接注册到“模块名称”注册中心[RFC6020]。
o Annotations are included in the data model. YANG compilers and tools supporting a certain annotation can thus take them into account and modify their behavior accordingly.
o 注释包含在数据模型中。因此,支持特定注释的编译器和工具可以考虑它们,并相应地修改它们的行为。
o The semantics of an annotation are defined in the "description" and "reference" statements.
o 注释的语义在“description”和“reference”语句中定义。
o An annotation can be declared as conditional by using the "if-feature" statement.
o 可以使用“if feature”语句将注释声明为有条件的。
o The type of each annotation is explicitly specified; any YANG built-in or derived type that is available for leaf or leaf-list data nodes may be specified for annotations as well.
o 明确指定每个注释的类型;也可以为注释指定叶或叶列表数据节点可用的任何内置或派生类型。
In the XML encoding, XML attributes are a natural instrument for attaching annotations to data node instances. This document deliberately adopts some restrictions in order to remain compatible with the XML encoding of YANG data node instances and limitations of XML attributes. Specifically,
在XML编码中,XML属性是将注释附加到数据节点实例的自然工具。本文档有意采用一些限制,以便与数据节点实例的XML编码和XML属性的限制保持兼容。明确地
o annotations can only be scalar values.
o 注释只能是标量值。
o annotations cannot be attached to a whole list or leaf-list instance, only to individual list or leaf-list entries.
o 注释不能附加到整个列表或叶列表实例,只能附加到单个列表或叶列表条目。
Due to the rules for YANG extensions (see Section 6.3.1 in [RFC7950]), annotation definitions posit relatively weak conformance requirements. The alternative of introducing a new built-in YANG statement for defining annotations was considered, but it was seen as a major change to the language that is inappropriate for YANG 1.1, which was chartered as a maintenance revision. After evaluating real-life usage of metadata annotations, it is conceivable that such a new built-in statement might be added in a future revision of YANG.
由于YANG扩展的规则(参见[RFC7950]中的第6.3.1节),注释定义提出了相对较弱的一致性要求。考虑了引入新的内置YANG语句来定义注释的替代方案,但这被视为对语言的重大更改,不适用于YANG 1.1,该语言被特许作为维护修订版。在评估了元数据注释的实际使用情况之后,可以想象这样一个新的内置语句可能会添加到YANG的未来版本中。
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 [RFC2119].
本文件中的关键词“必须”、“不得”、“必需”、“应”、“不应”、“应”、“不应”、“建议”、“可”和“可选”应按照[RFC2119]中所述进行解释。
The following terms are defined in [RFC6241]:
[RFC6241]中定义了以下术语:
o capability
o 能力
o client
o 客户
o datastore
o 数据存储
o message
o 消息
o protocol operation
o 协议操作
o server
o 服务器
The following terms are defined in [RFC7950]:
[RFC7950]中定义了以下术语:
o action
o 行动
o anydata
o 任何数据
o anyxml
o 任意XML
o built-in type
o 内置式
o container
o 容器
o data model
o 数据模型
o data node
o 数据节点
o data tree
o 数据树
o derived type
o 派生类型
o extension
o 扩大
o leaf
o 叶
o leaf-list
o 叶列表
o list
o 列表
o module
o 单元
o Remote Procedure Call (RPC) input and output
o 远程过程调用(RPC)输入和输出
The following terms are defined in [XML-INFOSET]:
[XML-INFOSET]中定义了以下术语:
o attribute
o 属性
o document
o 文件
o element
o 要素
The following terms are defined in [XML-NAMES]:
[XML-NAMES]中定义了以下术语:
o local name
o 本地名称
o namespace name
o 命名空间名称
o prefix
o 前缀
o qualified name
o 限定名
The following terms are defined in [RFC7159]:
[RFC7159]中定义了以下术语:
o array
o 大堆
o member
o 成员
o object
o 对象
o primitive type
o 原始类型
In the following text, 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.
在下面的文本中,XML元素名和扩展语句总是使用显式名称空间前缀编写,这些前缀假定绑定到URI引用,如表1所示。
+--------+------------------------------------------------+ | Prefix | URI Reference | +--------+------------------------------------------------+ | elm | http://example.org/example-last-modified | | md | urn:ietf:params:xml:ns:yang:ietf-yang-metadata | | rng | http://relaxng.org/ns/structure/1.0 | +--------+------------------------------------------------+
+--------+------------------------------------------------+ | Prefix | URI Reference | +--------+------------------------------------------------+ | elm | http://example.org/example-last-modified | | md | urn:ietf:params:xml:ns:yang:ietf-yang-metadata | | rng | http://relaxng.org/ns/structure/1.0 | +--------+------------------------------------------------+
Table 1: Used Namespace Prefixes and Corresponding URI References
表1:使用的名称空间前缀和相应的URI引用
o annotation: a single item of metadata that is attached to YANG data node instances.
o 注释:附加到数据节点实例的单个元数据项。
o metadata: additional information that complements a data tree.
o 元数据:补充数据树的附加信息。
o metadata object: an object in JSON encoding that contains all annotations attached to a given data node instance.
o 元数据对象:JSON编码的对象,包含附加到给定数据节点实例的所有注释。
Metadata annotations are defined by the YANG extension "md:annotation". This YANG language extension is defined in the module "ietf-yang-metadata" (Section 7).
元数据注释由扩展名“md:annotation”定义。该YANG语言扩展在模块“ietf YANG元数据”(第7节)中定义。
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 section in [RFC7950] where each statement is described.
“md:annotation”的子语句如表2所示。它们都是核心YANG语句,第二列中的数字指的是[RFC7950]中的相应章节,其中描述了每种语句。
+--------------+---------------------+-------------+ | substatement | section in RFC 7950 | cardinality | +--------------+---------------------+-------------+ | description | 7.21.3 | 0..1 | | if-feature | 7.20.2 | 0..n | | reference | 7.21.4 | 0..1 | | status | 7.21.2 | 0..1 | | type | 7.6.3 | 1 | | units | 7.3.3 | 0..1 | +--------------+---------------------+-------------+
+--------------+---------------------+-------------+ | substatement | section in RFC 7950 | cardinality | +--------------+---------------------+-------------+ | description | 7.21.3 | 0..1 | | if-feature | 7.20.2 | 0..n | | reference | 7.21.4 | 0..1 | | status | 7.21.2 | 0..1 | | type | 7.6.3 | 1 | | units | 7.3.3 | 0..1 | +--------------+---------------------+-------------+
Table 2: Substatements of "md:annotation"
表2:“md:注释”的子语句
An annotation carries a single value. The "type" substatement, which MUST be present, takes as an argument the name of an existing built-in or derived type, and the value of the annotation MUST match this type. See Section 7.4 of [RFC7950] for details.
注释只包含一个值。必须存在的“type”子语句将现有内置类型或派生类型的名称作为参数,并且注释的值必须与此类型匹配。详见[RFC7950]第7.4节。
An annotation can be made conditional by using one or more "if-feature" statements; the annotation is then supported only by servers that advertise the corresponding feature.
注释可以通过使用一个或多个“if-feature”语句来设置条件;然后,只有播发相应功能的服务器才支持注释。
The semantics and usage rules for an annotation SHOULD be fully specified in "description", "reference", and "units" statements.
注释的语义和使用规则应该在“description”、“reference”和“units”语句中完全指定。
An annotation MUST NOT change the data tree semantics defined by YANG. For example, it is illegal to define and use an annotation that allows for overriding uniqueness of leaf-list entries.
注释不得更改YANG定义的数据树语义。例如,定义和使用允许覆盖叶列表项唯一性的注释是非法的。
The "status" statement can be used exactly as it is used for YANG data nodes.
“status”语句的使用方式与数据节点完全相同。
A YANG module containing one or more "md:annotation" statements SHOULD NOT be used for defining data nodes or groupings. Also, derived types, identities, and features SHOULD NOT be defined in such a module unless they are used by the definitions of annotations in that module.
包含一个或多个“md:annotation”语句的模块不应用于定义数据节点或分组。此外,派生类型、标识和特征不应在此类模块中定义,除非该模块中的注释定义使用它们。
The following module defines the "last-modified" annotation:
以下模块定义了“上次修改”注释:
module example-last-modified { namespace "http://example.org/example-last-modified"; prefix "elm"; import ietf-yang-types { prefix "yang"; } import ietf-yang-metadata { prefix "md"; } md:annotation last-modified { type yang:date-and-time; description "This annotation contains the date and time when the annotated instance was last modified (or created)."; } }
module example-last-modified { namespace "http://example.org/example-last-modified"; prefix "elm"; import ietf-yang-types { prefix "yang"; } import ietf-yang-metadata { prefix "md"; } md:annotation last-modified { type yang:date-and-time; description "This annotation contains the date and time when the annotated instance was last modified (or created)."; } }
By advertising a YANG module in which a metadata annotation is defined using the "md:annotation" statement, a server indicates that it is prepared to handle that annotation according to the annotation's definition. That is, an annotation advertised by the server may be attached to an instance of a data node defined in any YANG module that is implemented by the server.
通过公布使用“md:annotation”语句定义元数据注释的模块,服务器表示它准备根据注释的定义处理该注释。也就是说,由服务器播发的注释可以附加到由服务器实现的任何模块中定义的数据节点的实例。
Depending on its semantics, an annotation may have an effect only in certain data trees and/or on instances of specific types of data nodes.
根据其语义,注释可能仅在某些数据树和/或特定类型数据节点的实例中有效。
A client MUST NOT add a specific annotation to data node instances if the server didn't advertise it.
如果服务器未公布特定的注释,则客户端不得向数据节点实例添加该注释。
Due care has to be exercised when introducing annotations in network management systems in order to avoid interoperability problems and software failures caused by a client that does not understand the annotations' semantics. Generally, it is safe for a server to use annotations in the following cases:
在网络管理系统中引入注释时必须格外小心,以避免互操作性问题和不理解注释语义的客户机导致的软件故障。通常,在以下情况下,服务器使用注释是安全的:
o An annotation is an integral part of a built-in or negotiated protocol capability.
o 注释是内置或协商协议功能的组成部分。
o An annotation contains auxiliary information that is not critical for protocol operation.
o 批注包含对协议操作不重要的辅助信息。
o The client explicitly asks the server, e.g., via a parameter of a protocol operation request, to include an annotation in the response.
o 客户端通过协议操作请求的参数明确要求服务器在响应中包含注释。
XML attributes are a natural choice for encoding metadata in XML instance documents. For JSON [RFC7159], 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 [RFC7951].
XML属性是在XML实例文档中编码元数据的自然选择。对于JSON[RFC7159],没有通用的元数据编码方法。因此,本文介绍了一种特殊的编码方法,该方法与[RFC7951]中定义的YANG数据节点实例的JSON编码一致。
Metadata annotations are added to XML-encoded instances of YANG data nodes as XML attributes according to these rules:
根据以下规则,元数据注释作为XML属性添加到数据节点的XML编码实例中:
o The local name of the attribute SHALL be the same as the name of the annotation specified in the argument of the corresponding "md:annotation" statement.
o 属性的本地名称应与相应“md:annotation”语句的参数中指定的注释名称相同。
o The namespace of the attribute SHALL be identified by the URI that appears as the argument of the "namespace" statement in the YANG module where the annotation is defined. It is RECOMMENDED that the prefix specified by the "prefix" statement in the same module be used in the qualified name of the attribute.
o 属性的名称空间应由URI标识,URI在定义注释的模块中作为“namespace”语句的参数出现。建议在属性的限定名称中使用同一模块中“prefix”语句指定的前缀。
o The attribute value SHALL be encoded in the same way as the value of a YANG leaf instance having the same type; see Section 9 of [RFC7950].
o 属性值的编码方式应与具有相同类型的阳叶实例的值相同;见[RFC7950]第9节。
For example, the "last-modified" annotation defined in Section 3.1 may be encoded as follows:
例如,第3.1节中定义的“最后修改的”注释可编码如下:
<foo xmlns:elm="http://example.org/example-last-modified" elm:last-modified="2015-09-16T10:27:35+02:00"> ... </foo>
<foo xmlns:elm="http://example.org/example-last-modified" elm:last-modified="2015-09-16T10:27:35+02:00"> ... </foo>
The JSON metadata encoding defined in this section has the following properties:
本节中定义的JSON元数据编码具有以下属性:
1. The encoding of YANG data node instances as defined in [RFC7951] does not change.
1. [RFC7951]中定义的数据节点实例编码不变。
2. Namespaces of metadata annotations are encoded in the same way as namespaces of YANG data node instances; see [RFC7951].
2. 元数据注释的名称空间编码方式与数据节点实例的名称空间编码方式相同;见[RFC7951]。
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 depend on the type of the data node as specified in the following subsections.
分配给数据节点实例的所有元数据注释都被编码为单个JSON对象的成员(名称/值对),此后表示为元数据对象。此对象的位置和名称取决于以下小节中指定的数据节点类型。
The name of a metadata annotation (as a member of the metadata object) has the following ABNF syntax [RFC5234], where the production for "identifier" is defined in Section 14 of [RFC7950]:
元数据注释的名称(作为元数据对象的成员)具有以下ABNF语法[RFC5234],其中“标识符”的产生在[RFC7950]的第14节中定义:
annotation-name = identifier ":" identifier
注释名称=标识符“:”标识符
where the left identifier is the name of the YANG module in which the annotation is defined and the identifier on the right is the name of the annotation specified in the argument of the corresponding "md:annotation" statement.
其中,左边的标识符是定义注释的模块的名称,右边的标识符是在相应的“md:annotation”语句的参数中指定的注释的名称。
Note that unlike member names of YANG data node instances in JSON encoding (see Section 4 in [RFC7951]), for annotations the explicit namespace identifier (module name) must always be present.
注意,与JSON编码中数据节点实例的成员名称不同(参见[RFC7951]中的第4节),对于注释,显式名称空间标识符(模块名称)必须始终存在。
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; see Section 6 of [RFC7951].
元数据注释的值应以与注释类型相同的阳叶节点的值完全相同的方式进行编码;见[RFC7951]第6节。
For a data node instance that is encoded as a JSON object (i.e., a container, list entry, or anydata node), the metadata object is added as a new member of that object with the name "@".
对于编码为JSON对象(即容器、列表条目或任意数据节点)的数据节点实例,元数据对象将添加为该对象的新成员,名称为“@”。
Examples:
示例:
o "cask" is a container or anydata node:
o “cask”是一个容器或任意数据节点:
"cask": { "@": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }, ... }
"cask": { "@": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }, ... }
o "seq" is a list whose key is "name"; annotation "last-modified" is added only to the first entry:
o “seq”是键为“name”的列表;注释“上次修改”仅添加到第一个条目:
"seq": [ { "@": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }, "name": "one", ... }, { "name": "two", ... } ]
"seq": [ { "@": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }, "name": "one", ... }, { "name": "two", ... } ]
For an anyxml or leaf instance, the metadata object is added as a sibling name/value pair whose name is the symbol "@" concatenated with the name of the leaf or anyxml member that is being annotated. The namespace part (module name) is included if and only if it is in the name of the annotated member.
对于anyxml或leaf实例,元数据对象被添加为同级名称/值对,其名称是符号“@”,并与正在注释的leaf或anyxml成员的名称连接在一起。当且仅当名称空间部分(模块名)位于注释成员的名称中时,才会包含该名称空间部分。
Examples:
示例:
o "flag" is a leaf node of the "boolean" type defined in module "foo", and we assume that the namespace name has to be expressed in its JSON encoding:
o “flag”是模块“foo”中定义的“boolean”类型的叶节点,我们假设名称空间名称必须用JSON编码表示:
"foo:flag": true, "@foo:flag": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }
"foo:flag": true, "@foo:flag": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }
o "stuff" is an anyxml node:
o “stuff”是一个anyxml节点:
"stuff": [1, null, "three"], "@stuff": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }
"stuff": [1, null, "three"], "@stuff": { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" }
For a leaf-list entry, 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 of the leaf-list entry, where the name is the symbol "@" concatenated with the name of the leaf-list that is being annotated, 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 entry, or null if the i-th entry has no annotations.
对于叶列表项(表示为JSON数组,带有基元类型的值),可以通过添加名称/数组对作为叶列表项的同级项,将注释分配给一个或多个条目,其中名称是与正在注释的叶列表名称连接的符号“@”,该值是一个JSON数组,其第i个元素是元数据对象,并将注释分配给叶列表项的第i个条目,如果第i个条目没有注释,则为null。
Trailing null values in that array, i.e., those following the last non-null metadata object, MAY be omitted.
该数组中的尾随空值,即最后一个非空元数据对象后面的值,可以省略。
For example, in the following leaf-list instance with four entries, the "last-modified" annotation is added to the second and third entries in the following way:
例如,在以下具有四个条目的叶列表实例中,“last modified”注释按以下方式添加到第二个和第三个条目中:
"bibliomod:folio": [6, 3, 7, 8], "@bibliomod:folio": [ null, { "example-last-modified:last-modified": "2015-06-18T17:01:14+02:00" }, { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" } ]
"bibliomod:folio": [6, 3, 7, 8], "@bibliomod:folio": [ null, { "example-last-modified:last-modified": "2015-06-18T17:01:14+02:00" }, { "example-last-modified:last-modified": "2015-09-16T10:27:35+02:00" } ]
[RFC6110] defines the standard mapping of YANG data models to Document Schema Definition Languages (DSDL) [ISO.19757-1]. This section specifies the mapping for the extension statement "md:annotation" (Section 7), which enables validation of XML instance documents containing metadata annotations.
[RFC6110]定义了数据模型到文档模式定义语言(DSDL)的标准映射[ISO.19757-1]。本节指定扩展语句“md:annotation”(第7节)的映射,它支持验证包含元数据注释的XML实例文档。
The first step of the DSDL mapping procedure, i.e., the transformation of the YANG data model to the hybrid schema (see Section 6 in [RFC6110]), is modified as follows:
DSDL映射过程的第一步,即将YANG数据模型转换为混合模式(见[RFC6110]第6节),修改如下:
1. If the data model contains at least one "md:annotation" statement, then a RELAX NG [ISO.19757-2] named pattern definition MUST be added as a child of the root <rng:grammar> element in the hybrid schema. It is RECOMMENDED to use the name "__yang_metadata__" for this named pattern.
1. 如果数据模型至少包含一条“md:annotation”语句,则必须将RELAX NG[ISO.19757-2]命名模式定义添加为混合模式中根<rng:grammar>元素的子元素。建议对此命名模式使用名称“\uuuuu yang\u metadata\uuuuuu”。
2. A reference to the named pattern described in item 1 MUST be included as a child of every <rng:element> pattern that corresponds to an anydata, container, leaf, leaf-list, or list data node.
2. 对第1项中描述的命名模式的引用必须作为与anydata、container、leaf、leaf list或list data节点相对应的每个<rng:element>模式的子级包含。
3. Every metadata annotation definition in the form
3. 表单中的每个元数据注释定义
md:annotation ARGUMENT { ... }
md:annotation ARGUMENT { ... }
is mapped to the following RELAX NG [ISO.19757-2] pattern:
映射到以下RELAX NG[ISO.19757-2]模式:
<rng:optional> <rng:attribute name="PREFIX:ARGUMENT"> ... </rng:attribute> </rng:optional>
<rng:optional> <rng:attribute name="PREFIX:ARGUMENT"> ... </rng:attribute> </rng:optional>
where PREFIX is the prefix bound to the namespace URI of the YANG module that contains the "md:annotation" statement. The above pattern SHALL be inserted as a child of the named pattern described in item 1.
其中PREFIX是绑定到包含“md:annotation”语句的模块的命名空间URI的前缀。上述模式应作为第1项所述命名模式的子模式插入。
4. Substatements of "md:annotation" SHALL be mapped to children of the "rng:attribute" pattern exactly as described in Section 10 of [RFC6110].
4. “md:annotation”的子状态应完全按照[RFC6110]第10节所述映射到“rng:attribute”模式的子状态。
For example, the named pattern (item 1), when constructed only for the "last-modified" annotation, will have the following definition:
例如,当仅为“上次修改”注释构造命名模式(项目1)时,将具有以下定义:
<rng:define name="__yang_metadata__"> <rng:optional> <rng:attribute name="elm:last-modified"> <rng:ref name="ietf-yang-types__date-and-time"/> </rng:attribute> </rng:optional> </rng:define>
<rng:define name="__yang_metadata__"> <rng:optional> <rng:attribute name="elm:last-modified"> <rng:ref name="ietf-yang-types__date-and-time"/> </rng:attribute> </rng:optional> </rng:define>
Every "rng:element" pattern that corresponds to an anydata, container, leaf, list, or leaf-list data node will then contain a reference to the above named pattern; for example:
与anydata、container、leaf、list或leaf-list数据节点相对应的每个“rng:element”模式将包含对上述模式的引用;例如:
<rng:element name="foo:bar"> <rng:ref name="__yang_metadata__"/> ... </rng:element>
<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.
请注意,对于对应于任何XML数据节点的“rng:element”模式,不必使用这样的引用,因为它们已经允许将任何XML属性附加到它们的实例。
The second step of the DSDL mapping procedure, i.e., the transformation of the hybrid schema to RELAX NG [ISO.19757-2], Schematron [ISO.19757-3], and Document Semantics Renaming Language (DSRL) [ISO.19757-8] schemas, is unaffected by the inclusion of "md:annotation".
DSDL映射过程的第二步,即将混合模式转换为RELAXNG[ISO.19757-2]、Schematron[ISO.19757-3]和文档语义重命名语言(DSRL)[ISO.19757-8]模式,不受包含“md:annotation”的影响。
<CODE BEGINS> file "ietf-yang-metadata@2016-08-05.yang"
<CODE BEGINS> file "ietf-yang-metadata@2016-08-05.yang"
module ietf-yang-metadata {
ietf模块{
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-metadata";
namespace "urn:ietf:params:xml:ns:yang:ietf-yang-metadata";
prefix "md";
前缀“md”;
organization "IETF NETMOD (NETCONF Data Modeling Language) Working Group";
组织“IETF NETMOD(NETCONF数据建模语言)工作组”;
contact "WG Web: <https://datatracker.ietf.org/wg/netmod/>
contact "WG Web: <https://datatracker.ietf.org/wg/netmod/>
WG List: <mailto:netmod@ietf.org>
WG List: <mailto:netmod@ietf.org>
WG Chair: Lou Berger <mailto:lberger@labn.net>
WG Chair: Lou Berger <mailto:lberger@labn.net>
WG Chair: Kent Watsen <mailto:kwatsen@juniper.net>
WG Chair: Kent Watsen <mailto:kwatsen@juniper.net>
Editor: Ladislav Lhotka <mailto:lhotka@nic.cz>";
Editor: Ladislav Lhotka <mailto:lhotka@nic.cz>";
description "This YANG module defines an 'extension' statement that allows for defining metadata annotations.
description“此模块定义了一个允许定义元数据注释的“extension”语句。
Copyright (c) 2016 IETF Trust and the persons identified as authors of the code. All rights reserved.
版权所有(c)2016 IETF信托基金和被确定为代码作者的人员。版权所有。
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).
根据IETF信托有关IETF文件的法律规定第4.c节规定的简化BSD许可证中包含的许可条款,允许以源代码和二进制格式重新分发和使用,无论是否修改(http://trustee.ietf.org/license-info).
This version of this YANG module is part of RFC 7952 (http://www.rfc-editor.org/info/rfc7952); see the RFC itself for full legal notices.";
This version of this YANG module is part of RFC 7952 (http://www.rfc-editor.org/info/rfc7952); see the RFC itself for full legal notices.";
revision 2016-08-05 { description "Initial revision."; reference "RFC 7952: Defining and Using Metadata with YANG"; }
revision 2016-08-05 { description "Initial revision."; reference "RFC 7952: 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 or submodule, i.e., it becomes a new alternative in the ABNF production rule for 'body-stmts' (Section 14 in RFC 7950).
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 or submodule, i.e., it becomes a new alternative in the ABNF production rule for 'body-stmts' (Section 14 in RFC 7950).
The argument of the 'md:annotation' statement defines the name of the annotation. Syntactically, it is a YANG identifier as defined in Section 6.2 of RFC 7950.
“md:annotation”语句的参数定义注释的名称。在语法上,它是RFC 7950第6.2节中定义的YANG标识符。
An annotation defined with this 'extension' statement inherits the namespace and other context from the YANG module in which it is defined.
使用此“extension”语句定义的注释从定义它的模块继承名称空间和其他上下文。
The data type of the annotation value is specified in the same way as for a leaf data node using the 'type' statement.
注释值的数据类型的指定方式与使用“type”语句的叶数据节点相同。
The semantics of the annotation and other documentation can be specified using the following standard YANG substatements (all are optional): 'description', 'if-feature', 'reference', 'status', and 'units'.
注释和其他文档的语义可以使用以下标准子语句指定(所有子语句都是可选的):“描述”、“如果特征”、“参考”、“状态”和“单位”。
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 a NETCONF <hello> message or in the YANG library (RFC 7950). The annotation can then be attached to any instance of a data node defined in any YANG module that is advertised by the server.
服务器通过包括在广告模块中定义注释的模块来宣布对特定注释的支持,例如,在NETCONF<hello>消息或YANG库(RFC 7950)中。然后,可以将注释附加到服务器播发的任何模块中定义的数据节点的任何实例。
XML encoding and JSON encoding of annotations are defined in RFC 7952."; } }
XML encoding and JSON encoding of annotations are defined in RFC 7952."; } }
<CODE ENDS>
<代码结束>
This document registers a URI in the "IETF XML Registry" [RFC3688]. Following the format in RFC 3688, the following registration has been made.
本文档在“IETF XML注册表”[RFC3688]中注册URI。按照RFC 3688中的格式,进行了以下注册。
--------------------------------------------------------------------- URI: urn:ietf:params:xml:ns:yang:ietf-yang-metadata
--------------------------------------------------------------------- URI: urn:ietf:params:xml:ns:yang:ietf-yang-metadata
Registrant Contact: The NETMOD WG of the IETF.
注册人联系人:IETF的NETMOD工作组。
XML: N/A, the requested URI is an XML namespace. ---------------------------------------------------------------------
XML: N/A, the requested URI is an XML namespace. ---------------------------------------------------------------------
This document registers a YANG module in the "YANG Module Names" registry [RFC6020].
本文件在“阳模块名称”注册表[RFC6020]中注册阳模块。
--------------------------------------------------------------------- Name: ietf-yang-metadata Namespace: urn:ietf:params:xml:ns:yang:ietf-yang-metadata Prefix: md Reference: RFC 7952 ---------------------------------------------------------------------
--------------------------------------------------------------------- Name: ietf-yang-metadata Namespace: urn:ietf:params:xml:ns:yang:ietf-yang-metadata Prefix: md Reference: RFC 7952 ---------------------------------------------------------------------
This document introduces a mechanism for defining metadata annotations in YANG modules and attaching them to instances of YANG data nodes. By itself, this mechanism represents no security threat. Security implications of a particular annotation defined using this mechanism MUST be duly considered and documented in the annotation's definition.
本文介绍了一种在YANG模块中定义元数据注释并将其附加到YANG数据节点实例的机制。这一机制本身并不构成安全威胁。必须在注释的定义中适当考虑并记录使用此机制定义的特定注释的安全含义。
An annotation SHOULD be subject to the same or stricter access control rules as the data node instance to which the annotation is attached. It is RECOMMENDED that security-sensitive or privacy-sensitive data be modeled as regular YANG data nodes rather than annotations.
注释应遵守与附加注释的数据节点实例相同或更严格的访问控制规则。建议将安全敏感或隐私敏感数据建模为常规数据节点,而不是注释。
[RFC2119] Bradner, S., "Key words for use in RFCs to Indicate Requirement Levels", BCP 14, RFC 2119, DOI 10.17487/RFC2119, March 1997, <http://www.rfc-editor.org/info/rfc2119>.
[RFC2119]Bradner,S.,“RFC中用于表示需求水平的关键词”,BCP 14,RFC 2119,DOI 10.17487/RFC2119,1997年3月<http://www.rfc-editor.org/info/rfc2119>.
[RFC3688] Mealling, M., "The IETF XML Registry", BCP 81, RFC 3688, DOI 10.17487/RFC3688, January 2004, <http://www.rfc-editor.org/info/rfc3688>.
[RFC3688]Mealling,M.,“IETF XML注册表”,BCP 81,RFC 3688,DOI 10.17487/RFC3688,2004年1月<http://www.rfc-editor.org/info/rfc3688>.
[RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax Specifications: ABNF", STD 68, RFC 5234, DOI 10.17487/RFC5234, January 2008, <http://www.rfc-editor.org/info/rfc5234>.
[RFC5234]Crocker,D.,Ed.和P.Overell,“语法规范的扩充BNF:ABNF”,STD 68,RFC 5234,DOI 10.17487/RFC5234,2008年1月<http://www.rfc-editor.org/info/rfc5234>.
[RFC6020] Bjorklund, M., Ed., "YANG - A Data Modeling Language for the Network Configuration Protocol (NETCONF)", RFC 6020, DOI 10.17487/RFC6020, October 2010, <http://www.rfc-editor.org/info/rfc6020>.
[RFC6020]Bjorklund,M.,Ed.“YANG-网络配置协议的数据建模语言(NETCONF)”,RFC 6020,DOI 10.17487/RFC6020,2010年10月<http://www.rfc-editor.org/info/rfc6020>.
[RFC6110] Lhotka, L., Ed., "Mapping YANG to Document Schema Definition Languages and Validating NETCONF Content", RFC 6110, DOI 10.17487/RFC6110, February 2011, <http://www.rfc-editor.org/info/rfc6110>.
[RFC6110]Lhotka,L.,Ed.“将YANG映射到文档模式定义语言并验证NETCONF内容”,RFC 6110,DOI 10.17487/RFC6110,2011年2月<http://www.rfc-editor.org/info/rfc6110>.
[RFC7159] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data Interchange Format", RFC 7159, DOI 10.17487/RFC7159, March 2014, <http://www.rfc-editor.org/info/rfc7159>.
[RFC7159]Bray,T.,Ed.“JavaScript对象表示法(JSON)数据交换格式”,RFC 7159,DOI 10.17487/RFC7159,2014年3月<http://www.rfc-editor.org/info/rfc7159>.
[RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", RFC 7950, DOI 10.17487/RFC7950, August 2016, <http://www.rfc-editor.org/info/rfc7950>.
[RFC7950]Bjorklund,M.,Ed.“YANG 1.1数据建模语言”,RFC 7950,DOI 10.17487/RFC7950,2016年8月<http://www.rfc-editor.org/info/rfc7950>.
[RFC7951] Lhotka, L., "JSON Encoding of Data Modeled with YANG", RFC 7951, DOI 10.17487/RFC7951, August 2016, <http://www.rfc-editor.org/info/rfc7951>.
[RFC7951]Lhotka,L.,“用YANG建模的数据的JSON编码”,RFC 7951,DOI 10.17487/RFC7951,2016年8月<http://www.rfc-editor.org/info/rfc7951>.
[XML-INFOSET] Cowan, J. and R. Tobin, "XML Information Set (Second Edition)", World Wide Web Consortium Recommendation REC-xml-infoset-20040204, February 2004, <http://www.w3.org/TR/2004/REC-xml-infoset-20040204>.
[XML-INFOSET]Cowan,J.和R.Tobin,“XML信息集(第二版)”,万维网联盟建议REC-XML-INFOSET-200402042004年2月<http://www.w3.org/TR/2004/REC-xml-infoset-20040204>.
[XML-NAMES] Bray, T., Hollander, D., Layman, A., Tobin, R., and H. Thompson, "Namespaces in XML 1.0 (Third Edition)", World Wide Web Consortium Recommendation REC-xml-names-20091208, December 2009, <http://www.w3.org/TR/2009/REC-xml-names-20091208>.
[XML-NAMES]Bray,T.,Hollander,D.,Layman,A.,Tobin,R.,和H.Thompson,“XML 1.0中的名称空间(第三版)”,万维网联盟建议REC-XML-NAMES-20091208,2009年12月<http://www.w3.org/TR/2009/REC-xml-names-20091208>.
[ISO.19757-1] International Organization for Standardization, "Information Technology - Document Schema Definition Languages (DSDL) - Part 1: Overview", ISO/IEC 19757-1, September 2008.
[ISO.19757-1]国际标准化组织,“信息技术-文档模式定义语言(DSDL)-第1部分:概述”,ISO/IEC 19757-12008年9月。
[ISO.19757-2] International Organization for Standardization, "Information technology -- Document Schema Definition Language (DSDL) -- Part 2: Regular-grammar-based validation -- RELAX NG", ISO/IEC 19757-2:2008, December 2008.
[ISO.19757-2]国际标准化组织,“信息技术——文档模式定义语言(DSDL)——第2部分:基于规则语法的验证——RELAXNG”,ISO/IEC 19757-2:2008,2008年12月。
[ISO.19757-3] International Organization for Standardization, "Information technology -- Document Schema Definition Languages (DSDL) -- Part 3: Rule-based validation -- Schematron", ISO/IEC 19757-3:2016, January 2016.
[ISO.19757-3]国际标准化组织,“信息技术——文档模式定义语言(DSDL)——第3部分:基于规则的验证——Schematron”,ISO/IEC 19757-3:2016,2016年1月。
[ISO.19757-8] International Organization for Standardization, "Information Technology - Document Schema Definition Languages (DSDL) - Part 8: Document Semantics Renaming Language - DSRL", ISO/IEC 19757-8:2008(E), December 2008.
[ISO.19757-8]国际标准化组织,“信息技术-文档模式定义语言(DSDL)-第8部分:文档语义重命名语言-DSRL”,ISO/IEC 19757-8:2008(E),2008年12月。
[RESTCONF] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF Protocol", Work in Progress, draft-ietf-netconf-restconf-16, August 2016.
[RESTCONF]Bierman,A.,Bjorklund,M.,和K.Watsen,“RESTCONF协议”,正在进行的工作,草稿-ietf-netconf-RESTCONF-162016年8月。
[RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed., and A. Bierman, Ed., "Network Configuration Protocol (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, <http://www.rfc-editor.org/info/rfc6241>.
[RFC6241]Enns,R.,Ed.,Bjorklund,M.,Ed.,Schoenwaeld,J.,Ed.,和A.Bierman,Ed.,“网络配置协议(NETCONF)”,RFC 6241,DOI 10.17487/RFC6241,2011年6月<http://www.rfc-editor.org/info/rfc6241>.
Acknowledgements
致谢
The author wishes to thank Andy Bierman, Martin Bjorklund, Benoit Claise, Juergen Schoenwaelder, and Kent Watsen for their helpful comments and suggestions.
作者要感谢安迪·比尔曼、马丁·比约克隆德、贝诺特·克莱斯、尤尔根·舍恩瓦埃尔德和肯特·沃特森提出了有益的意见和建议。
Author's Address
作者地址
Ladislav Lhotka CZ.NIC
拉迪斯拉夫·洛特卡CZ.NIC
Email: lhotka@nic.cz
Email: lhotka@nic.cz