idnits 2.17.1 draft-ietf-core-yang-cbor-12.txt: 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: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- ** The abstract seems to contain references ([RFC7049]), which it shouldn't. Please replace those with straight textual mentions of the documents in question. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 09, 2020) is 1508 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 1192, but not defined -- Looks like a reference, but probably isn't: '257' on line 1192 == Missing Reference: '0-9' is mentioned on line 1509, but not defined == Missing Reference: '1-9' is mentioned on line 1500, but not defined == Missing Reference: '0-4' is mentioned on line 1509, but not defined == Missing Reference: '0-5' is mentioned on line 1509, but not defined == Missing Reference: '0-9a-fA-F' is mentioned on line 1508, but not defined -- Looks like a reference, but probably isn't: '01' on line 1509 ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) == Outdated reference: A later version (-17) exists of draft-ietf-core-comi-08 == Outdated reference: A later version (-24) exists of draft-ietf-core-sid-11 Summary: 2 errors (**), 0 flaws (~~), 9 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: September 10, 2020 A. Pelov 6 Acklio 7 March 09, 2020 9 CBOR Encoding of Data Modeled with YANG 10 draft-ietf-core-yang-cbor-12 12 Abstract 14 This document defines encoding rules for serializing configuration 15 data, state data, RPC input and RPC output, Action input, Action 16 output, notifications and yang data template defined within YANG 17 modules using the Concise Binary Object Representation (CBOR) 18 [RFC7049]. 20 Status of This Memo 22 This Internet-Draft is submitted in full conformance with the 23 provisions of BCP 78 and BCP 79. 25 Internet-Drafts are working documents of the Internet Engineering 26 Task Force (IETF). Note that other groups may also distribute 27 working documents as Internet-Drafts. The list of current Internet- 28 Drafts is at https://datatracker.ietf.org/drafts/current/. 30 Internet-Drafts are draft documents valid for a maximum of six months 31 and may be updated, replaced, or obsoleted by other documents at any 32 time. It is inappropriate to use Internet-Drafts as reference 33 material or to cite them other than as "work in progress." 35 This Internet-Draft will expire on September 10, 2020. 37 Copyright Notice 39 Copyright (c) 2020 IETF Trust and the persons identified as the 40 document authors. All rights reserved. 42 This document is subject to BCP 78 and the IETF Trust's Legal 43 Provisions Relating to IETF Documents 44 (https://trustee.ietf.org/license-info) in effect on the date of 45 publication of this document. Please review these documents 46 carefully, as they describe your rights and restrictions with respect 47 to this document. Code Components extracted from this document must 48 include Simplified BSD License text as described in Section 4.e of 49 the Trust Legal Provisions and are provided without warranty as 50 described in the Simplified BSD License. 52 Table of Contents 54 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 55 2. Terminology and Notation . . . . . . . . . . . . . . . . . . 3 56 3. Properties of the CBOR Encoding . . . . . . . . . . . . . . . 5 57 3.1. CBOR diagnostic notation . . . . . . . . . . . . . . . . 5 58 3.2. YANG Schema Item iDentifier (SID) . . . . . . . . . . . . 6 59 3.3. Name . . . . . . . . . . . . . . . . . . . . . . . . . . 7 60 4. Encoding of YANG Schema Node Instances . . . . . . . . . . . 9 61 4.1. The 'leaf' . . . . . . . . . . . . . . . . . . . . . . . 9 62 4.1.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 9 63 4.1.2. Using names in keys . . . . . . . . . . . . . . . . . 9 64 4.2. The 'container' and other collections . . . . . . . . . . 10 65 4.2.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 11 66 4.2.2. Using names in keys . . . . . . . . . . . . . . . . . 12 67 4.3. The 'leaf-list' . . . . . . . . . . . . . . . . . . . . . 13 68 4.3.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 14 69 4.3.2. Using names in keys . . . . . . . . . . . . . . . . . 14 70 4.4. The 'list' and 'list' instance(s) . . . . . . . . . . . . 15 71 4.4.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 16 72 4.4.2. Using names in keys . . . . . . . . . . . . . . . . . 18 73 4.5. The 'anydata' . . . . . . . . . . . . . . . . . . . . . . 20 74 4.5.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 21 75 4.5.2. Using names in keys . . . . . . . . . . . . . . . . . 22 76 4.6. The 'anyxml' . . . . . . . . . . . . . . . . . . . . . . 23 77 4.6.1. Using SIDs in keys . . . . . . . . . . . . . . . . . 23 78 4.6.2. Using names in keys . . . . . . . . . . . . . . . . . 24 79 5. Encoding of YANG data templates . . . . . . . . . . . . . . . 24 80 5.1. Using SIDs in keys . . . . . . . . . . . . . . . . . . . 25 81 5.2. Using names in keys . . . . . . . . . . . . . . . . . . . 26 82 6. Representing YANG Data Types in CBOR . . . . . . . . . . . . 27 83 6.1. The unsigned integer Types . . . . . . . . . . . . . . . 27 84 6.2. The integer Types . . . . . . . . . . . . . . . . . . . . 28 85 6.3. The 'decimal64' Type . . . . . . . . . . . . . . . . . . 28 86 6.4. The 'string' Type . . . . . . . . . . . . . . . . . . . . 29 87 6.5. The 'boolean' Type . . . . . . . . . . . . . . . . . . . 29 88 6.6. The 'enumeration' Type . . . . . . . . . . . . . . . . . 29 89 6.7. The 'bits' Type . . . . . . . . . . . . . . . . . . . . . 30 90 6.8. The 'binary' Type . . . . . . . . . . . . . . . . . . . . 32 91 6.9. The 'leafref' Type . . . . . . . . . . . . . . . . . . . 32 92 6.10. The 'identityref' Type . . . . . . . . . . . . . . . . . 33 93 6.10.1. SIDs as identityref . . . . . . . . . . . . . . . . 33 94 6.10.2. Name as identityref . . . . . . . . . . . . . . . . 34 95 6.11. The 'empty' Type . . . . . . . . . . . . . . . . . . . . 34 96 6.12. The 'union' Type . . . . . . . . . . . . . . . . . . . . 35 97 6.13. The 'instance-identifier' Type . . . . . . . . . . . . . 36 98 6.13.1. SIDs as instance-identifier . . . . . . . . . . . . 36 99 6.13.2. Names as instance-identifier . . . . . . . . . . . . 39 100 7. Security Considerations . . . . . . . . . . . . . . . . . . . 41 101 8. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 41 102 8.1. CBOR Tags Registry . . . . . . . . . . . . . . . . . . . 41 103 9. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 41 104 10. References . . . . . . . . . . . . . . . . . . . . . . . . . 42 105 10.1. Normative References . . . . . . . . . . . . . . . . . . 42 106 10.2. Informative References . . . . . . . . . . . . . . . . . 42 107 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 43 109 1. Introduction 111 The specification of the YANG 1.1 data modeling language [RFC7950] 112 defines an XML encoding for data instances, i.e. contents of 113 configuration datastores, state data, RPC inputs and outputs, action 114 inputs and outputs, and event notifications. 116 A new set of encoding rules has been defined to allow the use of the 117 same data models in environments based on the JavaScript Object 118 Notation (JSON) Data Interchange Format [RFC8259]. This is 119 accomplished in the JSON Encoding of Data Modeled with YANG 120 specification [RFC7951]. 122 The aim of this document is to define a set of encoding rules for the 123 Concise Binary Object Representation (CBOR) [RFC7049]. The resulting 124 encoding is more compact compared to XML and JSON and more suitable 125 for Constrained Nodes and/or Constrained Networks as defined by 126 [RFC7228]. 128 2. Terminology and Notation 130 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 131 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 132 "OPTIONAL" in this document are to be interpreted as described in BCP 133 14 [RFC2119] [RFC8174] when, and only when, they appear in all 134 capitals, as shown here. 136 The following terms are defined in [RFC7950]: 138 o action 140 o anydata 142 o anyxml 144 o data node 145 o data tree 147 o datastore 149 o feature 151 o identity 153 o module 155 o notification 157 o RPC 159 o schema node 161 o schema tree 163 o submodule 165 The following terms are defined in [RFC8040]: 167 o yang-data (YANG extension) 169 o YANG data template 171 This specification also makes use of the following terminology: 173 o child: A schema node defined within a collection such as a 174 container, a list, a case, a notification, an RPC input, an RPC 175 output, an action input, an action output. 177 o delta: Difference between the current SID and a reference SID. A 178 reference SID is defined for each context for which deltas are 179 used. 181 o item: A schema node, an identity, a module, a submodule or a 182 feature defined using the YANG modeling language. 184 o parent: The collection in which a schema node is defined. 186 o YANG Schema Item iDentifier (SID): Unsigned integer used to 187 identify different YANG items. 189 3. Properties of the CBOR Encoding 191 This document defines CBOR encoding rules for YANG schema trees and 192 their subtrees. 194 A collection such as container, list instance, notification, RPC 195 input, RPC output, action input and action output is serialized using 196 a CBOR map in which each child schema node is encoded using a key and 197 a value. This specification supports two type of CBOR keys; YANG 198 Schema Item iDentifier (SID) as defined in Section 3.2 and names as 199 defined in Section 3.3. Each of these key types is encoded using a 200 specific CBOR type which allows their interpretation during the 201 deserialization process. Protocols or mechanisms implementing this 202 specification can mandate the use of a specific key type. 204 In order to minimize the size of the encoded data, the proposed 205 mapping avoids any unnecessary meta-information beyond those natively 206 supported by CBOR. For instance, CBOR tags are used solely in the 207 case of SID not encoded as delta, anyxml schema nodes and the union 208 datatype to distinguish explicitly the use of different YANG 209 datatypes encoded using the same CBOR major type. 211 Unless specified otherwise by the protocol or mechanism implementing 212 this specification, the indefinite lengths encoding as defined in 213 [RFC7049] section 2.2 SHALL be supported by CBOR decoders. 215 Data nodes implemented using a CBOR array, map, byte string, and text 216 string can be instantiated but empty. In this case, they are encoded 217 with a length of zero. 219 Application payloads carrying a value serialized using the rules 220 defined by this specification (e.g. CoAP Content-Format) SHOULD 221 include the identifier (e.g. SID, namespace qualified name, 222 instance-identifier) of this value. When SIDs are used as 223 identifiers, the reference SID SHALL be included in the payload to 224 allow stateless conversion of delta values to SIDs. 226 Examples in section Section 4 include a root CBOR map with a single 227 entry having a key set to either a namespace qualified name or a SID. 228 This root CBOR map is provided only as a typical usage example and is 229 not part of the present encoding rules. Only the value within this 230 CBOR map is compulsory. 232 3.1. CBOR diagnostic notation 234 Within this document, CBOR binary contents are represented using an 235 equivalent textual form called CBOR diagnostic notation as defined in 236 [RFC7049] section 6. This notation is used strictly for 237 documentation purposes and is never used in the data serialization. 238 Table 1 below provides a summary of this notation. 240 +----------+------+--------------------------+-----------+----------+ 241 | CBOR | CBOR | Diagnostic notation | Example | CBOR | 242 | content | type | | | encoding | 243 +----------+------+--------------------------+-----------+----------+ 244 | Unsigned | 0 | Decimal digits | 123 | 18 7B | 245 | integer | | | | | 246 | Negative | 1 | Decimal digits prefixed | -123 | 38 7A | 247 | integer | | by a minus sign | | | 248 | Byte | 2 | Hexadecimal value | h'F15C' | 42 f15C | 249 | string | | enclosed between single | | | 250 | | | quotes and prefixed by | | | 251 | | | an 'h' | | | 252 | Text | 3 | String of Unicode | "txt" | 63 | 253 | string | | characters enclosed | | 747874 | 254 | | | between double quotes | | | 255 | Array | 4 | Comma-separated list of | [ 1, 2 ] | 82 01 02 | 256 | | | values within square | | | 257 | | | brackets | | | 258 | Map | 5 | Comma-separated list of | { 1: 123, | a2 | 259 | | | key : value pairs within | 2: 456 } | 01187B | 260 | | | curly braces | | 021901C8 | 261 | Boolean | 7/20 | false | false | F4 | 262 | | 7/21 | true | true | F5 | 263 | Null | 7/22 | null | null | F6 | 264 | Not | 7/23 | undefined | undefined | F7 | 265 | assigned | | | | | 266 +----------+------+--------------------------+-----------+----------+ 268 Table 1: CBOR diagnostic notation summary 270 Note: CBOR binary contents shown in this specification are annotated 271 with comments. These comments are delimited by slashes ("/") as 272 defined in [RFC8610] Appendix G.6. 274 3.2. YANG Schema Item iDentifier (SID) 276 Some of the items defined in YANG [RFC7950] require the use of a 277 unique identifier. In both NETCONF [RFC6241] and RESTCONF [RFC8040], 278 these identifiers are implemented using strings. To allow the 279 implementation of data models defined in YANG in constrained devices 280 and constrained networks, a more compact method to identify YANG 281 items is required. This compact identifier, called YANG Schema Item 282 iDentifier (SID), is an unsigned integer. The following items are 283 identified using SIDs: 285 o identities 287 o data nodes 289 o RPCs and associated input(s) and output(s) 291 o actions and associated input(s) and output(s) 293 o notifications and associated information 295 o YANG modules, submodules and features 297 To minimize their size, SIDs used as keys in inner CBOR maps are 298 typically encoded using deltas. Conversion from SIDs to deltas and 299 back to SIDs are stateless processes solely based on the data 300 serialized or deserialized. These SIDs may also be encoded as 301 absolute number when enclosed by CBOR tag 47. 303 Mechanisms and processes used to assign SIDs to YANG items and to 304 guarantee their uniqueness are outside the scope of the present 305 specification. If SIDs are to be used, the present specification is 306 used in conjunction with a specification defining this management. 307 One example for such a specification is [I-D.ietf-core-sid]. 309 3.3. Name 311 This specification also supports the encoding of YANG item 312 identifiers as string, similar as those used by the JSON Encoding of 313 Data Modeled with YANG [RFC7951]. This approach can be used to avoid 314 the management overhead associated to SIDs allocation. The main 315 drawback is the significant increase in size of the encoded data. 317 YANG item identifiers implemented using names MUST be in one of the 318 following forms: 320 o simple - the identifier of the YANG item (i.e. schema node or 321 identity). 323 o namespace qualified - the identifier of the YANG item is prefixed 324 with the name of the module in which this item is defined, 325 separated by the colon character (":"). 327 The name of a module determines the namespace of all YANG items 328 defined in that module. If an item is defined in a submodule, then 329 the namespace qualified name uses the name of the main module to 330 which the submodule belongs. 332 ABNF syntax [RFC5234] of a name is shown in Figure 1, where the 333 production for "identifier" is defined in Section 14 of [RFC7950]. 335 name = [identifier ":"] identifier 337 Figure 1: ABNF Production for a simple or namespace qualified name 339 A namespace qualified name MUST be used for all members of a top- 340 level CBOR map and then also whenever the namespaces of the data node 341 and its parent node are different. In all other cases, the simple 342 form of the name SHOULD be used. 344 Definition example: 346 module example-foomod { 347 container top { 348 leaf foo { 349 type uint8; 350 } 351 } 352 } 354 module example-barmod { 355 import example-foomod { 356 prefix "foomod"; 357 } 358 augment "/foomod:top" { 359 leaf bar { 360 type boolean; 361 } 362 } 363 } 365 A valid CBOR encoding of the 'top' container is as follow. 367 CBOR diagnostic notation: 369 { 370 "example-foomod:top": { 371 "foo": 54, 372 "example-barmod:bar": true 373 } 374 } 376 Both the 'top' container and the 'bar' leaf defined in a different 377 YANG module as its parent container are encoded as namespace 378 qualified names. The 'foo' leaf defined in the same YANG module as 379 its parent container is encoded as simple name. 381 4. Encoding of YANG Schema Node Instances 383 Schema node instances defined using the YANG modeling language are 384 encoded using CBOR [RFC7049] based on the rules defined in this 385 section. We assume that the reader is already familiar with both 386 YANG [RFC7950] and CBOR [RFC7049]. 388 4.1. The 'leaf' 390 A 'leaf' MUST be encoded accordingly to its datatype using one of the 391 encoding rules specified in Section 6. 393 The following examples shows the encoding of a 'hostname' leaf using 394 a SID or a name. 396 Definition example from [RFC7317]: 398 leaf hostname { 399 type inet:domain-name; 400 } 402 4.1.1. Using SIDs in keys 404 CBOR diagnostic notation: 406 { 407 1752 : "myhost.example.com" / hostname (SID 1752) / 408 } 410 CBOR encoding: 412 A1 # map(1) 413 19 06D8 # unsigned(1752) 414 72 # text(18) 415 6D79686F73742E6578616D706C652E636F6D # "myhost.example.com" 417 4.1.2. Using names in keys 419 CBOR diagnostic notation: 421 { 422 "ietf-system:hostname" : "myhost.example.com" 423 } 425 CBOR encoding: 427 A1 # map(1) 428 74 # text(20) 429 696574662D73797374656D3A686F73746E616D65 430 72 # text(18) 431 6D79686F73742E6578616D706C652E636F6D 433 4.2. The 'container' and other collections 435 Collections such as containers, list instances, notification 436 contents, rpc inputs, rpc outputs, action inputs and action outputs 437 MUST be encoded using a CBOR map data item (major type 5). A map is 438 comprised of pairs of data items, with each data item consisting of a 439 key and a value. Each key within the CBOR map is set to a schema 440 node identifier, each value is set to the value of this schema node 441 instance according to the instance datatype. 443 This specification supports two type of CBOR keys; SID as defined in 444 Section 3.2 and names as defined in Section 3.3. 446 The following examples shows the encoding of a 'system-state' 447 container instance using SIDs or names. 449 Definition example from [RFC7317]: 451 typedef date-and-time { 452 type string { 453 pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-] 454 \d{2}:\d{2})'; 455 } 456 } 458 container system-state { 460 container clock { 461 leaf current-datetime { 462 type date-and-time; 463 } 465 leaf boot-datetime { 466 type date-and-time; 467 } 468 } 469 } 471 4.2.1. Using SIDs in keys 473 In the context of containers and other collections, CBOR map keys 474 within inner CBOR maps can be encoded using deltas or SIDs. In the 475 case of deltas, they MUST be encoded using a CBOR unsigned integer 476 (major type 0) or CBOR negative integer (major type 1), depending on 477 the actual delta value. In the case of SID, they are encoded using 478 the SID value enclosed by CBOR tag 47 as defined in Section 8.1. 480 Delta values are computed as follows: 482 o In the case of a 'container', deltas are equal to the SID of the 483 current schema node minus the SID of the parent 'container'. 485 o In the case of a 'list', deltas are equal to the SID of the 486 current schema node minus the SID of the parent 'list'. 488 o In the case of an 'rpc input' or 'rcp output', deltas are equal to 489 the SID of the current schema node minus the SID of the 'rpc'. 491 o In the case of an 'action input' or 'action output', deltas are 492 equal to the SID of the current schema node minus the SID of the 493 'action'. 495 o In the case of an 'notification content', deltas are equal to the 496 SID of the current schema node minus the SID of the 497 'notification'. 499 CBOR diagnostic notation: 501 { 502 1720 : { / system-state (SID 1720) / 503 1 : { / clock (SID 1721) / 504 2 : "2015-10-02T14:47:24Z-05:00", / current-datetime(SID 1723)/ 505 1 : "2015-09-15T09:12:58Z-05:00" / boot-datetime (SID 1722) / 506 } 507 } 508 } 510 CBOR encoding: 512 A1 # map(1) 513 19 06B8 # unsigned(1720) 514 A1 # map(1) 515 01 # unsigned(1) 516 A2 # map(2) 517 02 # unsigned(2) 518 78 1A # text(26) 519 323031352D31302D30325431343A34373A32345A2D30353A3030 520 01 # unsigned(1) 521 78 1A # text(26) 522 323031352D30392D31355430393A31323A35385A2D30353A3030 524 Figure 2: System state clock encoding 526 4.2.2. Using names in keys 528 CBOR map keys implemented using names MUST be encoded using a CBOR 529 text string data item (major type 3). A namespace-qualified name 530 MUST be used each time the namespace of a schema node and its parent 531 differ. In all other cases, the simple form of the name MUST be 532 used. Names and namespaces are defined in [RFC7951] section 4. 534 The following example shows the encoding of a 'system' container 535 instance using names. 537 Definition example from [RFC7317]: 539 typedef date-and-time { 540 type string { 541 pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-] 542 \d{2}:\d{2})'; 543 } 544 } 546 container system-state { 548 container clock { 549 leaf current-datetime { 550 type date-and-time; 551 } 553 leaf boot-datetime { 554 type date-and-time; 555 } 556 } 557 } 559 CBOR diagnostic notation: 561 { 562 "ietf-system:system-state" : { 563 "clock" : { 564 "current-datetime" : "2015-10-02T14:47:24Z-05:00", 565 "boot-datetime" : "2015-09-15T09:12:58Z-05:00" 566 } 567 } 568 } 570 CBOR encoding: 572 A1 # map(1) 573 78 18 # text(24) 574 696574662D73797374656D3A73797374656D2D7374617465 575 A1 # map(1) 576 65 # text(5) 577 636C6F636B # "clock" 578 A2 # map(2) 579 70 # text(16) 580 63757272656E742D6461746574696D65 581 78 1A # text(26) 582 323031352D31302D30325431343A34373A32345A2D30353A3030 583 6D # text(13) 584 626F6F742D6461746574696D65 585 78 1A # text(26) 586 323031352D30392D31355430393A31323A35385A2D30353A3030 588 4.3. The 'leaf-list' 590 A leaf-list MUST be encoded using a CBOR array data item (major type 591 4). Each entry of this array MUST be encoded accordingly to its 592 datatype using one of the encoding rules specified in Section 6. 594 The following example shows the encoding of the 'search' leaf-list 595 instance containing two entries, "ietf.org" and "ieee.org". 597 Definition example [RFC7317]: 599 typedef domain-name { 600 type string { 601 length "1..253"; 602 pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9].) 603 *([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.? 604 )|\.'; 605 } 606 } 608 leaf-list search { 609 type domain-name; 610 ordered-by user; 611 } 613 4.3.1. Using SIDs in keys 615 CBOR diagnostic notation: 617 { 618 1746 : [ "ietf.org", "ieee.org" ] / search (SID 1746) / 619 } 621 CBOR encoding: 623 A1 # map(1) 624 19 06D2 # unsigned(1746) 625 82 # array(2) 626 68 # text(8) 627 696574662E6F7267 # "ietf.org" 628 68 # text(8) 629 696565652E6F7267 # "ieee.org" 631 4.3.2. Using names in keys 633 CBOR diagnostic notation: 635 { 636 "ietf-system:search" : [ "ietf.org", "ieee.org" ] 637 } 639 CBOR encoding: 641 A1 # map(1) 642 72 # text(18) 643 696574662D73797374656D3A736561726368 # "ietf-system:search" 644 82 # array(2) 645 68 # text(8) 646 696574662E6F7267 # "ietf.org" 647 68 # text(8) 648 696565652E6F7267 # "ieee.org" 650 4.4. The 'list' and 'list' instance(s) 652 A list or a subset of a list MUST be encoded using a CBOR array data 653 item (major type 4). Each list instance within this CBOR array is 654 encoded using a CBOR map data item (major type 5) based on the 655 encoding rules of a collection as defined in Section 4.2. 657 It is important to note that this encoding rule also apply to a 658 single 'list' instance. 660 The following examples show the encoding of a 'server' list using 661 SIDs or names. 663 Definition example from [RFC7317]: 665 list server { 666 key name; 668 leaf name { 669 type string; 670 } 671 choice transport { 672 case udp { 673 container udp { 674 leaf address { 675 type host; 676 mandatory true; 677 } 678 leaf port { 679 type port-number; 680 } 681 } 682 } 683 } 684 leaf association-type { 685 type enumeration { 686 enum server; 687 enum peer; 688 enum pool; 689 } 690 default server; 691 } 692 leaf iburst { 693 type boolean; 694 default false; 695 } 696 leaf prefer { 697 type boolean; 698 default false; 699 } 700 } 702 4.4.1. Using SIDs in keys 704 The encoding rules of each 'list' instance are defined in 705 Section 4.2.1. Deltas of list members are equal to the SID of the 706 current schema node minus the SID of the 'list'. 708 CBOR diagnostic notation: 710 { 711 1756 : [ / server (SID 1756) / 712 { 713 3 : "NRC TIC server", / name (SID 1759) / 714 5 : { / udp (SID 1761) / 715 1 : "tic.nrc.ca", / address (SID 1762) / 716 2 : 123 / port (SID 1763) / 717 }, 718 1 : 0, / association-type (SID 1757) / 719 2 : false, / iburst (SID 1758) / 720 4 : true / prefer (SID 1760) / 721 }, 722 { 723 3 : "NRC TAC server", / name (SID 1759) / 724 5 : { / udp (SID 1761) / 725 1 : "tac.nrc.ca" / address (SID 1762) / 726 } 727 } 728 ] 729 } 731 CBOR encoding: 733 A1 # map(1) 734 19 06DC # unsigned(1756) 735 82 # array(2) 736 A5 # map(5) 737 03 # unsigned(3) 738 6E # text(14) 739 4E52432054494320736572766572 # "NRC TIC server" 740 05 # unsigned(5) 741 A2 # map(2) 742 01 # unsigned(1) 743 6A # text(10) 744 7469632E6E72632E6361 # "tic.nrc.ca" 745 02 # unsigned(2) 746 18 7B # unsigned(123) 747 01 # unsigned(1) 748 00 # unsigned(0) 749 02 # unsigned(2) 750 F4 # primitive(20) 751 04 # unsigned(4) 752 F5 # primitive(21) 753 A2 # map(2) 754 03 # unsigned(3) 755 6E # text(14) 756 4E52432054414320736572766572 # "NRC TAC server" 757 05 # unsigned(5) 758 A1 # map(1) 759 01 # unsigned(1) 760 6A # text(10) 761 7461632E6E72632E6361 # "tac.nrc.ca" 763 4.4.2. Using names in keys 765 The encoding rules of each 'list' instance are defined in 766 Section 4.2.2. 768 CBOR diagnostic notation: 770 { 771 "ietf-system:server" : [ 772 { 773 "name" : "NRC TIC server", 774 "udp" : { 775 "address" : "tic.nrc.ca", 776 "port" : 123 777 }, 778 "association-type" : 0, 779 "iburst" : false, 780 "prefer" : true 781 }, 782 { 783 "name" : "NRC TAC server", 784 "udp" : { 785 "address" : "tac.nrc.ca" 786 } 787 } 788 ] 789 } 791 CBOR encoding: 793 A1 # map(1) 794 72 # text(18) 795 696574662D73797374656D3A736572766572 796 82 # array(2) 797 A5 # map(5) 798 64 # text(4) 799 6E616D65 # "name" 800 6E # text(14) 801 4E52432054494320736572766572 802 63 # text(3) 803 756470 # "udp" 804 A2 # map(2) 805 67 # text(7) 806 61646472657373 # "address" 807 6A # text(10) 808 7469632E6E72632E6361 # "tic.nrc.ca" 809 64 # text(4) 810 706F7274 # "port" 811 18 7B # unsigned(123) 812 70 # text(16) 813 6173736F63696174696F6E2D74797065 814 00 # unsigned(0) 815 66 # text(6) 816 696275727374 # "iburst" 817 F4 # primitive(20) 818 66 # text(6) 819 707265666572 # "prefer" 820 F5 # primitive(21) 821 A2 # map(2) 822 64 # text(4) 823 6E616D65 # "name" 824 6E # text(14) 825 4E52432054414320736572766572 826 63 # text(3) 827 756470 # "udp" 828 A1 # map(1) 829 67 # text(7) 830 61646472657373 # "address" 831 6A # text(10) 832 7461632E6E72632E6361 # "tac.nrc.ca" 834 4.5. The 'anydata' 836 An anydata serves as a container for an arbitrary set of schema nodes 837 that otherwise appear as normal YANG-modeled data. An anydata 838 instance is encoded using the same rules as a container, i.e., CBOR 839 map. The requirement that anydata content can be modeled by YANG 840 implies the following: 842 o CBOR map keys of any inner schema nodes MUST be set to valid 843 deltas or names. 845 o The CBOR array MUST contain either unique scalar values (as a 846 leaf-list, see Section 4.3), or maps (as a list, see Section 4.4). 848 o CBOR map values MUST follow the encoding rules of one of the 849 datatypes listed in Section 4. 851 The following example shows a possible use of an anydata. In this 852 example, an anydata is used to define a schema node containing a 853 notification event, this schema node can be part of a YANG list to 854 create an event logger. 856 Definition example: 858 module event-log { 859 ... 860 anydata last-event; # SID 60123 862 This example also assumes the assistance of the following 863 notification. 865 module example-port { 866 ... 868 notification example-port-fault { # SID 60200 869 leaf port-name { # SID 60201 870 type string; 871 } 872 leaf port-fault { # SID 60202 873 type string; 874 } 875 } 876 } 878 4.5.1. Using SIDs in keys 880 CBOR diagnostic notation: 882 { 883 60123 : { / last-event (SID 60123) / 884 77 : { / event (SID 60200) / 885 1 : "0/4/21", / port-name (SID 60201) / 886 2 : "Open pin 2" / port-fault (SID 60202) / 887 } 888 } 889 } 890 CBOR encoding: 892 A1 # map(1) 893 19 EADB # unsigned(60123) 894 A1 # map(1) 895 18 4D # unsigned(77) 896 A2 # map(2) 897 18 4E # unsigned(78) 898 66 # text(6) 899 302F342F3231 # "0/4/21" 900 18 4F # unsigned(79) 901 6A # text(10) 902 4F70656E2070696E2032 # "Open pin 2" 904 In some implementations, it might be simpler to use the absolute SID 905 tag encoding for the anydata root element. The resulting encoding is 906 as follow: 908 { 909 60123 : { / last-event (SID 60123) / 910 47(60200) : { / event (SID 60123) / 911 1 : "0/4/21", / port-name (SID 60201) / 912 2 : "Open pin 2" / port-fault (SID 60202) / 913 } 914 } 915 } 917 4.5.2. Using names in keys 919 CBOR diagnostic notation: 921 { 922 "event-log:last-event" : { 923 "example-port: example-port-fault" : { 924 "port-name" : "0/4/21", 925 "port-fault" : "Open pin 2" 926 } 927 } 928 } 930 CBOR encoding: 932 A1 # map(1) 933 74 # text(20) 934 6576656E742D6C6F673A6C6173742D6576656E74 935 A1 # map(1) 936 78 20 # text(32) 937 6578616D706C652D706F72743A206578616D7 938 06C652D706F72742D6661756C74 939 A2 # map(2) 940 69 # text(9) 941 706F72742D6E616D65 # "port-name" 942 66 # text(6) 943 302F342F3231 # "0/4/21" 944 6A # text(10) 945 706F72742D6661756C74 # "port-fault" 946 6A # text(10) 947 4F70656E2070696E2032 # "Open pin 2" 949 4.6. The 'anyxml' 951 An anyxml schema node is used to serialize an arbitrary CBOR content, 952 i.e., its value can be any CBOR binary object. anyxml value MAY 953 contain CBOR data items tagged with one of the tag listed in 954 Section 8.1, these tags shall be supported. 956 The following example shows a valid CBOR encoded instance consisting 957 of a CBOR array containing the CBOR simple values 'true', 'null' and 958 'true'. 960 Definition example from [RFC7951]: 962 module bar-module { 963 ... 964 anyxml bar; 966 4.6.1. Using SIDs in keys 968 CBOR diagnostic notation: 970 { 971 60000 : [true, null, true] / bar (SID 60000) / 972 } 974 CBOR encoding: 976 A1 # map(1) 977 19 EA60 # unsigned(60000) 978 83 # array(3) 979 F5 # primitive(21) 980 F6 # primitive(22) 981 F5 # primitive(21) 983 4.6.2. Using names in keys 985 CBOR diagnostic notation: 987 { 988 "bar-module:bar" : [true, null, true] / bar (SID 60000) / 989 } 991 CBOR encoding: 993 A1 # map(1) 994 6E # text(14) 995 6261722D6D6F64756C653A626172 # "bar-module:bar" 996 83 # array(3) 997 F5 # primitive(21) 998 F6 # primitive(22) 999 F5 # primitive(21) 1001 5. Encoding of YANG data templates 1003 YANG data templates are data structures defined in YANG but not 1004 intended to be implemented as part of a datastore. YANG data 1005 templates are defined using the 'yang-data' extension as described by 1006 [RFC8040]. 1008 YANG data templates MUST be encoded using the encoding rules of a 1009 collection as defined in Section 4.2. 1011 Just like YANG containers, YANG data templates can be encoded using 1012 either SIDs or names. 1014 Definition example from [I-D.ietf-core-comi]: 1016 import ietf-restconf { 1017 prefix rc; 1018 } 1020 rc:yang-data yang-errors { 1021 container error { 1022 leaf error-tag { 1023 type identityref { 1024 base error-tag; 1025 } 1026 } 1027 leaf error-app-tag { 1028 type identityref { 1029 base error-app-tag; 1030 } 1031 } 1032 leaf error-data-node { 1033 type instance-identifier; 1034 } 1035 leaf error-message { 1036 type string; 1037 } 1038 } 1039 } 1041 5.1. Using SIDs in keys 1043 YANG template encoded using SIDs are carried in a CBOR map containing 1044 a single item pair. The key of this item is set to the SID assigned 1045 to the YANG template container, the value is set the CBOR encoding of 1046 this container as defined in Section 4.2. 1048 This example shows a serialization example of the yang-errors 1049 template as defined in [I-D.ietf-core-comi] using SIDs as defined in 1050 Section 3.2. 1052 CBOR diagnostic notation: 1054 { 1055 1024 : { / error (SID 1024) / 1056 4 : 1011, / error-tag (SID 1028) / 1057 / = invalid-value (SID 1011) / 1058 1 : 1018, / error-app-tag (SID 1025) / 1059 / = not-in-range (SID 1018) / 1060 2 : 1740, / error-data-node (SID 1026) / 1061 / = timezone-utc-offset (SID 1740) / 1062 3 : "Maximum exceeded" / error-message (SID 1027) / 1063 } 1064 } 1066 CBOR encoding: 1068 A1 # map(1) 1069 19 0400 # unsigned(1024) 1070 A4 # map(4) 1071 04 # unsigned(4) 1072 19 03F3 # unsigned(1011) 1073 01 # unsigned(1) 1074 19 03FA # unsigned(1018) 1075 02 # unsigned(2) 1076 19 06CC # unsigned(1740) 1077 03 # unsigned(3) 1078 70 # text(16) 1079 4D6178696D756D206578636565646564 1081 5.2. Using names in keys 1083 YANG template encoded using names are carried in a CBOR map 1084 containing a single item pair. The key of this item is set to the 1085 namespace qualified name of the YANG template container, the value is 1086 set the CBOR encoding of this container as defined in Section 3.3. 1088 This example shows a serialization example of the yang-errors 1089 template as defined in [I-D.ietf-core-comi] using names as defined 1090 Section 3.3. 1092 CBOR diagnostic notation: 1094 { 1095 "ietf-comi:error" : { 1096 "error-tag" : "invalid-value", 1097 "error-app-tag" : "not-in-range", 1098 "error-data-node" : "timezone-utc-offset", 1099 "error-message" : "Maximum exceeded" 1100 } 1101 } 1102 CBOR encoding: 1104 A1 # map(1) 1105 6F # text(15) 1106 696574662D636F6D693A6572726F72 # "ietf-comi:error" 1107 A4 # map(4) 1108 69 # text(9) 1109 6572726F722D746167 # "error-tag" 1110 6D # text(13) 1111 696E76616C69642D76616C7565 # "invalid-value" 1112 6D # text(13) 1113 6572726F722D6170702D746167 # "error-app-tag" 1114 6C # text(12) 1115 6E6F742D696E2D72616E6765 # "not-in-range" 1116 6F # text(15) 1117 6572726F722D646174612D6E6F6465 # "error-data-node" 1118 73 # text(19) 1119 74696D657A6F6E652D7574632D6F6666736574 1120 # "timezone-utc-offset" 1121 6D # text(13) 1122 6572726F722D6D657373616765 # "error-message" 1123 70 # text(16) 1124 4D6178696D756D206578636565646564 1126 6. Representing YANG Data Types in CBOR 1128 The CBOR encoding of an instance of a leaf or leaf-list schema node 1129 depends on the built-in type of that schema node. The following sub- 1130 section defined the CBOR encoding of each built-in type supported by 1131 YANG as listed in [RFC7950] section 4.2.4. Each subsection shows an 1132 example value assigned to a schema node instance of the discussed 1133 built-in type. 1135 6.1. The unsigned integer Types 1137 Leafs of type uint8, uint16, uint32 and uint64 MUST be encoded using 1138 a CBOR unsigned integer data item (major type 0). 1140 The following example shows the encoding of a 'mtu' leaf instance set 1141 to 1280 bytes. 1143 Definition example from [RFC8344]: 1145 leaf mtu { 1146 type uint16 { 1147 range "68..max"; 1148 } 1149 } 1150 CBOR diagnostic notation: 1280 1152 CBOR encoding: 19 0500 1154 6.2. The integer Types 1156 Leafs of type int8, int16, int32 and int64 MUST be encoded using 1157 either CBOR unsigned integer (major type 0) or CBOR negative integer 1158 (major type 1), depending on the actual value. 1160 The following example shows the encoding of a 'timezone-utc-offset' 1161 leaf instance set to -300 minutes. 1163 Definition example from [RFC7317]: 1165 leaf timezone-utc-offset { 1166 type int16 { 1167 range "-1500 .. 1500"; 1168 } 1169 } 1171 CBOR diagnostic notation: -300 1173 CBOR encoding: 39 012B 1175 6.3. The 'decimal64' Type 1177 Leafs of type decimal64 MUST be encoded using a decimal fraction as 1178 defined in [RFC7049] section 2.4.3. 1180 The following example shows the encoding of a 'my-decimal' leaf 1181 instance set to 2.57. 1183 Definition example from [RFC7317]: 1185 leaf my-decimal { 1186 type decimal64 { 1187 fraction-digits 2; 1188 range "1 .. 3.14 | 10 | 20..max"; 1189 } 1190 } 1192 CBOR diagnostic notation: 4([-2, 257]) 1194 CBOR encoding: C4 82 21 19 0101 1196 6.4. The 'string' Type 1198 Leafs of type string MUST be encoded using a CBOR text string data 1199 item (major type 3). 1201 The following example shows the encoding of a 'name' leaf instance 1202 set to "eth0". 1204 Definition example from [RFC8343]: 1206 leaf name { 1207 type string; 1208 } 1210 CBOR diagnostic notation: "eth0" 1212 CBOR encoding: 64 65746830 1214 6.5. The 'boolean' Type 1216 Leafs of type boolean MUST be encoded using a CBOR simple value 1217 'true' (major type 7, additional information 21) or 'false' (major 1218 type 7, additional information 20). 1220 The following example shows the encoding of an 'enabled' leaf 1221 instance set to 'true'. 1223 Definition example from [RFC7317]: 1225 leaf enabled { 1226 type boolean; 1227 } 1229 CBOR diagnostic notation: true 1231 CBOR encoding: F5 1233 6.6. The 'enumeration' Type 1235 Leafs of type enumeration MUST be encoded using a CBOR unsigned 1236 integer (major type 0) or CBOR negative integer (major type 1), 1237 depending on the actual value. Enumeration values are either 1238 explicitly assigned using the YANG statement 'value' or automatically 1239 assigned based on the algorithm defined in [RFC7950] section 9.6.4.2. 1241 The following example shows the encoding of an 'oper-status' leaf 1242 instance set to 'testing'. 1244 Definition example from [RFC7317]: 1246 leaf oper-status { 1247 type enumeration { 1248 enum up { value 1; } 1249 enum down { value 2; } 1250 enum testing { value 3; } 1251 enum unknown { value 4; } 1252 enum dormant { value 5; } 1253 enum not-present { value 6; } 1254 enum lower-layer-down { value 7; } 1255 } 1256 } 1258 CBOR diagnostic notation: 3 1260 CBOR encoding: 03 1262 To avoid overlap of 'value' defined in different 'enumeration' 1263 statements, 'enumeration' defined in a Leafs of type 'union' MUST be 1264 encoded using a CBOR text string data item (major type 3) and MUST 1265 contain one of the names assigned by 'enum' statements in YANG. The 1266 encoding MUST be enclosed by the enumeration CBOR tag as specified in 1267 Section 8.1. 1269 Definition example from [RFC7950]: 1271 type union { 1272 type int32; 1273 type enumeration { 1274 enum "unbounded"; 1275 } 1276 } 1278 CBOR diagnostic notation: 44("unbounded") 1280 CBOR encoding: D8 2C 69 756E626F756E646564 1282 6.7. The 'bits' Type 1284 Leafs of type bits MUST be encoded using a CBOR byte string data item 1285 (major type 2). Bits position are either explicitly assigned using 1286 the YANG statement 'position' or automatically assigned based on the 1287 algorithm defined in [RFC7950] section 9.7.4.2. 1289 Bits position 0 to 7 are assigned to the first byte within the byte 1290 string, bits 8 to 15 to the second byte, and subsequent bytes are 1291 assigned similarly. Within each byte, bits are assigned from least 1292 to most significant. 1294 The following example shows the encoding of an 'alarm-state' leaf 1295 instance with the 'under-repair' and 'critical' flags set. 1297 Definition example from [RFC8348]: 1299 typedef alarm-state { 1300 type bits { 1301 bit unknown; 1302 bit under-repair; 1303 bit critical; 1304 bit major; 1305 bit minor; 1306 bit warning; 1307 bit indeterminate; 1308 } 1309 } 1311 leaf alarm-state { 1312 type alarm-state; 1313 } 1315 CBOR diagnostic notation: h'06' 1317 CBOR encoding: 41 06 1319 To avoid overlap of 'bit' defined in different 'bits' statements, 1320 'bits' defined in a Leafs of type 'union' MUST be encoded using a 1321 CBOR text string data item (major type 3) and MUST contain a space- 1322 separated sequence of names of 'bit' that are set. The encoding MUST 1323 be enclosed by the bits CBOR tag as specified in Section 8.1. 1325 The following example shows the encoding of an 'alarm-state' leaf 1326 instance defined using a union type with the 'under-repair' and 1327 'critical' flags set. 1329 Definition example: 1331 leaf alarm-state-2 { 1332 type union { 1333 type alarm-state; 1334 type bits { 1335 bit extra-flag; 1336 } 1337 } 1338 } 1339 CBOR diagnostic notation: 43("under-repair critical") 1341 CBOR encoding: D8 2B 75 756E6465722D72657061697220637269746963616C 1343 6.8. The 'binary' Type 1345 Leafs of type binary MUST be encoded using a CBOR byte string data 1346 item (major type 2). 1348 The following example shows the encoding of an 'aes128-key' leaf 1349 instance set to 0x1f1ce6a3f42660d888d92a4d8030476e. 1351 Definition example: 1353 leaf aes128-key { 1354 type binary { 1355 length 16; 1356 } 1357 } 1359 CBOR diagnostic notation: h'1F1CE6A3F42660D888D92A4D8030476E' 1361 CBOR encoding: 50 1F1CE6A3F42660D888D92A4D8030476E 1363 6.9. The 'leafref' Type 1365 Leafs of type leafref MUST be encoded using the rules of the schema 1366 node referenced by the 'path' YANG statement. 1368 The following example shows the encoding of an 'interface-state-ref' 1369 leaf instance set to "eth1". 1371 Definition example from [RFC8343]: 1373 typedef interface-state-ref { 1374 type leafref { 1375 path "/interfaces-state/interface/name"; 1376 } 1377 } 1379 container interfaces-state { 1380 list interface { 1381 key "name"; 1382 leaf name { 1383 type string; 1384 } 1385 leaf-list higher-layer-if { 1386 type interface-state-ref; 1387 } 1388 } 1389 } 1391 CBOR diagnostic notation: "eth1" 1393 CBOR encoding: 64 65746831 1395 6.10. The 'identityref' Type 1397 This specification supports two approaches for encoding identityref, 1398 a YANG Schema Item iDentifier (SID) as defined in Section 3.2 or a 1399 name as defined in [RFC7951] section 6.8. 1401 6.10.1. SIDs as identityref 1403 When schema nodes of type identityref are implemented using SIDs, 1404 they MUST be encoded using a CBOR unsigned integer data item (major 1405 type 0). (Note that no delta mechanism is employed for SIDs as 1406 identityref.) 1408 The following example shows the encoding of a 'type' leaf instance 1409 set to the value 'iana-if-type:ethernetCsmacd' (SID 1880). 1411 Definition example from [RFC7317]: 1413 identity interface-type { 1414 } 1416 identity iana-interface-type { 1417 base interface-type; 1418 } 1420 identity ethernetCsmacd { 1421 base iana-interface-type; 1422 } 1424 leaf type { 1425 type identityref { 1426 base interface-type; 1427 } 1428 } 1430 CBOR diagnostic notation: 1880 1432 CBOR encoding: 19 0758 1434 6.10.2. Name as identityref 1436 Alternatively, an identityref MAY be encoded using a name as defined 1437 in Section 3.3. When names are used, identityref MUST be encoded 1438 using a CBOR text string data item (major type 3). If the identity 1439 is defined in different module than the leaf node containing the 1440 identityref data node, the namespace qualified form MUST be used. 1441 Otherwise, both the simple and namespace qualified forms are 1442 permitted. Names and namespaces are defined in Section 3.3. 1444 The following example shows the encoding of the identity 'iana-if- 1445 type:ethernetCsmacd' using its namespace qualified name. This 1446 example is described in Section 6.10.1. 1448 CBOR diagnostic notation: "iana-if-type:ethernetCsmacd" 1450 CBOR encoding: 78 1b 1451 69616E612D69662D747970653A65746865726E657443736D616364 1453 6.11. The 'empty' Type 1455 Leafs of type empty MUST be encoded using the CBOR null value (major 1456 type 7, additional information 22). 1458 The following example shows the encoding of a 'is-router' leaf 1459 instance when present. 1461 Definition example from [RFC8344]: 1463 leaf is-router { 1464 type empty; 1465 } 1467 CBOR diagnostic notation: null 1469 CBOR encoding: F6 1471 6.12. The 'union' Type 1473 Leafs of type union MUST be encoded using the rules associated with 1474 one of the types listed. When used in a union, the following YANG 1475 datatypes are enclosed by a CBOR tag to avoid confusion between 1476 different YANG datatypes encoded using the same CBOR major type. 1478 o bits 1480 o enumeration 1482 o identityref 1484 o instance-identifier 1486 See Section 8.1 for the assigned value of these CBOR tags. 1488 As mentioned in Section 6.6 and in Section 6.7, 'enumeration' and 1489 'bits' are encoded as CBOR text string data item (major type 3) when 1490 defined within a 'union' type. 1492 The following example shows the encoding of an 'ip-address' leaf 1493 instance when set to "2001:db8:a0b:12f0::1". 1495 Definition example from [RFC7317]: 1497 typedef ipv4-address { 1498 type string { 1499 pattern '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3} 1500 ([0-9][1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N} 1501 \p{L}]+)?'; 1502 } 1503 } 1505 typedef ipv6-address { 1506 type string { 1507 pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a 1508 -fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0 1509 -9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0 1510 -9]?[0-9])))(%[\p{N}\p{L}]+)?'; 1511 pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|((([^:]+:)*[^:]+) 1512 ?::(([^:]+:)*[^:]+)?)(%.+)?'; 1513 } 1514 } 1516 typedef ip-address { 1517 type union { 1518 type ipv4-address; 1519 type ipv6-address; 1520 } 1521 } 1523 leaf address { 1524 type inet:ip-address; 1525 } 1527 CBOR diagnostic notation: "2001:db8:a0b:12f0::1" 1529 CBOR encoding: 74 323030313A6462383A6130623A313266303A3A31 1531 6.13. The 'instance-identifier' Type 1533 This specification supports two approaches for encoding an instance- 1534 identifier, one based on YANG Schema Item iDentifier (SID) as defined 1535 in Section 3.2 and one based on names as defined in Section 3.3. 1537 6.13.1. SIDs as instance-identifier 1539 SIDs uniquely identify a schema node. In the case of a single 1540 instance schema node, i.e. a schema node defined at the root of a 1541 YANG module or submodule or schema nodes defined within a container, 1542 the SID is sufficient to identify this instance. 1544 In the case of a schema node member of a YANG list, a SID is combined 1545 with the list key(s) to identify each instance within the YANG 1546 list(s). 1548 Single instance schema nodes MUST be encoded using a CBOR unsigned 1549 integer data item (major type 0) and set to the targeted schema node 1550 SID. 1552 Schema nodes member of a YANG list MUST be encoded using a CBOR array 1553 data item (major type 4) containing the following entries: 1555 o The first entry MUST be encoded as a CBOR unsigned integer data 1556 item (major type 0) and set to the targeted schema node SID. 1558 o The following entries MUST contain the value of each key required 1559 to identify the instance of the targeted schema node. These keys 1560 MUST be ordered as defined in the 'key' YANG statement, starting 1561 from top level list, and follow by each of the subordinate 1562 list(s). 1564 Examples within this section assume the definition of a schema node 1565 of type 'instance-identifier': 1567 Definition example from [RFC7950]: 1569 container system { 1570 ... 1571 leaf reporting-entity { 1572 type instance-identifier; 1573 } 1575 leaf contact { type string; } 1577 leaf hostname { type inet:domain-name; } } ~~~~ 1579 *First example:* 1581 The following example shows the encoding of the 'reporting-entity' 1582 value referencing data node instance "/system/contact" (SID 1741). 1584 Definition example from [RFC7317]: 1586 container system { 1588 leaf contact { 1589 type string; 1590 } 1592 leaf hostname { 1593 type inet:domain-name; 1594 } 1595 } 1597 CBOR diagnostic notation: 1741 1599 CBOR encoding: 19 06CD 1601 *Second example:* 1603 The following example shows the encoding of the 'reporting-entity' 1604 value referencing list instance "/system/authentication/user/ 1605 authorized-key/key-data" (SID 1734) for user name "bob" and 1606 authorized-key "admin". 1608 Definition example from [RFC7317]: 1610 list user { 1611 key name; 1613 leaf name { 1614 type string; 1615 } 1616 leaf password { 1617 type ianach:crypt-hash; 1618 } 1620 list authorized-key { 1621 key name; 1623 leaf name { 1624 type string; 1625 } 1626 leaf algorithm { 1627 type string; 1628 } 1629 leaf key-data { 1630 type binary; 1631 } 1632 } 1633 CBOR diagnostic notation: [1734, "bob", "admin"] 1635 CBOR encoding: 1637 83 # array(3) 1638 19 06C6 # unsigned(1734) 1639 63 # text(3) 1640 626F62 # "bob" 1641 65 # text(5) 1642 61646D696E # "admin" 1644 *Third example:* 1646 The following example shows the encoding of the 'reporting-entity' 1647 value referencing the list instance "/system/authentication/user" 1648 (SID 1730) corresponding to user name "jack". 1650 CBOR diagnostic notation: [1730, "jack"] 1652 CBOR encoding: 1654 82 # array(2) 1655 19 06C2 # unsigned(1730) 1656 64 # text(4) 1657 6A61636B # "jack" 1659 6.13.2. Names as instance-identifier 1661 An "instance-identifier" value is encoded as a string that is 1662 analogical to the lexical representation in XML encoding; see 1663 Section 9.13.2 in [RFC7950]. However, the encoding of namespaces in 1664 instance-identifier values follows the rules stated in Section 3.3, 1665 namely: 1667 o The leftmost (top-level) data node name is always in the namespace 1668 qualified form. 1670 o Any subsequent data node name is in the namespace qualified form 1671 if the node is defined in a module other than its parent node, and 1672 the simple form is used otherwise. This rule also holds for node 1673 names appearing in predicates. 1675 For example, 1677 /ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ip 1678 is a valid instance-identifier value because the data nodes 1679 "interfaces", "interface", and "name" are defined in the module 1680 "ietf-interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". 1682 The resulting xpath MUST be encoded using a CBOR text string data 1683 item (major type 3). 1685 *First example:* 1687 This example is described in Section 6.13.1. 1689 CBOR diagnostic notation: "/ietf-system:system/contact" 1691 CBOR encoding: 1693 78 1c 2F696574662D73797374656D3A73797374656D2F636F6E74616374 1695 *Second example:* 1697 This example is described in Section 6.13.1. 1699 CBOR diagnostic notation: 1701 "/ietf-system:system/authentication/user[name='bob']/authorized-key 1702 [name='admin']/key-data" 1704 CBOR encoding: 1706 78 59 1707 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1708 74696F6E2F757365725B6E616D653D27626F62275D2F617574686F72697A 1709 65642D6B65790D0A5B6E616D653D2761646D696E275D2F6B65792D64617461 1711 *Third example:* 1713 This example is described in Section 6.13.1. 1715 CBOR diagnostic notation: 1717 "/ietf-system:system/authentication/user[name='bob']" 1719 CBOR encoding: 1721 78 33 1722 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1723 74696F6E2F757365725B6E616D653D27626F62275D 1725 7. Security Considerations 1727 The security considerations of [RFC7049] and [RFC7950] apply. 1729 This document defines an alternative encoding for data modeled in the 1730 YANG data modeling language. As such, this encoding does not 1731 contribute any new security issues in addition of those identified 1732 for the specific protocol or context for which it is used. 1734 To minimize security risks, software on the receiving side SHOULD 1735 reject all messages that do not comply to the rules of this document 1736 and reply with an appropriate error message to the sender. 1738 8. IANA Considerations 1740 8.1. CBOR Tags Registry 1742 This specification requires the assignment of CBOR tags for the 1743 following YANG datatypes. These tags are added to the CBOR Tags 1744 Registry as defined in section 7.2 of [RFC7049]. 1746 +-----+------------------+-----------------------------+-----------+ 1747 | Tag | Data Item | Semantics | Reference | 1748 +-----+------------------+-----------------------------+-----------+ 1749 | 43 | byte string | YANG bits datatype | [this] | 1750 | | | ; see Section 6.7. | | 1751 | 44 | unsigned integer | YANG enumeration datatype | [this] | 1752 | | | ;see Section 6.6. | | 1753 | 45 | unsigned integer | YANG identityref datatype | [this] | 1754 | | or text string | ; see Section 6.10. | | 1755 | 46 | unsigned integer | YANG instance-identifier | [this] | 1756 | | or text string | datatype; see Section 6.13. | [this] | 1757 | | or array | | | 1758 | 47 | unsigned integer | YANG Schema Item iDentifier | | 1759 | | | ; see Section 3.2. | [this] | 1760 +-----+------------------+-----------------------------+-----------+ 1762 // RFC Ed.: replace [this] with RFC number and remove this note 1764 9. Acknowledgments 1766 This document has been largely inspired by the extensive works done 1767 by Andy Bierman and Peter van der Stok on [I-D.ietf-core-comi]. 1768 [RFC7951] has also been a critical input to this work. The authors 1769 would like to thank the authors and contributors to these two drafts. 1771 The authors would also like to acknowledge the review, feedback, and 1772 comments from Ladislav Lhotka and Juergen Schoenwaelder. 1774 10. References 1776 10.1. Normative References 1778 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1779 Requirement Levels", BCP 14, RFC 2119, 1780 DOI 10.17487/RFC2119, March 1997, 1781 . 1783 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1784 Specifications: ABNF", STD 68, RFC 5234, 1785 DOI 10.17487/RFC5234, January 2008, 1786 . 1788 [RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed., 1789 and A. Bierman, Ed., "Network Configuration Protocol 1790 (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, 1791 . 1793 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1794 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 1795 October 2013, . 1797 [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", 1798 RFC 7950, DOI 10.17487/RFC7950, August 2016, 1799 . 1801 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1802 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1803 May 2017, . 1805 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 1806 Definition Language (CDDL): A Notational Convention to 1807 Express Concise Binary Object Representation (CBOR) and 1808 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 1809 June 2019, . 1811 10.2. Informative References 1813 [I-D.ietf-core-comi] 1814 Veillette, M., Stok, P., Pelov, A., Bierman, A., and I. 1815 Petrov, "CoAP Management Interface", draft-ietf-core- 1816 comi-08 (work in progress), September 2019. 1818 [I-D.ietf-core-sid] 1819 Veillette, M., Pelov, A., and I. Petrov, "YANG Schema Item 1820 iDentifier (SID)", draft-ietf-core-sid-11 (work in 1821 progress), March 2020. 1823 [RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for 1824 Constrained-Node Networks", RFC 7228, 1825 DOI 10.17487/RFC7228, May 2014, 1826 . 1828 [RFC7317] Bierman, A. and M. Bjorklund, "A YANG Data Model for 1829 System Management", RFC 7317, DOI 10.17487/RFC7317, August 1830 2014, . 1832 [RFC7951] Lhotka, L., "JSON Encoding of Data Modeled with YANG", 1833 RFC 7951, DOI 10.17487/RFC7951, August 2016, 1834 . 1836 [RFC8040] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF 1837 Protocol", RFC 8040, DOI 10.17487/RFC8040, January 2017, 1838 . 1840 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 1841 Interchange Format", STD 90, RFC 8259, 1842 DOI 10.17487/RFC8259, December 2017, 1843 . 1845 [RFC8343] Bjorklund, M., "A YANG Data Model for Interface 1846 Management", RFC 8343, DOI 10.17487/RFC8343, March 2018, 1847 . 1849 [RFC8344] Bjorklund, M., "A YANG Data Model for IP Management", 1850 RFC 8344, DOI 10.17487/RFC8344, March 2018, 1851 . 1853 [RFC8348] Bierman, A., Bjorklund, M., Dong, J., and D. Romascanu, "A 1854 YANG Data Model for Hardware Management", RFC 8348, 1855 DOI 10.17487/RFC8348, March 2018, 1856 . 1858 Authors' Addresses 1860 Michel Veillette (editor) 1861 Trilliant Networks Inc. 1862 610 Rue du Luxembourg 1863 Granby, Quebec J2J 2V2 1864 Canada 1866 Email: michel.veillette@trilliantinc.com 1867 Ivaylo Petrov (editor) 1868 Acklio 1869 1137A avenue des Champs Blancs 1870 Cesson-Sevigne, Bretagne 35510 1871 France 1873 Email: ivaylo@ackl.io 1875 Alexander Pelov 1876 Acklio 1877 1137A avenue des Champs Blancs 1878 Cesson-Sevigne, Bretagne 35510 1879 France 1881 Email: a@ackl.io