CBOR Encoding of Data Modeled with YANGTrilliant Networks Inc.610 Rue du LuxembourgGranbyQuebecJ2J 2V2Canada+14503750556michel.veillette@trilliantinc.comAcklio2bis rue de la ChataigneraieCesson-SevigneBretagne35510Francea@ackl.ioTridonic GmbH & Co KGFarbergasse 15DornbirnVorarlberg6850Austria+43664808926169abhinav.somaraju@tridonic.comLandis+Gyr30000 Mill Creek AveSuite 100AlpharettaGA30022US++16782581292randy.turner@landisgyr.comhttp://www.landisgyr.com/Acklio2bis rue de la châtaigneraieCesson-SévignéBretagne35510Franceana@ackl.io
Applications and Real-Time Area (art)
Internet Engineering Task ForceCBORThis document defines encoding rules for serializing configuration data, state data, RPC input and RPC output, Action input, Action output and notifications defined within YANG modules using the Concise Binary Object Representation (CBOR) .The specification of the YANG 1.1 data modelling language defines an XML encoding for data instances, i.e. contents of configuration datastores, state data, RPC inputs and outputs, action inputs and outputs, and event notifications.A new set of encoding rules has been defined to allow the use of the same data models in environments based on the JavaScript Object Notation (JSON) Data Interchange Format . This is accomplished in the JSON Encoding of Data Modeled with YANG specification .The aim of this document is to define a set of encoding rules for the Concise Binary Object Representation (CBOR) . The resulting encoding is more compact compared to XML and JSON and more suitable for Constrained Nodes and/or Constrained Networks as defined by .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 .The following terms are defined in :actionanydataanyxmldata nodedata treemodulenotificationRPCschema nodeschema treesubmoduleThe following terms are defined in :member namename of an identitynamespace-qualifiedThis specification also makes use of the following terminology:child: A schema node defined within a collection such as a container, a list, a case, a notification, an RPC input, an RPC output, an action input, an action output.delta : Difference between the SID assigned to the current schema node and the SID assigned to the parent.parent: The collection in which a schema node is defined.structured identifier or SID: Unsigned integer used to identify different YANG items.Within this document, CBOR binary contents are represented using an equivalent textual form called CBOR diagnostic notation as defined in section 6. This notation is used strictly for documentation purposes and is never used in the data serialization. below provides a summary of this notation.CBOR contentCBOR typeDiagnostic notationExampleCBOR encodingUnsigned integer0Decimal digits12318 7bNegative integer1Decimal digits prefixed by a minus sign-12338 7aByte string2Hexadecimal value enclosed between single quotes and prefixed by an ‘h’h’f15c’42 f15cText string3String of Unicode characters enclosed between double quotes“txt”63 747874Array4Comma-separated list of values within square brackets[ 1, 2 ]82 01 02Map5Comma-separated list of key : value pairs within curly braces{ 1: 123, 2: 456 }a2 01187b 021901c8Boolean7/20falsefalsef47/21truetruef5Null7/22nullnullf6Not assigned7/23undefinedundefinedf7The following extensions to the CBOR diagnostic notation are supported:Comments can be added to the end of each line. Any characters after a Pound sign (‘#’) outside of a string, up to the end of the line, are treated as a comment.Deltas are represented as numbers preceded by a ‘+’ or ‘–’ sign. The use of the ‘+’ sign for positive deltas represents an extension to the CBOR diagnostic notation as defined by section 6.This document defines CBOR encoding rules for YANG schema trees and their subtrees.Basic schema nodes such as leaf, leaf-list, list, anydata and anyxml can be encoded standalone. In this case, only the value of this schema node is encoded in CBOR. Identification of this value needs to be provided by some external means when required.A collection such as container, list instance, notification, RPC input, RPC output, action input and action output is serialized using a CBOR map in which each child schema node is encoded using a key and a value. This specification supports two type of keys; SID as defined in and member names as defined in . Each of these key type is encoded using a specific CBOR type which allows their interpretation during the deserialization process. The end user of this mapping specification can mandate the use of a specific key type or a specific subset of key types.In order to minimize the size of the encoded data, the proposed mapping avoid any unnecessary meta-information beyond those natively supported by CBOR. For instance, CBOR tags are used sorely in the case of the union datatype to distinguish explicitly the use of different YANG datatypes encoded using the same CBOR major type.It is expected that application entities generating and decoding CBOR contents have enough knowledge about the information processed in order to perform the expected task without the need of such extra meta-information.Schema node instances defined using the YANG modeling language are encoded using CBOR based on the rules defined in this section. We assume that the reader is
already familiar with both YANG and CBOR .Leafs MUST be encoded based on the encoding rules specified in .Collections such as containers, list instances, notifications, RPC inputs, RPC outputs, action inputs and action outputs MUST be encoded using a CBOR map data item (major type 5). A map is comprised of pairs of data items, with each data item consisting of a key and a value. Each key within the CBOR map is set to a data node identifier, each value is set to the value of this data node instance.This specification supports two type of keys; SID as defined in encoded using CBOR unsigned or signed integers and member names as defined in encoded using CBOR text strings. The use of CBOR byte strings for keys is reserved for future extensions.Keys implemented using SIDs MUST be encoded using a CBOR unsigned integer (major type 0) or CBOR signed integer (major type 1), depending on the actual value. Keys are set to the delta of the associated SID, delta values are computed as follows:The delta value is equal to the SID of the current schema node minus the SID of the parent schema node. When no parent exists in the context of use of this container, the delta is set to the SID of the current schema node (a parent with SID equal to zero is assumed).Delta values may result in a negative number, clients and servers MUST support negative deltas.The following example shows the encoding of the ‘system’ container using the SIDs defined in Appendix C.Definition example from :CBOR diagnostic notation:CBOR encoding:Keys implemented using member names MUST be encoded using a CBOR text string data item (major type 3). A namespace-qualified member name MUST be used for all members of a top-level collection, and then also whenever the namespaces of the schema node and its parent are different. In all other cases, the simple form of the member name MUST be used. Names and namespaces are defined in section 4.The following example shows the encoding of the the ‘system’ container using names. This example is described in .CBOR diagnostic notation:CBOR encoding:A leaf-list MUST be encoded using a CBOR array data item (major type 4).
Each entry of this array MUST be encoded using the rules defined by the YANG type specified.The following example shows the encoding the ‘search’ leaf-list containing the two entries, “ietf.org” and “ieee.org”.Definition example :CBOR diagnostic notation: [ “ietf.org”, “ieee.org” ]CBOR encoding: 82 68 696574662e6f7267 68 696565652e6f7267A list MUST be encoded using a CBOR array data item (major type 4). Each list instance within this CBOR array is encoded using a CBOR map data item (major type 5) based on the same rules as a YANG container as defined in .The follwoing example show the encoding a the ‘server’ list using the SIDs defined in Appendix C. It is important to note that the protocol or method using this mapping may carry a parent SID or may have the knowledge of this parent SID based on its context. In these cases, delta encoding can be performed based on this parent SID which minimizes the size of the encoded data.The following example shows the encoding of the ‘server’ list containing two enties. SIDs used in this example are defined in Appendix C. It is important to note that the protocol or method using this mapping may carry a parent SID or may have the knowledge of this parent SID based on its context. In these cases, delta encoding can be performed based on this parent SID which minimizes the size of the encoded data.Definition example from :CBOR diagnostic notation:CBOR encoding:The following example shows the encoding of the the ‘server’ list using names. This example is described in .CBOR diagnostic notation:CBOR encoding:An anydata serves as a container for an arbitrary set of schema nodes that otherwise appear as normal YANG-modeled data. An anydata instance is encoded using the same rules as a container, i.e., CBOR map. The requirement that anydata content can be modeled by YANG implies the following:Keys of any inner data nodes MUST be set to valid deltas or member names.The CBOR array MUST contain either unique scalar values (as a leaf-list, see ), or maps (as a list, see ).Values MUST follow the encoding rules of one of the datatypes listed in .An anyxml schema node is used to serialize an arbitrary CBOR content, i.e., its value can be any CBOR binary object.Leafs of type uint8, uint16, uint32 and uint64 MUST be encoded using a CBOR
unsigned integer data item (major type 0).The following example shows the encoding of leaf ‘mtu’ set to 1280 bytes.Definition example from :CBOR diagnostic notation: 1280CBOR encoding: 19 0500Leafs of type int8, int16, int32 and int64 MUST be encoded using either CBOR
unsigned integer (major type 0) or CBOR signed integer (major type 1), depending
on the actual value.The following example shows the encoding of leaf ‘timezone-utc-offset’ set to -300 minutes.Definition example from :CBOR diagnostic notation: -300CBOR encoding: 39 012bLeafs of type decimal64 MUST be encoded using either CBOR unsigned integer
(major type 0) or CBOR signed integer (major type 1), depending on the actual
value. The position of the decimal point is defined by the fraction-digits YANG statement and is not available in the CBOR encoding.The following example shows the encoding of leaf ‘my-decimal’ set to 2.57.Definition example from :CBOR diagnostic notation: 257CBOR encoding: 19 0101Leafs of type string MUST be encoded using a CBOR text string data item (major
type 3).The following example shows the encoding of leaf ‘name’ set to “eth0”.Definition example from :CBOR diagnostic notation: “eth0”CBOR encoding: 64 65746830Leafs of type boolean MUST be encoded using a CBOR true (major type 7, additional
information 21) or false data item (major type 7, additional information
20).The following example shows the encoding of leaf ‘enabled’ set to ‘true’.Definition example from :CBOR diagnostic notation: trueCBOR encoding: f5Leafs of type enumeration MUST be encoded using a CBOR unsigned integer (major type 0) or CBOR signed integer (major type 1), depending on the actual value. Enumeration values are either explicitly assigned using the YANG statement ‘value’ or automatically assigned based on the algorithm defined in section 9.6.4.2.The following example shows the encoding of leaf ‘oper-status’ set to ‘testing’.Definition example from :CBOR diagnostic notation: 3CBOR encoding: 03Leafs of type bits MUST be encoded using a CBOR byte string data item (major
type 2). Bits position are either explicitly assigned using the YANG statement
‘position’ or automatically assigned based on the algorithm defined in section 9.7.4.2.Bits position 0 to 7 are assigned to the first byte within the byte
string, bits 8 to 15 to the second byte, and subsequent bytes are assigned
similarly. Within each byte, bits are assigned from least to most significant.The following example shows the encoding of leaf ‘mybits’ with the ‘disable-nagle’ and ‘10-Mb-only’ flags set.Definition example from :CBOR diagnostic notation: h’05’CBOR encoding: 41 05Leafs of type binary MUST be encoded using a CBOR byte string data item (major
type 2).The following example shows the encoding of leaf ‘aes128-key’ set to 0x1f1ce6a3f42660d888d92a4d8030476e.Definition example:CBOR diagnostic notation: h’1f1ce6a3f42660d888d92a4d8030476e’CBOR encoding: 50 1f1ce6a3f42660d888d92a4d8030476eLeafs of type leafref MUST be encoded using the rules of the schema node referenced
by the ‘path’ YANG statement.The following example shows the encoding of leaf ‘interface-state-ref’ set to the value “eth1”.Definition example from :CBOR diagnostic notation: “eth1”CBOR encoding: 64 65746831This specification supports two approaches for encoding identityref, a SID as defined in or a name as defined in section 6.8.SIDs are globally unique and may be used as identityref. This approach is both compact and simple to implement. When SIDs are
used, identityref MUST be encoded using a CBOR unsigned integer data item (major type 0) and set to a SID allocated from a registered SID range.The following example shows the encoding of leaf ‘type’ set to the value ‘iana-if-type:ethernetCsmacd’ (SID 1180).Definition example from :CBOR diagnostic notation: 1180CBOR encoding: 19 049cAlternatively, an identityref may be encoded using a name as defined in section 6.8. When names are used, identityref MUST be encoded using a CBOR text string data item (major type 3). If the identity is defined in another module than the leaf node containing the identityref value, the namespace-qualified form MUST be used. Otherwise, both the simple and namespace-qualified forms are permitted. Names and namespaces are defined in section 4.The following example shows the encoding of the identity ‘iana-if-type:ethernetCsmacd’ using its name. This example is described in .CBOR diagnostic notation: “iana-if-type:ethernetCsmacd”CBOR encoding: 78 1b 69616e612d69662d747970653a65746865726e657443736d616364Leafs of type empty MUST be encoded using the CBOR null value (major type
7, additional information 22).The following example shows the encoding of leaf ‘is-router’ when present.Definition example from :CBOR diagnostic notation: nullCBOR encoding: f6Leafs of type union MUST be encoded using the rules associated with one of the types listed.
When used in a union, the following YANG datatypes are prefixed by CBOR tag to avoid confusion
between different YANG datatypes encoded using the same CBOR major type.bitsdecimal64enumerationidentityrefinstance-identifierleafref (Only when the datatype of the leaf referenced using the ‘path’ YANG statement require a CBOR tag)See for more information about these CBOR tags.The following example shows the encoding of leaf ‘ip-address’ when set to “2001:db8:a0b:12f0::1”.Definition example from :CBOR diagnostic notation: “2001:db8:a0b:12f0::1”CBOR encoding: 74 323030313a6462383a6130623a313266303a3a31This specification supports two approaches for encoding an instance-identifier, one based on SIDs as defined in and one based on names as defined in section 6.13.SIDs uniquely identify a data node. For a single instance data node, the SID is sufficient to identify this instance. For a multi-instance data node, a SID is combined with the list key(s) to identify each instance of this data node within the YANG list(s).Single instance data nodes MUST be encoded using a CBOR unsigned integer data item (major type 0) and set to the targeted data node SID.Multi-instances data nodes MUST be encoded using a CBOR array data item (major type 4) containing the following entries:The first entry MUST be encoded as a CBOR unsigned integer data item (major type 0) and set to the targeted data node SID.The following entries MUST contain the value of each key required to identify the instance of the targeted data node. These keys MUST be ordered as defined in the ‘key’ YANG statement, starting from top level list, and follow by each of the subordinate list(s).First example:The following example shows the encoding of a leaf of type instance-identifier which identify the data node “/system/contact” (SID 1737).Definition example from :CBOR diagnostic notation: 1737CBOR encoding: 19 06c9Second example:The following example shows the encoding of a leaf of type instance-identifier which identify the data node instance “/system/authentication/user/authorized-key/key-data” (SID 1730) for user name “bob” and authorized-key “admin”.Definition example from :CBOR diagnostic notation: [1730, “bob”, “admin”]CBOR encoding:Third example:The following example shows the encoding of a leaf of type instance-identifier which identify the list instance “/system/authentication/user” (SID 1726) corresponding to the user name “jack”.CBOR diagnostic notation: [1726, “jack”]CBOR encoding:The use of names as instance-identifier is defined in section 6.11. The resulting xpath MUST be encoded using a CBOR text string data item (major type 3).First example:This example is described in .CBOR diagnostic notation: “/ietf-system:system/contact”CBOR encoding:Second example:This example is described in .CBOR diagnostic notation:CBOR encoding:Third example:This example is described in .CBOR diagnostic notation:CBOR encoding:The security considerations of and apply.This document defines an alternative encoding for data modeled in the YANG data modeling language. As such, this encoding does not contribute any new security issues in addition of those identified for the specific protocol or context for which it is used.To minimize security risks, software on the receiving side SHOULD reject all messages that do not comply to the rules of this document and reply with an appropriate error message to the sender.This specification requires the assignment of CBOR tags for the following YANG datatypes.
These tags are added to the Tags Registry as defined in section 7.2 of .TagData ItemSemanticsReference40bitsYANG bits datatypeRFC XXXX41decimal64YANG decimal64 datatypeRFC XXXX42enumerationYANG enumeration datatypeRFC XXXX43identityrefYANG identityref datatypeRFC XXXX44instance-identifierYANG instance-identifier datatypeRFC XXXX// RFC Ed.: update Tag values using allocated tags if needed and remove this note
// RFC Ed.: replace XXXX with RFC number and remove this noteThis document has been largely inspired by the extensive works done by Andy Bierman and Peter van der Stok on . has also been a critical input to this work. The authors would like to thank the authors and contributors to these two drafts.The authors would also like to acknowledge the review, feedback, and comments from Ladislav Lhotka and Juergen Schoenwaelder.The YANG 1.1 Data Modeling LanguageYANG 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).Key words for use in RFCs to Indicate Requirement LevelsIn many standards track documents several words are used to signify the requirements in the specification. These words are often capitalized. This document defines these words as they should be interpreted in IETF documents. This document specifies an Internet Best Current Practices for the Internet Community, and requests discussion and suggestions for improvements.Concise Binary Object Representation (CBOR)The Concise Binary Object Representation (CBOR) is a data format whose design goals include the possibility of extremely small code size, fairly small message size, and extensibility without the need for version negotiation. These design goals make it different from earlier binary serializations such as ASN.1 and MessagePack.Structure Identifier (SID)Structured IDentifiers (SID) are used to identify different YANG items when encoded in CBOR. This document defines the registration and assignment processes of SIDs. To enable the implementation of these processes, this document also defines a file format used to persist and publish assigned SIDs.JSON Encoding of Data Modeled with YANGThis document defines encoding rules for representing configuration data, state data, parameters of RPC operations or actions, and notifications defined using YANG as JavaScript Object Notation (JSON) text.CoAP Management InterfaceThis document describes a network management interface for constrained devices, called CoMI. CoMI is an adaptation of the RESTCONF protocol for use in constrained devices and networks. The Constrained Application Protocol (CoAP) is used to access management data resources specified in YANG, or SMIv2 converted to YANG. CoMI use the YANG to CBOR mapping and encodes YANG names to reduce payload size. Note Discussion and suggestions for improvement are requested, and should be sent to core@ietf.org.The JavaScript Object Notation (JSON) Data Interchange FormatJavaScript Object Notation (JSON) is a lightweight, text-based, language-independent data interchange format. It was derived from the ECMAScript Programming Language Standard. JSON defines a small set of formatting rules for the portable representation of structured data.This document removes inconsistencies with other specifications of JSON, repairs specification errors, and offers experience-based interoperability guidance.A YANG Data Model for Interface ManagementThis document defines a YANG data model for the management of network interfaces. It is expected that interface-type-specific data models augment the generic interfaces data model defined in this document. The data model includes configuration data and state data (status information and counters for the collection of statistics).Terminology for Constrained-Node NetworksThe Internet Protocol Suite is increasingly used on small devices with severe constraints on power, memory, and processing resources, creating constrained-node networks. This document provides a number of basic terms that have been useful in the standardization work for constrained-node networks.A YANG Data Model for IP ManagementThis document defines a YANG data model for management of IP implementations. The data model includes configuration data and state data.A YANG Data Model for System ManagementThis document defines a YANG data model for the configuration and identification of some common system properties within a device containing a Network Configuration Protocol (NETCONF) server. This document also includes data node definitions for system identification, time-of-day management, user management, DNS resolver configuration, and some protocol operations for system management.