idnits 2.17.1 draft-ietf-core-yang-cbor-16.txt: -(9): Line appears to be too long, but this could be caused by non-ascii characters in UTF-8 encoding Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- == There are 3 instances of lines with non-ascii characters in the document. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (25 June 2021) is 1035 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Proposed Standard ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '-2' is mentioned on line 1210, but not defined -- Looks like a reference, but probably isn't: '257' on line 1210 == Missing Reference: '0-9' is mentioned on line 1563, but not defined == Missing Reference: '1-9' is mentioned on line 1554, but not defined == Missing Reference: '0-4' is mentioned on line 1563, but not defined == Missing Reference: '0-5' is mentioned on line 1563, but not defined == Missing Reference: '0-9a-fA-F' is mentioned on line 1562, but not defined -- Looks like a reference, but probably isn't: '01' on line 1563 == Outdated reference: A later version (-17) exists of draft-ietf-core-comi-11 == Outdated reference: A later version (-24) exists of draft-ietf-core-sid-15 Summary: 0 errors (**), 0 flaws (~~), 10 warnings (==), 4 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 Internet Engineering Task Force M. Veillette, Ed. 3 Internet-Draft Trilliant Networks Inc. 4 Intended status: Standards Track I. Petrov, Ed. 5 Expires: 27 December 2021 Google Switzerland GmbH 6 A. Pelov 7 Acklio 8 C. Bormann 9 Universität Bremen TZI 10 25 June 2021 12 CBOR Encoding of Data Modeled with YANG 13 draft-ietf-core-yang-cbor-16 15 Abstract 17 This document defines encoding rules for serializing configuration 18 data, state data, RPC input and RPC output, action input, action 19 output, notifications and the yang-data extension defined within YANG 20 modules using the Concise Binary Object Representation (CBOR, RFC 21 8949). 23 Status of This Memo 25 This Internet-Draft is submitted in full conformance with the 26 provisions of BCP 78 and BCP 79. 28 Internet-Drafts are working documents of the Internet Engineering 29 Task Force (IETF). Note that other groups may also distribute 30 working documents as Internet-Drafts. The list of current Internet- 31 Drafts is at https://datatracker.ietf.org/drafts/current/. 33 Internet-Drafts are draft documents valid for a maximum of six months 34 and may be updated, replaced, or obsoleted by other documents at any 35 time. It is inappropriate to use Internet-Drafts as reference 36 material or to cite them other than as "work in progress." 38 This Internet-Draft will expire on 27 December 2021. 40 Copyright Notice 42 Copyright (c) 2021 IETF Trust and the persons identified as the 43 document authors. All rights reserved. 45 This document is subject to BCP 78 and the IETF Trust's Legal 46 Provisions Relating to IETF Documents (https://trustee.ietf.org/ 47 license-info) in effect on the date of publication of this document. 48 Please review these documents carefully, as they describe your rights 49 and restrictions with respect to this document. Code Components 50 extracted from this document must include Simplified BSD License text 51 as described in Section 4.e of the Trust Legal Provisions and are 52 provided without warranty as described in the Simplified BSD License. 54 Table of Contents 56 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 57 2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3 58 3. Properties of the CBOR Encoding . . . . . . . . . . . . . . . 5 59 3.1. CBOR diagnostic notation . . . . . . . . . . . . . . . . 6 60 3.2. YANG Schema Item iDentifier . . . . . . . . . . . . . . . 8 61 3.3. Name . . . . . . . . . . . . . . . . . . . . . . . . . . 8 62 4. Encoding of YANG Schema Node Instances . . . . . . . . . . . 10 63 4.1. The 'leaf' . . . . . . . . . . . . . . . . . . . . . . . 10 64 4.1.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 10 65 4.1.2. Using names in keys . . . . . . . . . . . . . . . . . 11 66 4.2. The 'container' and other nodes from the data tree . . . 11 67 4.2.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 12 68 4.2.2. Using names in keys . . . . . . . . . . . . . . . . . 13 69 4.3. The 'leaf-list' . . . . . . . . . . . . . . . . . . . . . 14 70 4.3.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 14 71 4.3.2. Using names in keys . . . . . . . . . . . . . . . . . 15 72 4.4. The 'list' and 'list' entries . . . . . . . . . . . . . . 15 73 4.4.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 16 74 4.4.2. Using names in keys . . . . . . . . . . . . . . . . . 18 75 4.5. The 'anydata' . . . . . . . . . . . . . . . . . . . . . . 20 76 4.5.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 21 77 4.5.2. Using names in keys . . . . . . . . . . . . . . . . . 22 78 4.6. The 'anyxml' . . . . . . . . . . . . . . . . . . . . . . 23 79 4.6.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 23 80 4.6.2. Using names in keys . . . . . . . . . . . . . . . . . 24 81 5. Encoding of 'yang-data' extension . . . . . . . . . . . . . . 24 82 5.1. Using SIDs in keys . . . . . . . . . . . . . . . . . . . 25 83 5.2. Using names in keys . . . . . . . . . . . . . . . . . . . 26 84 6. Representing YANG Data Types in CBOR . . . . . . . . . . . . 27 85 6.1. The unsigned integer Types . . . . . . . . . . . . . . . 27 86 6.2. The integer Types . . . . . . . . . . . . . . . . . . . . 28 87 6.3. The 'decimal64' Type . . . . . . . . . . . . . . . . . . 28 88 6.4. The 'string' Type . . . . . . . . . . . . . . . . . . . . 29 89 6.5. The 'boolean' Type . . . . . . . . . . . . . . . . . . . 29 90 6.6. The 'enumeration' Type . . . . . . . . . . . . . . . . . 30 91 6.7. The 'bits' Type . . . . . . . . . . . . . . . . . . . . . 31 92 6.8. The 'binary' Type . . . . . . . . . . . . . . . . . . . . 33 93 6.9. The 'leafref' Type . . . . . . . . . . . . . . . . . . . 33 94 6.10. The 'identityref' Type . . . . . . . . . . . . . . . . . 34 95 6.10.1. SIDs as identityref . . . . . . . . . . . . . . . . 34 96 6.10.2. Name as identityref . . . . . . . . . . . . . . . . 35 98 6.11. The 'empty' Type . . . . . . . . . . . . . . . . . . . . 35 99 6.12. The 'union' Type . . . . . . . . . . . . . . . . . . . . 36 100 6.13. The 'instance-identifier' Type . . . . . . . . . . . . . 37 101 6.13.1. SIDs as instance-identifier . . . . . . . . . . . . 37 102 6.13.2. Names as instance-identifier . . . . . . . . . . . . 40 103 7. Content-Types . . . . . . . . . . . . . . . . . . . . . . . . 42 104 8. Security Considerations . . . . . . . . . . . . . . . . . . . 42 105 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 42 106 9.1. Media-Types Registry . . . . . . . . . . . . . . . . . . 42 107 9.2. CoAP Content-Formats Registry . . . . . . . . . . . . . . 43 108 9.3. CBOR Tags Registry . . . . . . . . . . . . . . . . . . . 44 109 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 44 110 10.1. Normative References . . . . . . . . . . . . . . . . . . 44 111 10.2. Informative References . . . . . . . . . . . . . . . . . 45 112 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . 46 113 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 47 115 1. Introduction 117 The specification of the YANG 1.1 data modeling language [RFC7950] 118 defines an XML encoding for data instances, i.e., contents of 119 configuration datastores, state data, RPC inputs and outputs, action 120 inputs and outputs, and event notifications. 122 An additional set of encoding rules has been defined in [RFC7951] 123 based on the JavaScript Object Notation (JSON) Data Interchange 124 Format [RFC8259]. 126 The aim of this document is to define a set of encoding rules for the 127 Concise Binary Object Representation (CBOR) [RFC8949]. The resulting 128 encoding is more compact compared to XML and JSON and more suitable 129 for Constrained Nodes and/or Constrained Networks as defined by 130 [RFC7228]. 132 2. Terminology and Notation 134 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 135 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 136 "OPTIONAL" in this document are to be interpreted as described in 137 BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all 138 capitals, as shown here. 140 The following terms are defined in [RFC7950]: 142 * action 144 * anydata 145 * anyxml 147 * data node 149 * data tree 151 * datastore 153 * feature 155 * identity 157 * module 159 * notification 161 * RPC 163 * schema node 165 * schema tree 167 * submodule 169 The following terms are defined in [RFC8040]: 171 * yang-data extension 173 This specification also makes use of the following terminology: 175 * child: A schema node defined as a child node of a container, a 176 list, a case, a notification, an RPC input, an RPC output, an 177 action input, or an action output. 179 * YANG Schema Item iDentifier (YANG SID or simply SID): Unsigned 180 integer used to identify different YANG items. 182 * delta: Difference between the current YANG SID and a reference 183 YANG SID. A reference YANG SID is defined for each context for 184 which deltas are used. 186 * item: A schema node, an identity, a module, a submodule, or a 187 feature defined using the YANG modeling language. 189 * list entry: the data associated with a single element of a list. 191 * parent: The container, list, case, notification, RPC input, RPC 192 output, action input or action output node in which a schema node 193 is defined. 195 3. Properties of the CBOR Encoding 197 This document defines CBOR encoding rules for YANG data trees and 198 their subtrees. 200 An instance of a schema node such as container, list, notification, 201 RPC input, RPC output, action input, or action output is serialized 202 using a CBOR map in which each child schema node is encoded using a 203 key and a value. This specification supports two types of CBOR keys; 204 YANG Schema Item iDentifier (YANG SID) as defined in Section 3.2 and 205 names as defined in Section 3.3. Each of these key types is encoded 206 using a specific CBOR type which allows their interpretation during 207 the deserialization process. Protocols or mechanisms implementing 208 this specification can mandate the use of a specific key type. 210 In order to minimize the size of the encoded data, the proposed 211 mapping avoids any unnecessary meta-information beyond those natively 212 supported by CBOR. For instance, CBOR tags are used solely in the 213 case of a SID not encoded as delta, anyxml schema nodes, or the union 214 datatype, to distinguish explicitly the use of different YANG 215 datatypes encoded using the same CBOR major type. 217 Unless specified otherwise by the protocol or mechanism implementing 218 this specification, the indefinite lengths encoding as defined in 219 Section 3.2 of [RFC8949] SHALL be supported by CBOR decoders. 221 Data nodes implemented using a CBOR array, map, byte string, or text 222 string can be instantiated but empty. In this case, they are encoded 223 with a length of zero. 225 When schema nodes are serialized using the rules defined by this 226 specification as part of an application payload, the payload SHOULD 227 include information that would allow a stateless way to identify each 228 node, such as the SID number associated with the node, SID delta from 229 another SID in the application payload, the namespace qualified name, 230 or the instance-identifier. 232 Examples in Section 4 include a root CBOR map with a single entry 233 having a key set to either a namespace qualified name or a SID. This 234 root CBOR map is provided only as a typical usage example and is not 235 part of the present encoding rules. Only the value within this CBOR 236 map is compulsory. 238 3.1. CBOR diagnostic notation 240 Within this document, CBOR binary contents are represented using an 241 equivalent textual form called CBOR diagnostic notation as defined in 242 Section 8 of [RFC8949]. This notation is used strictly for 243 documentation purposes and is never used in the data serialization. 244 Table 1 below provides a summary of this notation. 246 +==========+======+====================+===========+==========+ 247 | CBOR | CBOR | Diagnostic | Example | CBOR | 248 | content | type | notation | | encoding | 249 +==========+======+====================+===========+==========+ 250 | Unsigned | 0 | Decimal digits | 123 | 18 7B | 251 | integer | | | | | 252 +----------+------+--------------------+-----------+----------+ 253 | Negative | 1 | Decimal digits | -123 | 38 7A | 254 | integer | | prefixed by a | | | 255 | | | minus sign | | | 256 +----------+------+--------------------+-----------+----------+ 257 | Byte | 2 | Hexadecimal value | h'F15C' | 42 F15C | 258 | string | | enclosed between | | | 259 | | | single quotes and | | | 260 | | | prefixed by an 'h' | | | 261 +----------+------+--------------------+-----------+----------+ 262 | Text | 3 | String of Unicode | "txt" | 63 | 263 | string | | characters | | 747874 | 264 | | | enclosed between | | | 265 | | | double quotes | | | 266 +----------+------+--------------------+-----------+----------+ 267 | Array | 4 | Comma-separated | [ 1, 2 ] | 82 01 02 | 268 | | | list of values | | | 269 | | | within square | | | 270 | | | brackets | | | 271 +----------+------+--------------------+-----------+----------+ 272 | Map | 5 | Comma-separated | { 1: 123, | A2 | 273 | | | list of key : | 2: 456 } | 01187B | 274 | | | value pairs within | | 021901C8 | 275 | | | curly braces | | | 276 +----------+------+--------------------+-----------+----------+ 277 | Boolean | 7/20 | false | false | F4 | 278 +----------+------+--------------------+-----------+----------+ 279 | | 7/21 | true | true | F5 | 280 +----------+------+--------------------+-----------+----------+ 281 | Null | 7/22 | null | null | F6 | 282 +----------+------+--------------------+-----------+----------+ 283 | Not | 7/23 | undefined | undefined | F7 | 284 | assigned | | | | | 285 +----------+------+--------------------+-----------+----------+ 287 Table 1: CBOR diagnostic notation summary 289 Note: CBOR binary contents shown in this specification are annotated 290 with comments. These comments are delimited by slashes ("/") as 291 defined in [RFC8610] Appendix G.6. 293 3.2. YANG Schema Item iDentifier 295 Some of the items defined in YANG [RFC7950] require the use of a 296 unique identifier. In both Network Configuration Protocol (NETCONF) 297 [RFC6241] and RESTCONF [RFC8040], these identifiers are implemented 298 using strings. To allow the implementation of data models defined in 299 YANG in constrained devices and constrained networks, a more compact 300 method to identify YANG items is required. This compact identifier, 301 called YANG Schema Item iDentifier, is an unsigned integer. The 302 following items are identified using YANG SIDs (often shortened to 303 SIDs): 305 * identities 307 * data nodes 309 * RPCs and associated input(s) and output(s) 311 * actions and associated input(s) and output(s) 313 * notifications and associated information 315 * YANG modules, submodules, and features 317 To minimize their size, SIDs used as keys in inner CBOR maps are 318 typically encoded using deltas. Conversion from SIDs to deltas and 319 back to SIDs are stateless processes solely based on the data 320 serialized or deserialized. These SIDs may also be encoded as 321 absolute number when enclosed by CBOR tag 47. 323 Mechanisms and processes used to assign SIDs to YANG items and to 324 guarantee their uniqueness are outside the scope of the present 325 specification. If SIDs are to be used, the present specification is 326 used in conjunction with a specification defining this management. 327 One example for such a specification is [I-D.ietf-core-sid]. 329 3.3. Name 331 This specification also supports the encoding of YANG item 332 identifiers as strings, similar to those used by the JSON Encoding of 333 Data Modeled with YANG [RFC7951]. This approach can be used to avoid 334 the management overhead associated with SID allocation. The main 335 drawback is the significant increase in size of the encoded data. 337 YANG item identifiers implemented using names MUST be in one of the 338 following forms: 340 * simple - the identifier of the YANG item (i.e., schema node or 341 identity). 343 * namespace qualified - the identifier of the YANG item is prefixed 344 with the name of the module in which this item is defined, 345 separated by the colon character (":"). 347 The name of a module determines the namespace of all YANG items 348 defined in that module. If an item is defined in a submodule, then 349 the namespace qualified name uses the name of the main module to 350 which the submodule belongs. 352 ABNF syntax [RFC5234] of a name is shown in Figure 1, where the 353 production for "identifier" is defined in Section 14 of [RFC7950]. 355 name = [identifier ":"] identifier 357 Figure 1: ABNF Production for a simple or namespace qualified name 359 A namespace qualified name MUST be used for all members of a top- 360 level CBOR map and then also whenever the namespaces of the data node 361 and its parent node are different. In all other cases, the simple 362 form of the name SHOULD be used. 364 Definition example: 366 module example-foomod { 367 container top { 368 leaf foo { 369 type uint8; 370 } 371 } 372 } 374 module example-barmod { 375 import example-foomod { 376 prefix "foomod"; 377 } 378 augment "/foomod:top" { 379 leaf bar { 380 type boolean; 381 } 382 } 383 } 385 A valid CBOR encoding of the 'top' container is as follows. 387 CBOR diagnostic notation: 389 { 390 "example-foomod:top": { 391 "foo": 54, 392 "example-barmod:bar": true 393 } 394 } 396 Both the 'top' container and the 'bar' leaf defined in a different 397 YANG module as its parent container are encoded as namespace 398 qualified names. The 'foo' leaf defined in the same YANG module as 399 its parent container is encoded as simple name. 401 4. Encoding of YANG Schema Node Instances 403 Schema node instances defined using the YANG modeling language are 404 encoded using CBOR [RFC8949] based on the rules defined in this 405 section. We assume that the reader is already familiar with both 406 YANG [RFC7950] and CBOR [RFC8949]. 408 4.1. The 'leaf' 410 A 'leaf' MUST be encoded accordingly to its datatype using one of the 411 encoding rules specified in Section 6. 413 The following examples shows the encoding of a 'hostname' leaf using 414 a SID or a name. 416 Definition example from [RFC7317]: 418 typedef domain-name { 419 type string { 420 length "1..253"; 421 pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9].) 422 *([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.? 423 )|\.'; 424 } 425 } 427 leaf hostname { 428 type inet:domain-name; 429 } 431 4.1.1. Using SIDs in keys 433 As with all examples below, the delta in the outermost map assumes a 434 reference YANG SID (current schema node) of 0. 436 CBOR diagnostic notation: 438 { 439 1752 : "myhost.example.com" / hostname (SID 1752) / 440 } 442 CBOR encoding: 444 A1 # map(1) 445 19 06D8 # unsigned(1752) 446 72 # text(18) 447 6D79686F73742E6578616D706C652E636F6D # "myhost.example.com" 449 4.1.2. Using names in keys 451 CBOR diagnostic notation: 453 { 454 "ietf-system:hostname" : "myhost.example.com" 455 } 457 CBOR encoding: 459 A1 # map(1) 460 74 # text(20) 461 696574662D73797374656D3A686F73746E616D65 462 72 # text(18) 463 6D79686F73742E6578616D706C652E636F6D 465 4.2. The 'container' and other nodes from the data tree 467 Instances of containers, lists, notification contents, RPC inputs, 468 RPC outputs, action inputs, and action outputs schema nodes MUST be 469 encoded using a CBOR map data item (major type 5). A map is 470 comprised of pairs of data items, with each pair consisting of a key 471 and a value. Each key within the CBOR map is set to a schema node 472 identifier, each value is set to the value of this schema node 473 instance according to the instance datatype. 475 This specification supports two types of CBOR keys; SID as defined in 476 Section 3.2 and names as defined in Section 3.3. 478 The following examples shows the encoding of a 'system-state' 479 container schema node instance using SIDs or names. 481 Definition example from [RFC7317]: 483 typedef date-and-time { 484 type string { 485 pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-] 486 \d{2}:\d{2})'; 487 } 488 } 490 container system-state { 492 container clock { 493 leaf current-datetime { 494 type date-and-time; 495 } 497 leaf boot-datetime { 498 type date-and-time; 499 } 500 } 501 } 503 4.2.1. Using SIDs in keys 505 In the context of containers and other nodes from the data tree, CBOR 506 map keys within inner CBOR maps can be encoded using deltas or SIDs. 507 In the case of deltas, they MUST be encoded using a CBOR unsigned 508 integer (major type 0) or CBOR negative integer (major type 1), 509 depending on the actual delta value. In the case of SID, they are 510 encoded using the SID value enclosed by CBOR tag 47 as defined in 511 Section 9.3. 513 Delta values are computed as follows: 515 * In the case of a 'container', deltas are equal to the SID of the 516 current schema node minus the SID of the parent 'container'. 518 * In the case of a 'list', deltas are equal to the SID of the 519 current schema node minus the SID of the parent 'list'. 521 * In the case of an 'RPC input' or 'RPC output', deltas are equal to 522 the SID of the current schema node minus the SID of the 'RPC'. 524 * In the case of an 'action input' or 'action output', deltas are 525 equal to the SID of the current schema node minus the SID of the 526 'action'. 528 * In the case of a 'notification content', deltas are equal to the 529 SID of the current schema node minus the SID of the 530 'notification'. 532 CBOR diagnostic notation: 534 { 535 1720 : { / system-state (SID 1720) / 536 1 : { / clock (SID 1721) / 537 2 : "2015-10-02T14:47:24Z-05:00", / current-datetime(SID 1723)/ 538 1 : "2015-09-15T09:12:58Z-05:00" / boot-datetime (SID 1722) / 539 } 540 } 541 } 543 CBOR encoding: 545 A1 # map(1) 546 19 06B8 # unsigned(1720) 547 A1 # map(1) 548 01 # unsigned(1) 549 A2 # map(2) 550 02 # unsigned(2) 551 78 1A # text(26) 552 323031352D31302D30325431343A34373A32345A2D30353A3030 553 01 # unsigned(1) 554 78 1A # text(26) 555 323031352D30392D31355430393A31323A35385A2D30353A3030 557 Figure 2: System state clock encoding 559 4.2.2. Using names in keys 561 CBOR map keys implemented using names MUST be encoded using a CBOR 562 text string data item (major type 3). A namespace-qualified name 563 MUST be used each time the namespace of a schema node and its parent 564 differ. In all other cases, the simple form of the name MUST be 565 used. Names and namespaces are defined in Section 4 of [RFC7951]. 567 The following example shows the encoding of a 'system' container 568 schema node instance using names. 570 CBOR diagnostic notation: 572 { 573 "ietf-system:system-state" : { 574 "clock" : { 575 "current-datetime" : "2015-10-02T14:47:24Z-05:00", 576 "boot-datetime" : "2015-09-15T09:12:58Z-05:00" 577 } 578 } 579 } 580 CBOR encoding: 582 A1 # map(1) 583 78 18 # text(24) 584 696574662D73797374656D3A73797374656D2D7374617465 585 A1 # map(1) 586 65 # text(5) 587 636C6F636B # "clock" 588 A2 # map(2) 589 70 # text(16) 590 63757272656E742D6461746574696D65 591 78 1A # text(26) 592 323031352D31302D30325431343A34373A32345A2D30353A3030 593 6D # text(13) 594 626F6F742D6461746574696D65 595 78 1A # text(26) 596 323031352D30392D31355430393A31323A35385A2D30353A3030 598 4.3. The 'leaf-list' 600 A leaf-list MUST be encoded using a CBOR array data item (major type 601 4). Each entry of this array MUST be encoded accordingly to its 602 datatype using one of the encoding rules specified in Section 6. 604 The following example shows the encoding of the 'search' leaf-list 605 schema node instance containing two entries, "ietf.org" and 606 "ieee.org". 608 Definition example [RFC7317]: 610 typedef domain-name { 611 type string { 612 length "1..253"; 613 pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9].) 614 *([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.? 615 )|\.'; 616 } 617 } 619 leaf-list search { 620 type domain-name; 621 ordered-by user; 622 } 624 4.3.1. Using SIDs in keys 626 CBOR diagnostic notation: 628 { 629 1746 : [ "ietf.org", "ieee.org" ] / search (SID 1746) / 630 } 632 CBOR encoding: 634 A1 # map(1) 635 19 06D2 # unsigned(1746) 636 82 # array(2) 637 68 # text(8) 638 696574662E6F7267 # "ietf.org" 639 68 # text(8) 640 696565652E6F7267 # "ieee.org" 642 4.3.2. Using names in keys 644 CBOR diagnostic notation: 646 { 647 "ietf-system:search" : [ "ietf.org", "ieee.org" ] 648 } 650 CBOR encoding: 652 A1 # map(1) 653 72 # text(18) 654 696574662D73797374656D3A736561726368 # "ietf-system:search" 655 82 # array(2) 656 68 # text(8) 657 696574662E6F7267 # "ietf.org" 658 68 # text(8) 659 696565652E6F7267 # "ieee.org" 661 4.4. The 'list' and 'list' entries 663 A list or a subset of a list MUST be encoded using a CBOR array data 664 item (major type 4). Each list entry within this CBOR array is 665 encoded using a CBOR map data item (major type 5) based on the 666 encoding rules of a collection as defined in Section 4.2. 668 It is important to note that this encoding rule also applies to a 669 'list' schema node instance that has a single entry. 671 The following examples show the encoding of a 'server' list using 672 SIDs or names. 674 Definition example from [RFC7317]: 676 list server { 677 key name; 679 leaf name { 680 type string; 681 } 682 choice transport { 683 case udp { 684 container udp { 685 leaf address { 686 type host; 687 mandatory true; 688 } 689 leaf port { 690 type port-number; 691 } 692 } 693 } 694 } 695 leaf association-type { 696 type enumeration { 697 enum server; 698 enum peer; 699 enum pool; 700 } 701 default server; 702 } 703 leaf iburst { 704 type boolean; 705 default false; 706 } 707 leaf prefer { 708 type boolean; 709 default false; 710 } 711 } 713 4.4.1. Using SIDs in keys 715 The encoding rules of each 'list' entry are defined in Section 4.2.1. 716 Deltas of list members are equal to the SID of the current schema 717 node minus the SID of the 'list'. 719 CBOR diagnostic notation: 721 { 722 1756 : [ / server (SID 1756) / 723 { 724 3 : "NRC TIC server", / name (SID 1759) / 725 5 : { / udp (SID 1761) / 726 1 : "tic.nrc.ca", / address (SID 1762) / 727 2 : 123 / port (SID 1763) / 728 }, 729 1 : 0, / association-type (SID 1757) / 730 2 : false, / iburst (SID 1758) / 731 4 : true / prefer (SID 1760) / 732 }, 733 { 734 3 : "NRC TAC server", / name (SID 1759) / 735 5 : { / udp (SID 1761) / 736 1 : "tac.nrc.ca" / address (SID 1762) / 737 } 738 } 739 ] 740 } 742 CBOR encoding: 744 A1 # map(1) 745 19 06DC # unsigned(1756) 746 82 # array(2) 747 A5 # map(5) 748 03 # unsigned(3) 749 6E # text(14) 750 4E52432054494320736572766572 # "NRC TIC server" 751 05 # unsigned(5) 752 A2 # map(2) 753 01 # unsigned(1) 754 6A # text(10) 755 7469632E6E72632E6361 # "tic.nrc.ca" 756 02 # unsigned(2) 757 18 7B # unsigned(123) 758 01 # unsigned(1) 759 00 # unsigned(0) 760 02 # unsigned(2) 761 F4 # primitive(20) 762 04 # unsigned(4) 763 F5 # primitive(21) 764 A2 # map(2) 765 03 # unsigned(3) 766 6E # text(14) 767 4E52432054414320736572766572 # "NRC TAC server" 768 05 # unsigned(5) 769 A1 # map(1) 770 01 # unsigned(1) 771 6A # text(10) 772 7461632E6E72632E6361 # "tac.nrc.ca" 774 4.4.2. Using names in keys 776 The encoding rules of each 'list' entry are defined in Section 4.2.2. 778 CBOR diagnostic notation: 780 { 781 "ietf-system:server" : [ 782 { 783 "name" : "NRC TIC server", 784 "udp" : { 785 "address" : "tic.nrc.ca", 786 "port" : 123 787 }, 788 "association-type" : 0, 789 "iburst" : false, 790 "prefer" : true 791 }, 792 { 793 "name" : "NRC TAC server", 794 "udp" : { 795 "address" : "tac.nrc.ca" 796 } 797 } 798 ] 799 } 801 CBOR encoding: 803 A1 # map(1) 804 72 # text(18) 805 696574662D73797374656D3A736572766572 806 82 # array(2) 807 A5 # map(5) 808 64 # text(4) 809 6E616D65 # "name" 810 6E # text(14) 811 4E52432054494320736572766572 812 63 # text(3) 813 756470 # "udp" 814 A2 # map(2) 815 67 # text(7) 816 61646472657373 # "address" 817 6A # text(10) 818 7469632E6E72632E6361 # "tic.nrc.ca" 819 64 # text(4) 820 706F7274 # "port" 821 18 7B # unsigned(123) 822 70 # text(16) 823 6173736F63696174696F6E2D74797065 824 00 # unsigned(0) 825 66 # text(6) 826 696275727374 # "iburst" 827 F4 # primitive(20) 828 66 # text(6) 829 707265666572 # "prefer" 830 F5 # primitive(21) 831 A2 # map(2) 832 64 # text(4) 833 6E616D65 # "name" 834 6E # text(14) 835 4E52432054414320736572766572 836 63 # text(3) 837 756470 # "udp" 838 A1 # map(1) 839 67 # text(7) 840 61646472657373 # "address" 841 6A # text(10) 842 7461632E6E72632E6361 # "tac.nrc.ca" 844 4.5. The 'anydata' 846 An anydata serves as a container for an arbitrary set of schema nodes 847 that otherwise appear as normal YANG-modeled data. An anydata schema 848 node instance is encoded using the same rules as a container, i.e., 849 CBOR map. The requirement that anydata content can be modeled by 850 YANG implies the following: 852 * CBOR map keys of any inner schema nodes MUST be set to valid 853 deltas or names. 855 * The CBOR array MUST contain either unique scalar values (as a 856 leaf-list, see Section 4.3), or maps (as a list, see Section 4.4). 858 * CBOR map values MUST follow the encoding rules of one of the 859 datatypes listed in Section 4. 861 The following example shows a possible use of an anydata. In this 862 example, an anydata is used to define a schema node containing a 863 notification event; this schema node can be part of a YANG list to 864 create an event logger. 866 Definition example: 868 module event-log { 869 ... 870 anydata last-event; # SID 60123 871 } 873 This example also assumes the assistance of the following 874 notification. 876 module example-port { 877 ... 879 notification example-port-fault { # SID 60200 880 leaf port-name { # SID 60201 881 type string; 882 } 883 leaf port-fault { # SID 60202 884 type string; 885 } 886 } 887 } 889 4.5.1. Using SIDs in keys 891 CBOR diagnostic notation: 893 { 894 60123 : { / last-event (SID 60123) / 895 77 : { / example-port-fault (SID 60200) / 896 1 : "0/4/21", / port-name (SID 60201) / 897 2 : "Open pin 2" / port-fault (SID 60202) / 898 } 899 } 900 } 902 CBOR encoding: 904 A1 # map(1) 905 19 EADB # unsigned(60123) 906 A1 # map(1) 907 18 4D # unsigned(77) 908 A2 # map(2) 909 18 4E # unsigned(78) 910 66 # text(6) 911 302F342F3231 # "0/4/21" 912 18 4F # unsigned(79) 913 6A # text(10) 914 4F70656E2070696E2032 # "Open pin 2" 916 In some implementations, it might be simpler to use the absolute SID 917 tag encoding for the anydata root element. The resulting encoding is 918 as follows: 920 { 921 60123 : { / last-event (SID 60123) / 922 47(60200) : { / event-port-fault (SID 60200) / 923 1 : "0/4/21", / port-name (SID 60201) / 924 2 : "Open pin 2" / port-fault (SID 60202) / 925 } 926 } 927 } 929 4.5.2. Using names in keys 931 CBOR diagnostic notation: 933 { 934 "event-log:last-event" : { 935 "example-port:example-port-fault" : { 936 "port-name" : "0/4/21", 937 "port-fault" : "Open pin 2" 938 } 939 } 940 } 941 CBOR encoding: 943 A1 # map(1) 944 74 # text(20) 945 6576656E742D6C6F673A6C6173742D6576656E74 946 A1 # map(1) 947 78 20 # text(32) 948 6578616D706C652D706F72743A206578616D7 949 06C652D706F72742D6661756C74 950 A2 # map(2) 951 69 # text(9) 952 706F72742D6E616D65 # "port-name" 953 66 # text(6) 954 302F342F3231 # "0/4/21" 955 6A # text(10) 956 706F72742D6661756C74 # "port-fault" 957 6A # text(10) 958 4F70656E2070696E2032 # "Open pin 2" 960 4.6. The 'anyxml' 962 An anyxml schema node is used to serialize an arbitrary CBOR content, 963 i.e., its value can be any CBOR binary object. anyxml value MAY 964 contain CBOR data items tagged with one of the tags listed in 965 Section 9.3. The tags listed in Section 9.3 SHALL be supported. 967 The following example shows a valid CBOR encoded anyxml schema node 968 instance consisting of a CBOR array containing the CBOR simple values 969 'true', 'null' and 'true'. 971 Definition example from [RFC7951]: 973 module bar-module { 974 ... 975 anyxml bar; # SID 60000 976 } 978 4.6.1. Using SIDs in keys 980 CBOR diagnostic notation: 982 { 983 60000 : [true, null, true] / bar (SID 60000) / 984 } 986 CBOR encoding: 988 A1 # map(1) 989 19 EA60 # unsigned(60000) 990 83 # array(3) 991 F5 # primitive(21) 992 F6 # primitive(22) 993 F5 # primitive(21) 995 4.6.2. Using names in keys 997 CBOR diagnostic notation: 999 { 1000 "bar-module:bar" : [true, null, true] / bar (SID 60000) / 1001 } 1003 CBOR encoding: 1005 A1 # map(1) 1006 6E # text(14) 1007 6261722D6D6F64756C653A626172 # "bar-module:bar" 1008 83 # array(3) 1009 F5 # primitive(21) 1010 F6 # primitive(22) 1011 F5 # primitive(21) 1013 5. Encoding of 'yang-data' extension 1015 The yang-data extension [RFC8040] is used to define data structures 1016 in YANG that are not intended to be implemented as part of a 1017 datastore. 1019 The yang-data extension MUST be encoded using the encoding rules of 1020 nodes of data trees as defined in Section 4.2. 1022 Just like YANG containers, the yang-data extension can be encoded 1023 using either SIDs or names. 1025 Definition example from [I-D.ietf-core-comi] Appendix A: 1027 module ietf-coreconf { 1028 ... 1030 import ietf-restconf { 1031 prefix rc; 1032 } 1034 rc:yang-data yang-errors { 1035 container error { 1036 leaf error-tag { 1037 type identityref { 1038 base error-tag; 1039 } 1040 } 1041 leaf error-app-tag { 1042 type identityref { 1043 base error-app-tag; 1044 } 1045 } 1046 leaf error-data-node { 1047 type instance-identifier; 1048 } 1049 leaf error-message { 1050 type string; 1051 } 1052 } 1053 } 1054 } 1056 5.1. Using SIDs in keys 1058 The yang-data extensions encoded using SIDs are carried in a CBOR map 1059 containing a single item pair. The key of this item is set to the 1060 SID assigned to the yang-data extension container; the value is set 1061 to the CBOR encoding of this container as defined in Section 4.2. 1063 This example shows a serialization example of the yang-errors yang- 1064 data extension as defined in [I-D.ietf-core-comi] using SIDs as 1065 defined in Section 3.2. 1067 CBOR diagnostic notation: 1069 { 1070 1024 : { / error (SID 1024) / 1071 4 : 1011, / error-tag (SID 1028) / 1072 / = invalid-value (SID 1011) / 1073 1 : 1018, / error-app-tag (SID 1025) / 1074 / = not-in-range (SID 1018) / 1075 2 : 1740, / error-data-node (SID 1026) / 1076 / = timezone-utc-offset (SID 1740) / 1077 3 : "Maximum exceeded" / error-message (SID 1027) / 1078 } 1079 } 1081 CBOR encoding: 1083 A1 # map(1) 1084 19 0400 # unsigned(1024) 1085 A4 # map(4) 1086 04 # unsigned(4) 1087 19 03F3 # unsigned(1011) 1088 01 # unsigned(1) 1089 19 03FA # unsigned(1018) 1090 02 # unsigned(2) 1091 19 06CC # unsigned(1740) 1092 03 # unsigned(3) 1093 70 # text(16) 1094 4D6178696D756D206578636565646564 1096 5.2. Using names in keys 1098 The yang-data extensions encoded using names are carried in a CBOR 1099 map containing a single item pair. The key of this item is set to 1100 the namespace qualified name of the yang-data extension container; 1101 the value is set to the CBOR encoding of this container as defined in 1102 Section 3.3. 1104 This example shows a serialization example of the yang-errors yang- 1105 data extension as defined in [I-D.ietf-core-comi] using names as 1106 defined Section 3.3. 1108 CBOR diagnostic notation: 1110 { 1111 "ietf-coreconf:error" : { 1112 "error-tag" : "invalid-value", 1113 "error-app-tag" : "not-in-range", 1114 "error-data-node" : "timezone-utc-offset", 1115 "error-message" : "Maximum exceeded" 1116 } 1117 } 1119 CBOR encoding: 1121 A1 # map(1) 1122 73 # text(19) 1123 696574662D636F7265636F6E663A6572726F72 # "ietf-coreconf:error" 1124 A4 # map(4) 1125 69 # text(9) 1126 6572726F722D746167 # "error-tag" 1127 6D # text(13) 1128 696E76616C69642D76616C7565 # "invalid-value" 1129 6D # text(13) 1130 6572726F722D6170702D746167 # "error-app-tag" 1131 6C # text(12) 1132 6E6F742D696E2D72616E6765 # "not-in-range" 1133 6F # text(15) 1134 6572726F722D646174612D6E6F6465 # "error-data-node" 1135 73 # text(19) 1136 74696D657A6F6E652D7574632D6F6666736574 1137 # "timezone-utc-offset" 1138 6D # text(13) 1139 6572726F722D6D657373616765 # "error-message" 1140 70 # text(16) 1141 4D6178696D756D206578636565646564 1143 6. Representing YANG Data Types in CBOR 1145 The CBOR encoding of an instance of a leaf or leaf-list schema node 1146 depends on the built-in type of that schema node. The following sub- 1147 section defines the CBOR encoding of each built-in type supported by 1148 YANG as listed in Section 4.2.4 of [RFC7950]. Each subsection shows 1149 an example value assigned to a schema node instance of the discussed 1150 built-in type. 1152 6.1. The unsigned integer Types 1154 Leafs of type uint8, uint16, uint32 and uint64 MUST be encoded using 1155 a CBOR unsigned integer data item (major type 0). 1157 The following example shows the encoding of an 'mtu' leaf schema node 1158 instance set to 1280 bytes. 1160 Definition example from [RFC8344]: 1162 leaf mtu { 1163 type uint16 { 1164 range "68..max"; 1165 } 1166 } 1168 CBOR diagnostic notation: 1280 1170 CBOR encoding: 19 0500 1172 6.2. The integer Types 1174 Leafs of type int8, int16, int32 and int64 MUST be encoded using 1175 either CBOR unsigned integer (major type 0) or CBOR negative integer 1176 (major type 1), depending on the actual value. 1178 The following example shows the encoding of a 'timezone-utc-offset' 1179 leaf schema node instance set to -300 minutes. 1181 Definition example from [RFC7317]: 1183 leaf timezone-utc-offset { 1184 type int16 { 1185 range "-1500 .. 1500"; 1186 } 1187 } 1189 CBOR diagnostic notation: -300 1191 CBOR encoding: 39 012B 1193 6.3. The 'decimal64' Type 1195 Leafs of type decimal64 MUST be encoded using a decimal fraction as 1196 defined in Section 3.4.4 of [RFC8949]. 1198 The following example shows the encoding of a 'my-decimal' leaf 1199 schema node instance set to 2.57. 1201 Definition example from [RFC7317]: 1203 leaf my-decimal { 1204 type decimal64 { 1205 fraction-digits 2; 1206 range "1 .. 3.14 | 10 | 20..max"; 1207 } 1208 } 1210 CBOR diagnostic notation: 4([-2, 257]) 1212 CBOR encoding: C4 82 21 19 0101 1214 6.4. The 'string' Type 1216 Leafs of type string MUST be encoded using a CBOR text string data 1217 item (major type 3). 1219 The following example shows the encoding of a 'name' leaf schema node 1220 instance set to "eth0". 1222 Definition example from [RFC8343]: 1224 leaf name { 1225 type string; 1226 } 1228 CBOR diagnostic notation: "eth0" 1230 CBOR encoding: 64 65746830 1232 6.5. The 'boolean' Type 1234 Leafs of type boolean MUST be encoded using a CBOR simple value 1235 'true' (major type 7, additional information 21) or 'false' (major 1236 type 7, additional information 20). 1238 The following example shows the encoding of an 'enabled' leaf schema 1239 node instance set to 'true'. 1241 Definition example from [RFC7317]: 1243 leaf enabled { 1244 type boolean; 1245 } 1247 CBOR diagnostic notation: true 1249 CBOR encoding: F5 1251 6.6. The 'enumeration' Type 1253 Leafs of type enumeration MUST be encoded using a CBOR unsigned 1254 integer (major type 0) or CBOR negative integer (major type 1), 1255 depending on the actual value. Enumeration values are either 1256 explicitly assigned using the YANG statement 'value' or automatically 1257 assigned based on the algorithm defined in Section 9.6.4.2 of 1258 [RFC7950]. 1260 The following example shows the encoding of an 'oper-status' leaf 1261 schema node instance set to 'testing'. 1263 Definition example from [RFC7317]: 1265 leaf oper-status { 1266 type enumeration { 1267 enum up { value 1; } 1268 enum down { value 2; } 1269 enum testing { value 3; } 1270 enum unknown { value 4; } 1271 enum dormant { value 5; } 1272 enum not-present { value 6; } 1273 enum lower-layer-down { value 7; } 1274 } 1275 } 1277 CBOR diagnostic notation: 3 1279 CBOR encoding: 03 1281 Values of 'enumeration' types defined in a 'union' type MUST be 1282 encoded using a CBOR text string data item (major type 3) and MUST 1283 contain one of the names assigned by 'enum' statements in YANG. The 1284 encoding MUST be enclosed by the enumeration CBOR tag as specified in 1285 Section 9.3. 1287 Definition example from [RFC7950]: 1289 type union { 1290 type int32; 1291 type enumeration { 1292 enum unbounded; 1293 } 1294 } 1296 CBOR diagnostic notation: 44("unbounded") 1298 CBOR encoding: D8 2C 69 756E626F756E646564 1300 6.7. The 'bits' Type 1302 Keeping in mind that bit positions are either explicitly assigned 1303 using the YANG statement 'position' or automatically assigned based 1304 on the algorithm defined in Section 9.7.4.2 of [RFC7950], each 1305 element of type bits could be seen as a set of bit positions (or 1306 offsets from position 0), that have a value of either 1, which 1307 represents the bit being set or 0, which represents that the bit is 1308 not set. 1310 Leafs of type bits MUST be encoded either using a CBOR array or byte 1311 string (major type 2). In case CBOR array representation is used, 1312 each element is either a positive integer (major type 0 with value 0 1313 being disallowed) that can be used to calculate the offset of the 1314 next byte string, or a byte string (major type 2) that carries the 1315 information whether certain bits are set or not. The initial offset 1316 value is 0 and each unsigned integer modifies the offset value of the 1317 next byte string by the integer value multiplied by 8. For example, 1318 if the bit offset is 0 and there is an integer with value 5, the 1319 first byte of the byte string that follows will represent bit 1320 positions 40 to 47 both ends included. If the byte string has a 1321 second byte, it will carry information about bits 48 to 55 and so on. 1322 Within each byte, bits are assigned from least to most significant. 1323 After the byte string, the offset is modified by the number of bytes 1324 in the byte string multiplied by 8. Bytes with no bits set at the 1325 end of the byte string are removed. An example follows. 1327 The following example shows the encoding of an 'alarm-state' leaf 1328 schema node instance with the 'critical' (position 3), 'warning' 1329 (position 8) and 'indeterminate' (position 128) flags set. 1331 typedef alarm-state { 1332 type bits { 1333 bit unknown; 1334 bit under-repair; 1335 bit critical; 1336 bit major; 1337 bit minor; 1338 bit warning { 1339 position 8; 1340 } 1341 bit indeterminate { 1342 position 128; 1343 } 1344 } 1345 } 1347 leaf alarm-state { 1348 type alarm-state; 1349 } 1351 CBOR diagnostic notation: [h'0401', 14, h'01'] 1353 CBOR encoding: 83 42 0401 0E 41 01 1355 In a number of cases the array would only need to have one element - 1356 a byte string with a small number of bytes inside. For this case, it 1357 is expected to omit the array element and have only the byte array 1358 that would have been inside. To illustrate this, let us consider the 1359 same example YANG definition, but this time encoding only 'under- 1360 repair' and 'critical' flags. The result would be 1362 CBOR diagnostic notation: h'06' 1364 CBOR encoding: 41 06 1366 Elements in the array MUST be either byte strings or positive 1367 unsigned integers, where byte strings and integers MUST alternate, 1368 i.e., adjacent byte strings or adjacent integers are an error. An 1369 array with a single byte string MUST instead be encoded as just that 1370 byte string. An array with a single positive integer is an error. 1372 Values of 'bits' types defined in a 'union' type MUST be encoded 1373 using a CBOR text string data item (major type 3) and MUST contain a 1374 space-separated sequence of names of 'bits' that are set. The 1375 encoding MUST be enclosed by the bits CBOR tag as specified in 1376 Section 9.3. 1378 The following example shows the encoding of an 'alarm-state' leaf 1379 schema node instance defined using a union type with the 'under- 1380 repair' and 'critical' flags set. 1382 Definition example: 1384 leaf alarm-state-2 { 1385 type union { 1386 type alarm-state; 1387 type bits { 1388 bit extra-flag; 1389 } 1390 } 1391 } 1393 CBOR diagnostic notation: 43("under-repair critical") 1395 CBOR encoding: D8 2B 75 756E6465722D72657061697220637269746963616C 1397 6.8. The 'binary' Type 1399 Leafs of type binary MUST be encoded using a CBOR byte string data 1400 item (major type 2). 1402 The following example shows the encoding of an 'aes128-key' leaf 1403 schema node instance set to 0x1f1ce6a3f42660d888d92a4d8030476e. 1405 Definition example: 1407 leaf aes128-key { 1408 type binary { 1409 length 16; 1410 } 1411 } 1413 CBOR diagnostic notation: h'1F1CE6A3F42660D888D92A4D8030476E' 1415 CBOR encoding: 50 1F1CE6A3F42660D888D92A4D8030476E 1417 6.9. The 'leafref' Type 1419 Leafs of type leafref MUST be encoded using the rules of the schema 1420 node referenced by the 'path' YANG statement. 1422 The following example shows the encoding of an 'interface-state-ref' 1423 leaf schema node instance set to "eth1". 1425 Definition example from [RFC8343]: 1427 typedef interface-state-ref { 1428 type leafref { 1429 path "/interfaces-state/interface/name"; 1430 } 1431 } 1433 container interfaces-state { 1434 list interface { 1435 key "name"; 1436 leaf name { 1437 type string; 1438 } 1439 leaf-list higher-layer-if { 1440 type interface-state-ref; 1441 } 1442 } 1443 } 1445 CBOR diagnostic notation: "eth1" 1447 CBOR encoding: 64 65746831 1449 6.10. The 'identityref' Type 1451 This specification supports two approaches for encoding identityref: 1452 as a YANG Schema Item iDentifier as defined in Section 3.2, or as a 1453 name as defined in Section 6.8 of [RFC7951]. 1455 6.10.1. SIDs as identityref 1457 When schema nodes of type identityref are implemented using SIDs, 1458 they MUST be encoded using a CBOR unsigned integer data item (major 1459 type 0). (Note that no delta mechanism is employed for SIDs used for 1460 identityref.) 1462 The following example shows the encoding of a 'type' leaf schema node 1463 instance set to the value 'iana-if-type:ethernetCsmacd' (SID 1880). 1465 Definition example from [RFC7317]: 1467 identity interface-type { 1468 } 1470 identity iana-interface-type { 1471 base interface-type; 1472 } 1474 identity ethernetCsmacd { 1475 base iana-interface-type; 1476 } 1478 leaf type { 1479 type identityref { 1480 base interface-type; 1481 } 1482 } 1484 CBOR diagnostic notation: 1880 1486 CBOR encoding: 19 0758 1488 6.10.2. Name as identityref 1490 Alternatively, an identityref MAY be encoded using a name as defined 1491 in Section 3.3. When names are used, identityref MUST be encoded 1492 using a CBOR text string data item (major type 3). If the identity 1493 is defined in different module than the leaf node containing the 1494 identityref data node, the namespace qualified form MUST be used. 1495 Otherwise, both the simple and namespace qualified forms are 1496 permitted. Names and namespaces are defined in Section 3.3. 1498 The following example shows the encoding of the identity 'iana-if- 1499 type:ethernetCsmacd' using its namespace qualified name. This 1500 example is described in Section 6.10.1. 1502 CBOR diagnostic notation: "iana-if-type:ethernetCsmacd" 1504 CBOR encoding: 78 1b 1505 69616E612D69662D747970653A65746865726E657443736D616364 1507 6.11. The 'empty' Type 1509 Leafs of type empty MUST be encoded using the CBOR null value (major 1510 type 7, additional information 22). 1512 The following example shows the encoding of an 'is-router' leaf 1513 schema node instance when present. 1515 Definition example from [RFC8344]: 1517 leaf is-router { 1518 type empty; 1519 } 1521 CBOR diagnostic notation: null 1523 CBOR encoding: F6 1525 6.12. The 'union' Type 1527 Leafs of type union MUST be encoded using the rules associated with 1528 one of the types listed. When used in a union, the following YANG 1529 datatypes are enclosed by a CBOR tag to avoid confusion between 1530 different YANG datatypes encoded using the same CBOR major type. 1532 * bits 1534 * enumeration 1536 * identityref 1538 * instance-identifier 1540 See Section 9.3 for the assigned value of these CBOR tags. 1542 As mentioned in Section 6.6 and in Section 6.7, 'enumeration' and 1543 'bits' are encoded as a CBOR text string data item (major type 3) 1544 when defined within a 'union' type. 1546 The following example shows the encoding of an 'ip-address' leaf 1547 schema node instance when set to "2001:db8:a0b:12f0::1". 1549 Definition example from [RFC7317]: 1551 typedef ipv4-address { 1552 type string { 1553 pattern '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3} 1554 ([0-9][1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N} 1555 \p{L}]+)?'; 1556 } 1557 } 1559 typedef ipv6-address { 1560 type string { 1561 pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a 1562 -fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0 1563 -9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0 1564 -9]?[0-9])))(%[\p{N}\p{L}]+)?'; 1565 pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|((([^:]+:)*[^:]+) 1566 ?::(([^:]+:)*[^:]+)?)(%.+)?'; 1567 } 1568 } 1570 typedef ip-address { 1571 type union { 1572 type ipv4-address; 1573 type ipv6-address; 1574 } 1575 } 1577 leaf address { 1578 type ip-address; 1579 } 1581 CBOR diagnostic notation: "2001:db8:a0b:12f0::1" 1583 CBOR encoding: 74 323030313A6462383A6130623A313266303A3A31 1585 6.13. The 'instance-identifier' Type 1587 This specification supports two approaches for encoding an instance- 1588 identifier, one based on YANG Schema Item iDentifier as defined in 1589 Section 3.2 and one based on names as defined in Section 3.3. 1591 6.13.1. SIDs as instance-identifier 1593 SIDs uniquely identify a schema node. In the case of a single 1594 instance schema node, i.e., a schema node defined at the root of a 1595 YANG module or submodule or schema nodes defined within a container, 1596 the SID is sufficient to identify this instance. 1598 In the case of a schema node member of a YANG list, a SID is combined 1599 with the list key(s) to identify each instance within the YANG 1600 list(s). 1602 Single instance schema nodes MUST be encoded using a CBOR unsigned 1603 integer data item (major type 0) and set to the targeted schema node 1604 SID. 1606 Schema node members of a YANG list MUST be encoded using a CBOR array 1607 data item (major type 4) containing the following entries: 1609 * The first entry MUST be encoded as a CBOR unsigned integer data 1610 item (major type 0) and set to the targeted schema node SID. 1612 * The following entries MUST contain the value of each key required 1613 to identify the instance of the targeted schema node. These keys 1614 MUST be ordered as defined in the 'key' YANG statement, starting 1615 from the top level list, and followed by each of the subordinate 1616 list(s). 1618 Examples within this section assume the definition of a schema node 1619 of type 'instance-identifier': 1621 Definition example from [RFC7950]: 1623 container system { 1624 ... 1625 leaf reporting-entity { 1626 type instance-identifier; 1627 } 1629 *First example:* 1631 The following example shows the encoding of the 'reporting-entity' 1632 value referencing data node instance "/system/contact" (SID 1741). 1634 Definition example from [RFC7317]: 1636 container system { 1638 leaf contact { 1639 type string; 1640 } 1642 leaf hostname { 1643 type inet:domain-name; 1644 } 1645 } 1646 CBOR diagnostic notation: 1741 1648 CBOR encoding: 19 06CD 1650 *Second example:* 1652 The following example shows the encoding of the 'reporting-entity' 1653 value referencing list instance "/system/authentication/user/ 1654 authorized-key/key-data" (SID 1734) for user name "bob" and 1655 authorized-key "admin". 1657 Definition example from [RFC7317]: 1659 list user { 1660 key name country; 1662 leaf name { 1663 type string; 1664 } 1666 leaf password { 1667 type ianach:crypt-hash; 1668 } 1670 list authorized-key { 1671 key name country; 1673 leaf country { 1674 type string; 1675 } 1677 leaf name { 1678 type string; 1679 } 1681 leaf algorithm { 1682 type string; 1683 } 1685 leaf key-data { 1686 type binary; 1687 } 1688 } 1689 } 1691 CBOR diagnostic notation: [1734, "bob", "admin", "france"] 1693 CBOR encoding: 1695 84 # array(4) 1696 19 06C6 # unsigned(1734) 1697 63 # text(3) 1698 626F62 # "bob" 1699 65 # text(5) 1700 61646D696E # "admin" 1701 66 # text(6) 1702 6672616E6365 # "france" 1704 *Third example:* 1706 The following example shows the encoding of the 'reporting-entity' 1707 value referencing the list instance "/system/authentication/user" 1708 (SID 1730) corresponding to user name "jack". 1710 CBOR diagnostic notation: [1730, "jack"] 1712 CBOR encoding: 1714 82 # array(2) 1715 19 06C2 # unsigned(1730) 1716 64 # text(4) 1717 6A61636B # "jack" 1719 6.13.2. Names as instance-identifier 1721 An "instance-identifier" value is encoded as a string that is 1722 analogous to the lexical representation in XML encoding; see 1723 Section 9.13.2 of [RFC7950]. However, the encoding of namespaces in 1724 instance-identifier values follows the rules stated in Section 3.3, 1725 namely: 1727 * The leftmost (top-level) data node name is always in the namespace 1728 qualified form. 1730 * Any subsequent data node name is in the namespace qualified form 1731 if the node is defined in a module other than its parent node, and 1732 the simple form is used otherwise. This rule also holds for node 1733 names appearing in predicates. 1735 For example, 1737 /ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ip 1739 is a valid instance-identifier value because the data nodes 1740 "interfaces", "interface", and "name" are defined in the module 1741 "ietf-interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". 1743 The resulting xpath MUST be encoded using a CBOR text string data 1744 item (major type 3). 1746 *First example:* 1748 This example is described in Section 6.13.1. 1750 CBOR diagnostic notation: "/ietf-system:system/contact" 1752 CBOR encoding: 1754 78 1c 2F696574662D73797374656D3A73797374656D2F636F6E74616374 1756 *Second example:* 1758 This example is described in Section 6.13.1. 1760 CBOR diagnostic notation (the line break is inserted for exposition 1761 only): 1763 "/ietf-system:system/authentication/user[name='bob']/ 1764 authorized-key[name='admin']/key-data" 1766 CBOR encoding: 1768 78 59 1769 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1770 74696F6E2F757365725B6E616D653D27626F62275D2F617574686F72697A 1771 65642D6B65795B6E616D653D2761646D696E275D2F6B65792D64617461 1773 *Third example:* 1775 This example is described in Section 6.13.1. 1777 CBOR diagnostic notation: 1779 "/ietf-system:system/authentication/user[name='jack']" 1781 CBOR encoding: 1783 78 33 1784 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1785 74696F6E2F757365725B6E616D653D27626F62275D 1787 7. Content-Types 1789 This specification defines the media-type "application/yang- 1790 data+cbor", which can be used without parameters or with the 1791 parameter "id=name" or "id=sid". 1793 This media-type represents a CBOR YANG document containing one or 1794 multiple data node values. Depending on the presence and value of 1795 the media-type parameter "id", each data node is identified by its 1796 associated namespace qualified name as defined in Section 3.3 1797 ("id=name"), by its associated YANG SID (represented as a SID delta 1798 or via tag 47) as defined in Section 3.2 ("id=sid"), or either of 1799 these (no "id" parameter given). 1801 The format of an "application/yang-data+cbor" representation is that 1802 of a CBOR map, mapping names and/or SIDs (as defined above) into 1803 instance values (using the rules defined in Section 4). 1805 It is not foreseen at this point that the valid set of values for the 1806 "id" parameter will extend beyond "name", "sid", or being unset; if 1807 that does happen, any new value is foreseen to be of the form 1808 "[a-z][a-z0-9]*(-[a-z0-9]+)*". 1810 8. Security Considerations 1812 The security considerations of [RFC8949] and [RFC7950] apply. 1814 This document defines an alternative encoding for data modeled in the 1815 YANG data modeling language. As such, this encoding does not 1816 contribute any new security issues in addition to those identified 1817 for the specific protocol or context for which it is used. 1819 To minimize security risks, software on the receiving side SHOULD 1820 reject all messages that do not comply to the rules of this document 1821 and reply with an appropriate error message to the sender. 1823 9. IANA Considerations 1825 9.1. Media-Types Registry 1827 This document adds the following Media-Type to the "Media Types" 1828 registry. 1830 +================+============================+===========+ 1831 | Name | Template | Reference | 1832 +================+============================+===========+ 1833 | yang-data+cbor | application/yang-data+cbor | RFC XXXX | 1834 +----------------+----------------------------+-----------+ 1836 Table 2 1838 // RFC Ed.: please replace RFC XXXX with this RFC number and remove 1839 this note. 1841 Type name: application 1842 Subtype name: yang-data+cbor 1843 Required parameters: none 1844 Optional parameters: id (see Section 7 of RFC XXXX) 1845 Encoding considerations: binary (CBOR) 1846 Security considerations: see Section 8 of RFC XXXX 1847 Published specification: RFC XXXX 1848 Person & email address to contact for further information: CORE WG 1849 mailing list (core@ietf.org), or IETF Applications and Real-Time 1850 Area (art@ietf.org) 1851 Intended usage: COMMON 1852 Restrictions on usage: none 1853 Author/Change controller: IETF 1855 9.2. CoAP Content-Formats Registry 1857 This document adds the following Content-Format to the "CoAP Content- 1858 Formats", within the "Constrained RESTful Environments (CoRE) 1859 Parameters" registry, where TBD3 comes from the "Expert Review" 0-255 1860 range and TBD1 and TBD2 come from the "IETF Review" 256-9999 range. 1862 +============================+================+======+===========+ 1863 | Content Type | Content Coding | ID | Reference | 1864 +============================+================+======+===========+ 1865 | application/yang-data+cbor | - | TBD1 | RFC XXXX | 1866 +----------------------------+----------------+------+-----------+ 1867 | application/yang- | - | TBD2 | RFC XXXX | 1868 | data+cbor; id=name | | | | 1869 +----------------------------+----------------+------+-----------+ 1870 | application/yang- | - | TBD3 | RFC XXXX | 1871 | data+cbor; id=sid | | | | 1872 +----------------------------+----------------+------+-----------+ 1874 Table 3 1876 // RFC Ed.: please replace TBDx with assigned IDs, remove the 1877 requested ranges, and remove this note. 1878 // RFC Ed.: please replace RFC XXXX with this RFC number and remove 1879 this note. 1881 9.3. CBOR Tags Registry 1883 This specification requires the assignment of CBOR tags for the 1884 following YANG datatypes. These tags are added to the CBOR Tags 1885 Registry as defined in Section 9.2 of [RFC8949]. 1887 +=====+==================+=============================+===========+ 1888 | Tag | Data Item | Semantics | Reference | 1889 +=====+==================+=============================+===========+ 1890 | 43 | text string | YANG bits datatype | RFC XXXX | 1891 +-----+------------------+-----------------------------+-----------+ 1892 | | | ; see Section 6.7. | | 1893 +-----+------------------+-----------------------------+-----------+ 1894 | 44 | text string | YANG enumeration datatype | RFC XXXX | 1895 +-----+------------------+-----------------------------+-----------+ 1896 | | | ; see Section 6.6. | | 1897 +-----+------------------+-----------------------------+-----------+ 1898 | 45 | unsigned integer | YANG identityref datatype | RFC XXXX | 1899 +-----+------------------+-----------------------------+-----------+ 1900 | | or text string | ; see Section 6.10 | | 1901 +-----+------------------+-----------------------------+-----------+ 1902 | 46 | unsigned integer | YANG instance-identifier | RFC XXXX | 1903 +-----+------------------+-----------------------------+-----------+ 1904 | | or text string | datatype; see Section 6.13. | RFC XXXX | 1905 +-----+------------------+-----------------------------+-----------+ 1906 | | or array | | | 1907 +-----+------------------+-----------------------------+-----------+ 1908 | 47 | unsigned integer | YANG Schema Item iDentifier | | 1909 +-----+------------------+-----------------------------+-----------+ 1910 | | | (SID); see Section 3.2. | RFC XXXX | 1911 +-----+------------------+-----------------------------+-----------+ 1913 Table 4 1915 // RFC Ed.: please replace RFC XXXX with RFC number and remove this 1916 note 1918 10. References 1920 10.1. Normative References 1922 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1923 Requirement Levels", BCP 14, RFC 2119, 1924 DOI 10.17487/RFC2119, March 1997, 1925 . 1927 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1928 Specifications: ABNF", STD 68, RFC 5234, 1929 DOI 10.17487/RFC5234, January 2008, 1930 . 1932 [RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed., 1933 and A. Bierman, Ed., "Network Configuration Protocol 1934 (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, 1935 . 1937 [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", 1938 RFC 7950, DOI 10.17487/RFC7950, August 2016, 1939 . 1941 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1942 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1943 May 2017, . 1945 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 1946 Definition Language (CDDL): A Notational Convention to 1947 Express Concise Binary Object Representation (CBOR) and 1948 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 1949 June 2019, . 1951 [RFC8949] Bormann, C. and P. Hoffman, "Concise Binary Object 1952 Representation (CBOR)", STD 94, RFC 8949, 1953 DOI 10.17487/RFC8949, December 2020, 1954 . 1956 10.2. Informative References 1958 [I-D.ietf-core-comi] 1959 Veillette, M., Stok, P. V. D., Pelov, A., Bierman, A., and 1960 I. Petrov, "CoAP Management Interface (CORECONF)", Work in 1961 Progress, Internet-Draft, draft-ietf-core-comi-11, 17 1962 January 2021, . 1965 [I-D.ietf-core-sid] 1966 Veillette, M., Pelov, A., and I. Petrov, "YANG Schema Item 1967 iDentifier (YANG SID)", Work in Progress, Internet-Draft, 1968 draft-ietf-core-sid-15, 17 January 2021, 1969 . 1972 [RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for 1973 Constrained-Node Networks", RFC 7228, 1974 DOI 10.17487/RFC7228, May 2014, 1975 . 1977 [RFC7317] Bierman, A. and M. Bjorklund, "A YANG Data Model for 1978 System Management", RFC 7317, DOI 10.17487/RFC7317, August 1979 2014, . 1981 [RFC7951] Lhotka, L., "JSON Encoding of Data Modeled with YANG", 1982 RFC 7951, DOI 10.17487/RFC7951, August 2016, 1983 . 1985 [RFC8040] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF 1986 Protocol", RFC 8040, DOI 10.17487/RFC8040, January 2017, 1987 . 1989 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 1990 Interchange Format", STD 90, RFC 8259, 1991 DOI 10.17487/RFC8259, December 2017, 1992 . 1994 [RFC8343] Bjorklund, M., "A YANG Data Model for Interface 1995 Management", RFC 8343, DOI 10.17487/RFC8343, March 2018, 1996 . 1998 [RFC8344] Bjorklund, M., "A YANG Data Model for IP Management", 1999 RFC 8344, DOI 10.17487/RFC8344, March 2018, 2000 . 2002 Acknowledgments 2004 This document has been largely inspired by the extensive works done 2005 by Andy Bierman and Peter van der Stok on [I-D.ietf-core-comi]. 2006 [RFC7951] has also been a critical input to this work. The authors 2007 would like to thank the authors and contributors to these two drafts. 2009 The authors would also like to acknowledge the review, feedback, and 2010 comments from Ladislav Lhotka and Jürgen Schönwälder. 2012 Authors' Addresses 2014 Michel Veillette (editor) 2015 Trilliant Networks Inc. 2016 610 Rue du Luxembourg 2017 Granby Quebec J2J 2V2 2018 Canada 2020 Email: michel.veillette@trilliantinc.com 2022 Ivaylo Petrov (editor) 2023 Google Switzerland GmbH 2024 Brandschenkestrasse 110 2025 CH-8002 Zurich 2026 Switzerland 2028 Email: ivaylopetrov@google.com 2030 Alexander Pelov 2031 Acklio 2032 1137A avenue des Champs Blancs 2033 35510 Cesson-Sevigne 2034 France 2036 Email: a@ackl.io 2038 Carsten Bormann 2039 Universität Bremen TZI 2040 Postfach 330440 2041 D-28359 Bremen 2042 Germany 2044 Phone: +49-421-218-63921 2045 Email: cabo@tzi.org