YANG 1.1数据建模语言
YANG is a data modeling language used to model configuration data, state data, Remote Procedure Calls, and notifications for network management protocols. This document describes the syntax and semantics of version 1.1 of the YANG language. YANG version 1.1 is a maintenance release of the YANG language, addressing ambiguities and defects in the original specification. There are a small number of backward incompatibilities from YANG version 1. This document also specifies the YANG mappings to the Network Configuration Protocol (NETCONF).
YANG是一种数据建模语言,用于为网络管理协议的配置数据、状态数据、远程过程调用和通知建模。本文档描述了YANG语言1.1版的语法和语义。YANG版本1.1是YANG语言的维护版本,解决了原始规范中的歧义和缺陷。YANG版本1中存在少量向后不兼容。本文档还指定了到网络配置协议(NETCONF)的映射。
这是一份互联网标准跟踪文件。本文件是互联网工程任务组(IETF)的产品。它代表了IETF社区的共识。它已经接受了公众审查,并已被互联网工程指导小组(IESG)批准出版。有关互联网标准的更多信息,请参见RFC 7841第2节
YANG is a data modeling language originally designed to model configuration and state data manipulated by the Network Configuration Protocol (NETCONF), NETCONF Remote Procedure Calls, and NETCONF notifications [RFC6241]. Since the publication of YANG version 1 [RFC6020], YANG has been used or proposed to be used for other protocols (e.g., RESTCONF [RESTCONF] and the Constrained Application Protocol (CoAP) Management Interface (CoMI) [CoMI]). Further, encodings other than XML have been proposed (e.g., JSON [RFC7951]).
YANG是一种数据建模语言,最初设计用于对由网络配置协议(NETCONF)、NETCONF远程过程调用和NETCONF通知[RFC6241]操作的配置和状态数据进行建模。自YANG版本1[RFC6020]发布以来,YANG已被用于或拟用于其他协议(例如RESTCONF[RESTCONF]和受限应用协议(CoAP)管理接口(CoMI)[CoMI])。此外,还提出了XML以外的编码(例如,JSON[RFC7951])。
This document describes the syntax and semantics of version 1.1 of the YANG language. It also describes how a data model defined in a YANG module is encoded in the Extensible Markup Language (XML) [XML] and how NETCONF operations are used to manipulate the data. Other protocols and encodings are possible but are out of scope for this specification.
本文档描述了YANG语言1.1版的语法和语义。它还描述了如何用可扩展标记语言(XML)[XML]对模块中定义的数据模型进行编码,以及如何使用NETCONF操作来操作数据。其他协议和编码是可能的,但不在本规范的范围内。
In terms of developing YANG data models, [YANG-Guidelines] provides some guidelines and recommendations.
在开发YANG数据模型方面,[YANG指南]提供了一些指南和建议。
Note that this document does not obsolete RFC 6020 [RFC6020].
请注意,本文件并未废除RFC 6020[RFC6020]。
This document defines version 1.1 of the YANG language. YANG version 1.1 is a maintenance release of the YANG language, addressing ambiguities and defects in the original specification [RFC6020].本文件定义了YANG语言的1.1版。YANG版本1.1是YANG语言的维护版本,解决了原始规范[RFC6020]中的歧义和缺陷。
The following changes are not backward compatible with YANG version 1:以下更改与YANG版本1不向后兼容:
o Changed the rules for the interpretation of escaped characters in double-quoted strings. This is a backward-incompatible change from YANG version 1. When updating a YANG version 1 module to 1.1 and the module uses a character sequence that is now illegal, the string must be changed to match the new rules. See Section 6.1.3 for details. 更改了双引号字符串中转义字符的解释规则。这是对YANG版本1的向后不兼容更改。当将版本1模块更新为1.1并且模块使用的字符序列现在是非法的时,必须更改字符串以匹配新规则。详见第6.1.3节。
o An unquoted string cannot contain any single or double quote characters. This is a backward-incompatible change from YANG version 1. When updating a YANG version 1 module to 1.1 and the module uses such quote characters, the string must be changed to match the new rules. See Section 6.1.3 for details. 未加引号的字符串不能包含任何单引号或双引号字符。这是对YANG版本1的向后不兼容更改。将第1版模块更新为1.1版时,如果模块使用此类引号字符,则必须更改字符串以匹配新规则。详见第6.1.3节。
o Made “when” and “if-feature” illegal on list keys. This is a backward-incompatible change from YANG version 1. When updating a YANG version 1 module to 1.1 and the module uses these constructs, they must be removed to match the new rules. 使列表键上的“何时”和“如果”功能非法。这是对YANG版本1的向后不兼容更改。将第1版模块更新为1.1版并且模块使用这些结构时,必须删除这些结构以匹配新规则。
o Defined the legal characters in YANG modules. When updating a YANG version 1 module to 1.1, any characters that are now illegal must be removed. See Section 6 for details. 定义了杨模块中的法律特征。将1版模块更新为1.1时,必须删除所有现在非法的字符。详见第6节。
o Made noncharacters illegal in the built-in type “string”. This change affects the runtime behavior of YANG-based protocols. 使内置类型“string”中的非字符非法。此更改会影响基于YANG的协议的运行时行为。
The following additional changes have been done to YANG:对YANG进行了以下附加更改:
o Changed the YANG version from “1” to “1.1”. 将YANG版本从“1”更改为“1.1”。
o Made the “yang-version” statement mandatory in YANG version “1.1”. 在杨版“1.1”中强制执行“杨版”声明。
o Extended the “if-feature” syntax to be a boolean expression over feature names. 扩展了“if feature”语法,使其成为功能名称上的布尔表达式。
o Allow “if-feature” in “bit”, “enum”, and “identity”. 允许在“位”、“枚举”和“标识”中使用“如果特征”。
o Allow “if-feature” in “refine”. 在“优化”中允许“如果特征”。
o Allow “choice” as a shorthand “case” statement (see Section 7.9.2). 允许“选择”作为简写的“案例”陈述(见第7.9.2节)。
o Added a new substatement “modifier” to the “pattern” statement (see Section 9.4.6). 在“模式”语句中添加了新的子语句“修饰符”(见第9.4.6节)。
o Allow “must” in “input”, “output”, and “notification”. 在“输入”、“输出”和“通知”中允许“必须”。
o Allow “require-instance” in leafref. 允许在leafref中使用“require instance”。
o Allow “description” and “reference” in “import” and “include”. 在“导入”和“包含”中允许“说明”和“引用”。
o Allow imports of multiple revisions of a module. 允许导入模块的多个修订版。
o Allow “augment” to add conditionally mandatory nodes (see Section 7.17). 允许“增强”添加有条件的强制性节点(见第7.17节)。
o Added a set of new XML Path Language (XPath) functions in Section 10. 在第10节中添加了一组新的XML路径语言(XPath)函数。
o Clarified the XPath context’s tree in Section 6.4.1. 在第6.4.1节中阐明了XPath上下文的树。
o Defined the string value of an identityref in XPath expressions (see Section 9.10). 在XPath表达式中定义identityref的字符串值(请参见第9.10节)。
o Clarified what unprefixed names mean in leafrefs in typedefs (see Sections 6.4.1 and 9.9.2). 阐明typedefs中leafrefs中未固定名称的含义(见第6.4.1节和第9.9.2节)。
o Allow identities to be derived from multiple base identities (see Sections 7.18 and 9.10). 允许从多个基本标识派生标识(见第7.18节和第9.10节)。
o Allow enumerations and bits to be subtyped (see Sections 9.6 and 9.7). 允许对枚举和位进行子类型化(参见第9.6节和第9.7节)。
o Allow leaf-lists to have default values (see Section 7.7.2). 允许叶列表具有默认值(见第7.7.2节)。
o Allow non-unique values in non-configuration leaf-lists (see Section 7.7). 在非配置叶列表中允许非唯一值(见第7.7节)。
o Use syntax for case-sensitive strings (as per [RFC7405]) in the grammar. 语法中区分大小写的字符串使用语法(按照[RFC7405])。
o Changed the module advertisement mechanism (see Section 5.6.4). 更改了模块广告机制(见第5.6.4节)。
o Changed the scoping rules for definitions in submodules. A submodule can now reference all definitions in all submodules that belong to the same module, without using the “include” statement. 更改了子模块中定义的作用域规则。子模块现在可以引用属于同一模块的所有子模块中的所有定义,而无需使用“include”语句。
o Added a new statement “action”, which is used to define operations tied to data nodes. 添加了一个新语句“action”,用于定义绑定到数据节点的操作。
o Allow notifications to be tied to data nodes.允许将通知绑定到数据节点。
o Added a new data definition statement “anydata” (see Section 7.10), which is RECOMMENDED to be used instead of “anyxml” when the data can be modeled in YANG. 添加了一个新的数据定义语句“anydata”(参见第7.10节),建议在数据可以用XML建模时使用该语句代替“anyxml”。
o Allow types “empty” and “leafref” in unions.允许在联合中使用类型“empty”和“leafref”。
o Allow type “empty” in a key.允许在键中键入“empty”。
o Removed the restriction that identifiers could not start with the characters “xml”. 删除了标识符不能以字符“xml”开头的限制。
The following changes have been done to the NETCONF mapping:
对NETCONF映射进行了以下更改:
o A server advertises support for YANG 1.1 modules by using ietf-yang-library [RFC7895] instead of listing them as capabilities in the <hello> message. 服务器通过使用ietf YANG library[RFC7895]而不是在<hello>消息中将其作为功能列出,来宣传对YANG 1.1模块的支持。
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].本文件中的关键词“必须”、“不得”、“必需”、“应”、“不应”、“建议”、“不建议”、“可”和“可选”应按照BCP 14[RFC2119]中的说明进行解释。
This non-normative section is intended to give a high-level overview of YANG to first-time readers.
本非规范性章节旨在向初次阅读的读者提供杨的高级概述。
YANG is a language originally designed to model data for the NETCONF protocol. A YANG module defines hierarchies of data that can be used for NETCONF-based operations, including configuration, state data, RPCs, and notifications. This allows a complete description of all data sent between a NETCONF client and server. Although out of scope for this specification, YANG can also be used with protocols other than NETCONF.
YANG是一种最初设计用于为NETCONF协议建模数据的语言。模块定义了可用于基于NETCONF的操作的数据层次结构,包括配置、状态数据、RPC和通知。这允许完整描述NETCONF客户端和服务器之间发送的所有数据。尽管超出了本规范的范围,但YANG也可用于NETCONF以外的协议。
YANG models the hierarchical organization of data as a tree in which each node has a name, and either a value or a set of child nodes. YANG provides clear and concise descriptions of the nodes, as well as the interaction between those nodes.
YANG将数据的分层组织建模为一棵树,其中每个节点都有一个名称、一个值或一组子节点。YANG对节点以及这些节点之间的交互进行了清晰简洁的描述。
YANG structures data models into modules and submodules. A module can import definitions from other external modules and can include definitions from submodules. The hierarchy can be augmented, allowing one module to add data nodes to the hierarchy defined in another module. This augmentation can be conditional, with new nodes appearing only if certain conditions are met.
YANG将数据模型分为模块和子模块。模块可以从其他外部模块导入定义,也可以包含子模块的定义。层次结构可以扩充,允许一个模块向另一个模块中定义的层次结构添加数据节点。这种扩展可以是有条件的,只有在满足某些条件时才会出现新节点。
YANG data models can describe constraints to be enforced on the data, restricting the presence or value of nodes based on the presence or value of other nodes in the hierarchy. These constraints are enforceable by either the client or the server.
YANG数据模型可以描述对数据实施的约束,根据层次结构中其他节点的存在或值限制节点的存在或值。这些约束可由客户端或服务器强制执行。
YANG defines a set of built-in types and has a type mechanism through which additional types may be defined. Derived types can restrict their base type’s set of valid values using mechanisms like range or pattern restrictions that can be enforced by clients or servers. They can also define usage conventions for use of the derived type, such as a string-based type that contains a hostname.
YANG定义了一组内置类型,并具有一种类型机制,通过该机制可以定义其他类型。派生类型可以使用诸如范围或模式限制之类的机制来限制其基类型的有效值集,这些机制可以由客户端或服务器强制实施。它们还可以定义使用派生类型的使用约定,例如包含主机名的基于字符串的类型。
YANG permits the definition of reusable groupings of nodes. The usage of these groupings can refine or augment the nodes, allowing it to tailor the nodes to its particular needs. Derived types and groupings can be defined in one module and used in either the same module or another module that imports it.
YANG允许定义可重用的节点分组。这些分组的使用可以细化或扩充节点,使其能够根据特定需求定制节点。派生类型和分组可以在一个模块中定义,并在同一个模块或导入它的另一个模块中使用。
YANG data hierarchy constructs include defining lists where list entries are identified by keys that distinguish them from each other. Such lists may be defined as either sorted by user or automatically sorted by the system. For user-sorted lists, operations are defined for manipulating the order of the list entries.
数据层次结构包括定义列表,其中列表项由键标识,键将它们彼此区分开来。此类列表可定义为按用户排序或由系统自动排序。对于用户排序的列表,定义了用于操纵列表项顺序的操作。
YANG modules can be translated into an equivalent XML syntax called YANG Independent Notation (YIN) (Section 13), allowing applications using XML parsers and Extensible Stylesheet Language Transformations (XSLT) scripts to operate on the models. The conversion from YANG to YIN is semantically lossless, so content in YIN can be round-tripped back into YANG.
YANG模块可以转换为一种等价的XML语法,称为YANG独立表示法(YIN)(第13节),允许使用XML解析器和可扩展样式表语言转换(XSLT)脚本的应用程序在模型上操作。从阳到阴的转换在语义上是无损的,因此阴中的内容可以循环回到阳中。
YANG is an extensible language, allowing extensions to be defined by standards bodies, vendors, and individuals. The statement syntax allows these extensions to coexist with standard YANG statements in a natural way, while extensions in a YANG module stand out sufficiently for the reader to notice them.
YANG是一种可扩展语言,允许标准机构、供应商和个人定义扩展。语句语法允许这些扩展以一种自然的方式与标准的YANG语句共存,而YANG模块中的扩展足以让读者注意到它们。
YANG resists the tendency to solve all possible problems, limiting the problem space to allow expression of data models for network management protocols such as NETCONF, not arbitrary XML documents or arbitrary data models.
YANG抵制解决所有可能问题的趋势,限制了问题空间,以允许网络管理协议(如NETCONF)的数据模型表达,而不是任意XML文档或任意数据模型。
To the extent possible, YANG maintains compatibility with the Simple Network Management Protocol’s (SNMP’s) SMIv2 (Structure of Management Information version 2 [RFC2578] [RFC2579]). SMIv2-based MIB modules can be automatically translated into YANG modules for read-only access [RFC6643]. However, YANG is not concerned with reverse translation from YANG to SMIv2.
YANG尽可能保持与简单网络管理协议(SNMP)SMIv2(管理信息结构版本2[RFC2578][RFC2579])的兼容性。基于SMIv2的MIB模块可以自动转换为只读访问的模块[RFC6643]。然而,杨并不关心从杨到SMIv2的反向翻译。
This section introduces some important constructs used in YANG that will aid in the understanding of the language specifics in later sections.
本节介绍YANG中使用的一些重要结构,这些结构将有助于理解后面章节中的语言细节。
YANG data models are defined in modules. A module contains a collection of related definitions.
YANG数据模型在模块中定义。模块包含相关定义的集合。
A module contains three types of statements: module header statements, “revision” statements, and definition statements. The module header statements describe the module and give information about the module itself, the “revision” statements give information about the history of the module, and the definition statements are the body of the module where the data model is defined.
模块包含三种类型的语句:模块标题语句、“修订”语句和定义语句。模块标题语句描述模块并提供关于模块本身的信息,“修订”语句提供关于模块历史的信息,定义语句是定义数据模型的模块主体。
A server may implement a number of modules, allowing multiple views of the same data or multiple views of disjoint subsections of the server’s data. Alternatively, the server may implement only one module that defines all available data.
服务器可以实现多个模块,允许相同数据的多个视图或服务器数据不相交子部分的多个视图。或者,服务器可以仅实现一个定义所有可用数据的模块。
A module may have portions of its definitions separated into submodules, based on the needs of the module designer. The external view remains that of a single module, regardless of the presence or size of its submodules.
根据模块设计者的需要,模块可以将其定义的部分划分为子模块。外部视图保持单个模块的视图,无论其子模块的存在或大小。
The “import” statement allows a module or submodule to reference definitions defined in other modules.
“import”语句允许模块或子模块引用在其他模块中定义的定义。
The “include” statement is used in a module to identify each submodule that belongs to it.
“include”语句在模块中用于标识属于它的每个子模块。
YANG defines four main types of data nodes for data modeling. In each of the following subsections, the examples show the YANG syntax as well as a corresponding XML encoding. The syntax of YANG statements is defined in Section 6.3.
YANG为数据建模定义了四种主要类型的数据节点。在下面的每个小节中,示例都显示了YANG语法以及相应的XML编码。YANG语句的语法定义见第6.3节。
4.2.2.1. Leaf Nodes 叶节点
A leaf instance contains simple data like an integer or a string. It has exactly one value of a particular type and no child nodes.
叶实例包含简单的数据,如整数或字符串。它只有一个特定类型的值,并且没有子节点。
YANG举例:
leaf host-name {
type string;
description
"Hostname for this system.";
}
XML Encoding Example:
<host-name>my.example.com</host-name>
The “leaf” statement is covered in Section 7.6.
4.2.2.2. 叶列表节点
A leaf-list defines a sequence of values of a particular type. /叶列表定义特定类型的值序列。
YANG举例:
leaf-list domain-search {
type string;
description
"List of domain names to search.";
}
XML Encoding Example:XML编码示例:
<domain-search>high.example.com</domain-search>
<domain-search>low.example.com</domain-search>
<domain-search>everywhere.example.com</domain-search>
4.2.2.3. 容器节点
A container is used to group related nodes in a subtree. A container has only child nodes and no value. A container may contain any number of child nodes of any type (leafs, lists, containers, leaf-lists, actions, and notifications).
容器用于将子树中的相关节点分组。容器只有子节点,没有值。容器可以包含任意数量的任意类型的子节点(叶、列表、容器、叶列表、操作和通知)。
YANG:
container system {
container login {
leaf message {
type string;
description
"Message given at start of login session.";
}
}
}
XML Encoding Example:XML编码示例:
<system>
<login>
<message>Good morning</message>
</login>
</system>
YANG can model state data, as well as configuration data, based on the “config” statement. When a node is tagged with “config false”, its subhierarchy is flagged as state data. If it is tagged with “config true”, its subhierarchy is flagged as configuration data. Parent containers, lists, and key leafs are reported also, giving the context for the state data.
YANG可以根据“config”语句对状态数据和配置数据进行建模。当一个节点被标记为“config false”时,它的子层次结构被标记为状态数据。如果它被标记为“config true”,则其子层次结构被标记为配置数据。还报告父容器、列表和键叶,为状态数据提供上下文。
In this example, two leafs are defined for each interface, a configured speed and an observed speed.
在本例中,为每个接口定义了两个LEAF,一个配置速度和一个观察速度。
list interface {
key "name";
config true;
leaf name {
type string;
}
leaf speed {
type enumeration {
enum 10m;
enum 100m;
enum auto;
}
}
leaf observed-speed {
type uint32;
config false;
}
}
YANG has a set of built-in types, similar to those of many programming languages, but with some differences due to special requirements of network management. The following table summarizes the built-in types discussed in Section 9:
YANG有一组内置类型,类似于许多编程语言的类型,但由于网络管理的特殊要求而有所不同。下表总结了第9节中讨论的内置类型:
+---------------------+-------------------------------------+
| Name | Description |
+---------------------+-------------------------------------+
| binary | Any binary data |
| bits | A set of bits or flags |
| boolean | "true" or "false" |
| decimal64 | 64-bit signed decimal number |
| empty | A leaf that does not have any value |
| enumeration | One of an enumerated set of strings |
| identityref | A reference to an abstract identity |
| instance-identifier | A reference to a data tree node |
| int8 | 8-bit signed integer |
| int16 | 16-bit signed integer |
| int32 | 32-bit signed integer |
| int64 | 64-bit signed integer |
| leafref | A reference to a leaf instance |
| string | A character string |
| uint8 | 8-bit unsigned integer |
| uint16 | 16-bit unsigned integer |
| uint32 | 32-bit unsigned integer |
| uint64 | 64-bit unsigned integer |
| union | Choice of member types |
+---------------------+-------------------------------------+
The “type” statement is covered in Section 7.4. “类型”说明见第7.4节。