idnits 2.17.1 draft-ietf-core-yang-cbor-13.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 (July 04, 2020) is 1385 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 1199, but not defined -- Looks like a reference, but probably isn't: '257' on line 1199 == Missing Reference: '0-9' is mentioned on line 1549, but not defined == Missing Reference: '1-9' is mentioned on line 1540, but not defined == Missing Reference: '0-4' is mentioned on line 1549, but not defined == Missing Reference: '0-5' is mentioned on line 1549, but not defined == Missing Reference: '0-9a-fA-F' is mentioned on line 1548, but not defined -- Looks like a reference, but probably isn't: '01' on line 1549 == Unused Reference: 'RFC8348' is defined on line 1941, but no explicit reference was found in the text ** Obsolete normative reference: RFC 7049 (Obsoleted by RFC 8949) == Outdated reference: A later version (-17) exists of draft-ietf-core-comi-09 == Outdated reference: A later version (-24) exists of draft-ietf-core-sid-13 Summary: 2 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: January 5, 2021 A. Pelov 6 Acklio 7 July 04, 2020 9 CBOR Encoding of Data Modeled with YANG 10 draft-ietf-core-yang-cbor-13 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 extension 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 January 5, 2021. 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 . . . . . . . . . . . . . . . . 6 58 3.2. YANG Schema Item iDentifier . . . . . . . . . . . . . . . 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 nodes from the data tree . . . 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' extension . . . . . . . . . . . . . . 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 . . . . . . . . . . . . . . . . . 30 89 6.7. The 'bits' Type . . . . . . . . . . . . . . . . . . . . . 31 90 6.8. The 'binary' Type . . . . . . . . . . . . . . . . . . . . 33 91 6.9. The 'leafref' Type . . . . . . . . . . . . . . . . . . . 33 92 6.10. The 'identityref' Type . . . . . . . . . . . . . . . . . 34 93 6.10.1. SIDs as identityref . . . . . . . . . . . . . . . . 34 94 6.10.2. Name as identityref . . . . . . . . . . . . . . . . 35 95 6.11. The 'empty' Type . . . . . . . . . . . . . . . . . . . . 35 96 6.12. The 'union' Type . . . . . . . . . . . . . . . . . . . . 36 97 6.13. The 'instance-identifier' Type . . . . . . . . . . . . . 37 98 6.13.1. SIDs as instance-identifier . . . . . . . . . . . . 37 99 6.13.2. Names as instance-identifier . . . . . . . . . . . . 40 100 7. Content-Types . . . . . . . . . . . . . . . . . . . . . . . . 42 101 8. Security Considerations . . . . . . . . . . . . . . . . . . . 42 102 9. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 42 103 9.1. Media-Types Registry . . . . . . . . . . . . . . . . . . 42 104 9.2. CoAP Content-Formats Registry . . . . . . . . . . . . . . 43 105 9.3. CBOR Tags Registry . . . . . . . . . . . . . . . . . . . 43 106 10. Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . 43 107 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 44 108 11.1. Normative References . . . . . . . . . . . . . . . . . . 44 109 11.2. Informative References . . . . . . . . . . . . . . . . . 44 110 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 45 112 1. Introduction 114 The specification of the YANG 1.1 data modeling language [RFC7950] 115 defines an XML encoding for data instances, i.e. contents of 116 configuration datastores, state data, RPC inputs and outputs, action 117 inputs and outputs, and event notifications. 119 An additional set of encoding rules has been defined in [RFC7951] 120 based on the JavaScript Object Notation (JSON) Data Interchange 121 Format [RFC8259]. 123 The aim of this document is to define a set of encoding rules for the 124 Concise Binary Object Representation (CBOR) [RFC7049]. The resulting 125 encoding is more compact compared to XML and JSON and more suitable 126 for Constrained Nodes and/or Constrained Networks as defined by 127 [RFC7228]. 129 2. Terminology and Notation 131 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 132 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 133 "OPTIONAL" in this document are to be interpreted as described in BCP 134 14 [RFC2119] [RFC8174] when, and only when, they appear in all 135 capitals, as shown here. 137 The following terms are defined in [RFC7950]: 139 o action 141 o anydata 143 o anyxml 144 o data node 146 o data tree 148 o datastore 150 o feature 152 o identity 154 o module 156 o notification 158 o RPC 160 o schema node 162 o schema tree 164 o submodule 166 The following terms are defined in [RFC8040]: 168 o yang-data extension 170 This specification also makes use of the following terminology: 172 o child: A schema node defined as a child node of a container, a 173 list, a case, a notification, an RPC input, an RPC output, an 174 action input, an action output. 176 o delta: Difference between the current YANG SID and a reference 177 YANG SID. A reference YANG SID is defined for each context for 178 which deltas are used. 180 o item: A schema node, an identity, a module, a submodule or a 181 feature defined using the YANG modeling language. 183 o parent: The container, list, case, notification, RPC input, RPC 184 output, action input or action output node in which a schema node 185 is defined. 187 o YANG Schema Item iDentifier (YANG SID or simply SID): Unsigned 188 integer used to identify different YANG items. 190 3. Properties of the CBOR Encoding 192 This document defines CBOR encoding rules for YANG data trees and 193 their subtrees. 195 A node from the data tree such as container, list instance, 196 notification, RPC input, RPC output, action input and action output 197 is serialized using a CBOR map in which each child schema node is 198 encoded using a key and a value. This specification supports two 199 types of CBOR keys; YANG Schema Item iDentifier (YANG SID) as defined 200 in Section 3.2 and names as defined in Section 3.3. Each of these 201 key types is encoded using a specific CBOR type which allows their 202 interpretation during the deserialization process. Protocols or 203 mechanisms implementing this specification can mandate the use of a 204 specific key type. 206 In order to minimize the size of the encoded data, the proposed 207 mapping avoids any unnecessary meta-information beyond those natively 208 supported by CBOR. For instance, CBOR tags are used solely in the 209 case of SID not encoded as delta, anyxml schema nodes and the union 210 datatype to distinguish explicitly the use of different YANG 211 datatypes encoded using the same CBOR major type. 213 Unless specified otherwise by the protocol or mechanism implementing 214 this specification, the indefinite lengths encoding as defined in 215 [RFC7049] section 2.2 SHALL be supported by CBOR decoders. 217 Data nodes implemented using a CBOR array, map, byte string, and text 218 string can be instantiated but empty. In this case, they are encoded 219 with a length of zero. 221 When schema node are serialized using the rules defined by this 222 specification as part of an application payload, the payload SHOULD 223 include information that would allow a stateless way to identify each 224 node, such as the SID number associated with the node, SID delta from 225 another SID in the application payload, the namespace qualified name 226 or the instance-identifier. 228 Examples in Section 4 include a root CBOR map with a single entry 229 having a key set to either a namespace qualified name or a SID. This 230 root CBOR map is provided only as a typical usage example and is not 231 part of the present encoding rules. Only the value within this CBOR 232 map is compulsory. 234 3.1. CBOR diagnostic notation 236 Within this document, CBOR binary contents are represented using an 237 equivalent textual form called CBOR diagnostic notation as defined in 238 [RFC7049] section 6. This notation is used strictly for 239 documentation purposes and is never used in the data serialization. 240 Table 1 below provides a summary of this notation. 242 +----------+------+--------------------------+-----------+----------+ 243 | CBOR | CBOR | Diagnostic notation | Example | CBOR | 244 | content | type | | | encoding | 245 +----------+------+--------------------------+-----------+----------+ 246 | Unsigned | 0 | Decimal digits | 123 | 18 7B | 247 | integer | | | | | 248 | Negative | 1 | Decimal digits prefixed | -123 | 38 7A | 249 | integer | | by a minus sign | | | 250 | Byte | 2 | Hexadecimal value | h'F15C' | 42 F15C | 251 | string | | enclosed between single | | | 252 | | | quotes and prefixed by | | | 253 | | | an 'h' | | | 254 | Text | 3 | String of Unicode | "txt" | 63 | 255 | string | | characters enclosed | | 747874 | 256 | | | between double quotes | | | 257 | Array | 4 | Comma-separated list of | [ 1, 2 ] | 82 01 02 | 258 | | | values within square | | | 259 | | | brackets | | | 260 | Map | 5 | Comma-separated list of | { 1: 123, | A2 | 261 | | | key : value pairs within | 2: 456 } | 01187B | 262 | | | curly braces | | 021901C8 | 263 | Boolean | 7/20 | false | false | F4 | 264 | | 7/21 | true | true | F5 | 265 | Null | 7/22 | null | null | F6 | 266 | Not | 7/23 | undefined | undefined | F7 | 267 | assigned | | | | | 268 +----------+------+--------------------------+-----------+----------+ 270 Table 1: CBOR diagnostic notation summary 272 Note: CBOR binary contents shown in this specification are annotated 273 with comments. These comments are delimited by slashes ("/") as 274 defined in [RFC8610] Appendix G.6. 276 3.2. YANG Schema Item iDentifier 278 Some of the items defined in YANG [RFC7950] require the use of a 279 unique identifier. In both NETCONF [RFC6241] and RESTCONF [RFC8040], 280 these identifiers are implemented using strings. To allow the 281 implementation of data models defined in YANG in constrained devices 282 and constrained networks, a more compact method to identify YANG 283 items is required. This compact identifier, called YANG Schema Item 284 iDentifier, is an unsigned integer. The following items are 285 identified using YANG SIDs (often shortened to SIDs): 287 o identities 289 o data nodes 291 o RPCs and associated input(s) and output(s) 293 o actions and associated input(s) and output(s) 295 o notifications and associated information 297 o YANG modules, submodules and features 299 To minimize their size, SIDs used as keys in inner CBOR maps are 300 typically encoded using deltas. Conversion from SIDs to deltas and 301 back to SIDs are stateless processes solely based on the data 302 serialized or deserialized. These SIDs may also be encoded as 303 absolute number when enclosed by CBOR tag 47. 305 Mechanisms and processes used to assign SIDs to YANG items and to 306 guarantee their uniqueness are outside the scope of the present 307 specification. If SIDs are to be used, the present specification is 308 used in conjunction with a specification defining this management. 309 One example for such a specification is [I-D.ietf-core-sid]. 311 3.3. Name 313 This specification also supports the encoding of YANG item 314 identifiers as string, similar as those used by the JSON Encoding of 315 Data Modeled with YANG [RFC7951]. This approach can be used to avoid 316 the management overhead associated to SIDs allocation. The main 317 drawback is the significant increase in size of the encoded data. 319 YANG item identifiers implemented using names MUST be in one of the 320 following forms: 322 o simple - the identifier of the YANG item (i.e. schema node or 323 identity). 325 o namespace qualified - the identifier of the YANG item is prefixed 326 with the name of the module in which this item is defined, 327 separated by the colon character (":"). 329 The name of a module determines the namespace of all YANG items 330 defined in that module. If an item is defined in a submodule, then 331 the namespace qualified name uses the name of the main module to 332 which the submodule belongs. 334 ABNF syntax [RFC5234] of a name is shown in Figure 1, where the 335 production for "identifier" is defined in Section 14 of [RFC7950]. 337 name = [identifier ":"] identifier 339 Figure 1: ABNF Production for a simple or namespace qualified name 341 A namespace qualified name MUST be used for all members of a top- 342 level CBOR map and then also whenever the namespaces of the data node 343 and its parent node are different. In all other cases, the simple 344 form of the name SHOULD be used. 346 Definition example: 348 module example-foomod { 349 container top { 350 leaf foo { 351 type uint8; 352 } 353 } 354 } 356 module example-barmod { 357 import example-foomod { 358 prefix "foomod"; 359 } 360 augment "/foomod:top" { 361 leaf bar { 362 type boolean; 363 } 364 } 365 } 367 A valid CBOR encoding of the 'top' container is as follows. 369 CBOR diagnostic notation: 371 { 372 "example-foomod:top": { 373 "foo": 54, 374 "example-barmod:bar": true 375 } 376 } 377 Both the 'top' container and the 'bar' leaf defined in a different 378 YANG module as its parent container are encoded as namespace 379 qualified names. The 'foo' leaf defined in the same YANG module as 380 its parent container is encoded as simple name. 382 4. Encoding of YANG Schema Node Instances 384 Schema node instances defined using the YANG modeling language are 385 encoded using CBOR [RFC7049] based on the rules defined in this 386 section. We assume that the reader is already familiar with both 387 YANG [RFC7950] and CBOR [RFC7049]. 389 4.1. The 'leaf' 391 A 'leaf' MUST be encoded accordingly to its datatype using one of the 392 encoding rules specified in Section 6. 394 The following examples shows the encoding of a 'hostname' leaf using 395 a SID or a name. 397 Definition example from [RFC7317]: 399 leaf hostname { 400 type inet:domain-name; 401 } 403 4.1.1. Using SIDs in keys 405 CBOR diagnostic notation: 407 { 408 1752 : "myhost.example.com" / hostname (SID 1752) / 409 } 411 CBOR encoding: 413 A1 # map(1) 414 19 06D8 # unsigned(1752) 415 72 # text(18) 416 6D79686F73742E6578616D706C652E636F6D # "myhost.example.com" 418 4.1.2. Using names in keys 420 CBOR diagnostic notation: 422 { 423 "ietf-system:hostname" : "myhost.example.com" 424 } 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 nodes from the data tree 435 Containers, list instances, notification contents, rpc inputs, rpc 436 outputs, action inputs and action outputs MUST be encoded using a 437 CBOR map data item (major type 5). A map is comprised of pairs of 438 data items, with each data item consisting of a key and a value. 439 Each key within the CBOR map is set to a schema node identifier, each 440 value is set to the value of this schema node instance according to 441 the instance datatype. 443 This specification supports two types 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 nodes from the data tree, CBOR 474 map keys within inner CBOR maps can be encoded using deltas or SIDs. 475 In the case of deltas, they MUST be encoded using a CBOR unsigned 476 integer (major type 0) or CBOR negative integer (major type 1), 477 depending on the actual delta value. In the case of SID, they are 478 encoded using the SID value enclosed by CBOR tag 47 as defined in 479 Section 9.3. 481 Delta values are computed as follows: 483 o In the case of a 'container', deltas are equal to the SID of the 484 current schema node minus the SID of the parent 'container'. 486 o In the case of a 'list', deltas are equal to the SID of the 487 current schema node minus the SID of the parent 'list'. 489 o In the case of an 'rpc input' or 'rcp output', deltas are equal to 490 the SID of the current schema node minus the SID of the 'rpc'. 492 o In the case of an 'action input' or 'action output', deltas are 493 equal to the SID of the current schema node minus the SID of the 494 'action'. 496 o In the case of an 'notification content', deltas are equal to the 497 SID of the current schema node minus the SID of the 498 'notification'. 500 CBOR diagnostic notation: 502 { 503 1720 : { / system-state (SID 1720) / 504 1 : { / clock (SID 1721) / 505 2 : "2015-10-02T14:47:24Z-05:00", / current-datetime(SID 1723)/ 506 1 : "2015-09-15T09:12:58Z-05:00" / boot-datetime (SID 1722) / 507 } 508 } 509 } 511 CBOR encoding: 513 A1 # map(1) 514 19 06B8 # unsigned(1720) 515 A1 # map(1) 516 01 # unsigned(1) 517 A2 # map(2) 518 02 # unsigned(2) 519 78 1A # text(26) 520 323031352D31302D30325431343A34373A32345A2D30353A3030 521 01 # unsigned(1) 522 78 1A # text(26) 523 323031352D30392D31355430393A31323A35385A2D30353A3030 525 Figure 2: System state clock encoding 527 4.2.2. Using names in keys 529 CBOR map keys implemented using names MUST be encoded using a CBOR 530 text string data item (major type 3). A namespace-qualified name 531 MUST be used each time the namespace of a schema node and its parent 532 differ. In all other cases, the simple form of the name MUST be 533 used. Names and namespaces are defined in [RFC7951] section 4. 535 The following example shows the encoding of a 'system' container 536 instance using names. 538 Definition example from [RFC7317]: 540 typedef date-and-time { 541 type string { 542 pattern '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|[\+\-] 543 \d{2}:\d{2})'; 544 } 545 } 547 container system-state { 549 container clock { 550 leaf current-datetime { 551 type date-and-time; 552 } 554 leaf boot-datetime { 555 type date-and-time; 556 } 557 } 558 } 560 CBOR diagnostic notation: 562 { 563 "ietf-system:system-state" : { 564 "clock" : { 565 "current-datetime" : "2015-10-02T14:47:24Z-05:00", 566 "boot-datetime" : "2015-09-15T09:12:58Z-05:00" 567 } 568 } 569 } 571 CBOR encoding: 573 A1 # map(1) 574 78 18 # text(24) 575 696574662D73797374656D3A73797374656D2D7374617465 576 A1 # map(1) 577 65 # text(5) 578 636C6F636B # "clock" 579 A2 # map(2) 580 70 # text(16) 581 63757272656E742D6461746574696D65 582 78 1A # text(26) 583 323031352D31302D30325431343A34373A32345A2D30353A3030 584 6D # text(13) 585 626F6F742D6461746574696D65 586 78 1A # text(26) 587 323031352D30392D31355430393A31323A35385A2D30353A3030 589 4.3. The 'leaf-list' 591 A leaf-list MUST be encoded using a CBOR array data item (major type 592 4). Each entry of this array MUST be encoded accordingly to its 593 datatype using one of the encoding rules specified in Section 6. 595 The following example shows the encoding of the 'search' leaf-list 596 instance containing two entries, "ietf.org" and "ieee.org". 598 Definition example [RFC7317]: 600 typedef domain-name { 601 type string { 602 length "1..253"; 603 pattern '((([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9].) 604 *([a-zA-Z0-9_]([a-zA-Z0-9\-_]){0,61})?[a-zA-Z0-9]\.? 605 )|\.'; 606 } 607 } 609 leaf-list search { 610 type domain-name; 611 ordered-by user; 612 } 614 4.3.1. Using SIDs in keys 616 CBOR diagnostic notation: 618 { 619 1746 : [ "ietf.org", "ieee.org" ] / search (SID 1746) / 620 } 622 CBOR encoding: 624 A1 # map(1) 625 19 06D2 # unsigned(1746) 626 82 # array(2) 627 68 # text(8) 628 696574662E6F7267 # "ietf.org" 629 68 # text(8) 630 696565652E6F7267 # "ieee.org" 632 4.3.2. Using names in keys 634 CBOR diagnostic notation: 636 { 637 "ietf-system:search" : [ "ietf.org", "ieee.org" ] 638 } 640 CBOR encoding: 642 A1 # map(1) 643 72 # text(18) 644 696574662D73797374656D3A736561726368 # "ietf-system:search" 645 82 # array(2) 646 68 # text(8) 647 696574662E6F7267 # "ietf.org" 648 68 # text(8) 649 696565652E6F7267 # "ieee.org" 651 4.4. The 'list' and 'list' instance(s) 653 A list or a subset of a list MUST be encoded using a CBOR array data 654 item (major type 4). Each list instance within this CBOR array is 655 encoded using a CBOR map data item (major type 5) based on the 656 encoding rules of a collection as defined in Section 4.2. 658 It is important to note that this encoding rule also apply to a 659 single 'list' instance. 661 The following examples show the encoding of a 'server' list using 662 SIDs or names. 664 Definition example from [RFC7317]: 666 list server { 667 key name; 669 leaf name { 670 type string; 671 } 672 choice transport { 673 case udp { 674 container udp { 675 leaf address { 676 type host; 677 mandatory true; 678 } 679 leaf port { 680 type port-number; 681 } 682 } 683 } 684 } 685 leaf association-type { 686 type enumeration { 687 enum server; 688 enum peer; 689 enum pool; 690 } 691 default server; 692 } 693 leaf iburst { 694 type boolean; 695 default false; 696 } 697 leaf prefer { 698 type boolean; 699 default false; 700 } 701 } 703 4.4.1. Using SIDs in keys 705 The encoding rules of each 'list' instance are defined in 706 Section 4.2.1. Deltas of list members are equal to the SID of the 707 current schema node minus the SID of the 'list'. 709 CBOR diagnostic notation: 711 { 712 1756 : [ / server (SID 1756) / 713 { 714 3 : "NRC TIC server", / name (SID 1759) / 715 5 : { / udp (SID 1761) / 716 1 : "tic.nrc.ca", / address (SID 1762) / 717 2 : 123 / port (SID 1763) / 718 }, 719 1 : 0, / association-type (SID 1757) / 720 2 : false, / iburst (SID 1758) / 721 4 : true / prefer (SID 1760) / 722 }, 723 { 724 3 : "NRC TAC server", / name (SID 1759) / 725 5 : { / udp (SID 1761) / 726 1 : "tac.nrc.ca" / address (SID 1762) / 727 } 728 } 729 ] 730 } 732 CBOR encoding: 734 A1 # map(1) 735 19 06DC # unsigned(1756) 736 82 # array(2) 737 A5 # map(5) 738 03 # unsigned(3) 739 6E # text(14) 740 4E52432054494320736572766572 # "NRC TIC server" 741 05 # unsigned(5) 742 A2 # map(2) 743 01 # unsigned(1) 744 6A # text(10) 745 7469632E6E72632E6361 # "tic.nrc.ca" 746 02 # unsigned(2) 747 18 7B # unsigned(123) 748 01 # unsigned(1) 749 00 # unsigned(0) 750 02 # unsigned(2) 751 F4 # primitive(20) 752 04 # unsigned(4) 753 F5 # primitive(21) 754 A2 # map(2) 755 03 # unsigned(3) 756 6E # text(14) 757 4E52432054414320736572766572 # "NRC TAC server" 758 05 # unsigned(5) 759 A1 # map(1) 760 01 # unsigned(1) 761 6A # text(10) 762 7461632E6E72632E6361 # "tac.nrc.ca" 764 4.4.2. Using names in keys 766 The encoding rules of each 'list' instance are defined in 767 Section 4.2.2. 769 CBOR diagnostic notation: 771 { 772 "ietf-system:server" : [ 773 { 774 "name" : "NRC TIC server", 775 "udp" : { 776 "address" : "tic.nrc.ca", 777 "port" : 123 778 }, 779 "association-type" : 0, 780 "iburst" : false, 781 "prefer" : true 782 }, 783 { 784 "name" : "NRC TAC server", 785 "udp" : { 786 "address" : "tac.nrc.ca" 787 } 788 } 789 ] 790 } 792 CBOR encoding: 794 A1 # map(1) 795 72 # text(18) 796 696574662D73797374656D3A736572766572 797 82 # array(2) 798 A5 # map(5) 799 64 # text(4) 800 6E616D65 # "name" 801 6E # text(14) 802 4E52432054494320736572766572 803 63 # text(3) 804 756470 # "udp" 805 A2 # map(2) 806 67 # text(7) 807 61646472657373 # "address" 808 6A # text(10) 809 7469632E6E72632E6361 # "tic.nrc.ca" 810 64 # text(4) 811 706F7274 # "port" 812 18 7B # unsigned(123) 813 70 # text(16) 814 6173736F63696174696F6E2D74797065 815 00 # unsigned(0) 816 66 # text(6) 817 696275727374 # "iburst" 818 F4 # primitive(20) 819 66 # text(6) 820 707265666572 # "prefer" 821 F5 # primitive(21) 822 A2 # map(2) 823 64 # text(4) 824 6E616D65 # "name" 825 6E # text(14) 826 4E52432054414320736572766572 827 63 # text(3) 828 756470 # "udp" 829 A1 # map(1) 830 67 # text(7) 831 61646472657373 # "address" 832 6A # text(10) 833 7461632E6E72632E6361 # "tac.nrc.ca" 835 4.5. The 'anydata' 837 An anydata serves as a container for an arbitrary set of schema nodes 838 that otherwise appear as normal YANG-modeled data. An anydata 839 instance is encoded using the same rules as a container, i.e., CBOR 840 map. The requirement that anydata content can be modeled by YANG 841 implies the following: 843 o CBOR map keys of any inner schema nodes MUST be set to valid 844 deltas or names. 846 o The CBOR array MUST contain either unique scalar values (as a 847 leaf-list, see Section 4.3), or maps (as a list, see Section 4.4). 849 o CBOR map values MUST follow the encoding rules of one of the 850 datatypes listed in Section 4. 852 The following example shows a possible use of an anydata. In this 853 example, an anydata is used to define a schema node containing a 854 notification event, this schema node can be part of a YANG list to 855 create an event logger. 857 Definition example: 859 module event-log { 860 ... 861 anydata last-event; # SID 60123 863 This example also assumes the assistance of the following 864 notification. 866 module example-port { 867 ... 869 notification example-port-fault { # SID 60200 870 leaf port-name { # SID 60201 871 type string; 872 } 873 leaf port-fault { # SID 60202 874 type string; 875 } 876 } 877 } 879 4.5.1. Using SIDs in keys 881 CBOR diagnostic notation: 883 { 884 60123 : { / last-event (SID 60123) / 885 77 : { / example-port-fault (SID 60200) / 886 1 : "0/4/21", / port-name (SID 60201) / 887 2 : "Open pin 2" / port-fault (SID 60202) / 888 } 889 } 890 } 891 CBOR encoding: 893 A1 # map(1) 894 19 EADB # unsigned(60123) 895 A1 # map(1) 896 18 4D # unsigned(77) 897 A2 # map(2) 898 18 4E # unsigned(78) 899 66 # text(6) 900 302F342F3231 # "0/4/21" 901 18 4F # unsigned(79) 902 6A # text(10) 903 4F70656E2070696E2032 # "Open pin 2" 905 In some implementations, it might be simpler to use the absolute SID 906 tag encoding for the anydata root element. The resulting encoding is 907 as follows: 909 { 910 60123 : { / last-event (SID 60123) / 911 47(60200) : { / event-port-fault (SID 60200) / 912 1 : "0/4/21", / port-name (SID 60201) / 913 2 : "Open pin 2" / port-fault (SID 60202) / 914 } 915 } 916 } 918 4.5.2. Using names in keys 920 CBOR diagnostic notation: 922 { 923 "event-log:last-event" : { 924 "example-port:example-port-fault" : { 925 "port-name" : "0/4/21", 926 "port-fault" : "Open pin 2" 927 } 928 } 929 } 931 CBOR encoding: 933 A1 # map(1) 934 74 # text(20) 935 6576656E742D6C6F673A6C6173742D6576656E74 936 A1 # map(1) 937 78 20 # text(32) 938 6578616D706C652D706F72743A206578616D7 939 06C652D706F72742D6661756C74 940 A2 # map(2) 941 69 # text(9) 942 706F72742D6E616D65 # "port-name" 943 66 # text(6) 944 302F342F3231 # "0/4/21" 945 6A # text(10) 946 706F72742D6661756C74 # "port-fault" 947 6A # text(10) 948 4F70656E2070696E2032 # "Open pin 2" 950 4.6. The 'anyxml' 952 An anyxml schema node is used to serialize an arbitrary CBOR content, 953 i.e., its value can be any CBOR binary object. anyxml value MAY 954 contain CBOR data items tagged with one of the tags listed in 955 Section 9.3, these tags shall be supported. 957 The following example shows a valid CBOR encoded instance consisting 958 of a CBOR array containing the CBOR simple values 'true', 'null' and 959 'true'. 961 Definition example from [RFC7951]: 963 module bar-module { 964 ... 965 anyxml bar; # SID 60000 967 4.6.1. Using SIDs in keys 969 CBOR diagnostic notation: 971 { 972 60000 : [true, null, true] / bar (SID 60000) / 973 } 975 CBOR encoding: 977 A1 # map(1) 978 19 EA60 # unsigned(60000) 979 83 # array(3) 980 F5 # primitive(21) 981 F6 # primitive(22) 982 F5 # primitive(21) 984 4.6.2. Using names in keys 986 CBOR diagnostic notation: 988 { 989 "bar-module:bar" : [true, null, true] / bar (SID 60000) / 990 } 992 CBOR encoding: 994 A1 # map(1) 995 6E # text(14) 996 6261722D6D6F64756C653A626172 # "bar-module:bar" 997 83 # array(3) 998 F5 # primitive(21) 999 F6 # primitive(22) 1000 F5 # primitive(21) 1002 5. Encoding of 'yang-data' extension 1004 The yang-data extension [RFC8040] is used to define data structures 1005 in YANG that are not intended to be implemented as part of a 1006 datastore. 1008 The yang-data extension MUST be encoded using the encoding rules of 1009 nodes of data trees as defined in Section 4.2. 1011 Just like YANG containers, yang-data extension can be encoded using 1012 either SIDs or names. 1014 Definition example from [I-D.ietf-core-comi] Appendix A: 1016 module ietf-coreconf { 1017 ... 1019 import ietf-restconf { 1020 prefix rc; 1021 } 1023 rc:yang-data yang-errors { 1024 container error { 1025 leaf error-tag { 1026 type identityref { 1027 base error-tag; 1028 } 1029 } 1030 leaf error-app-tag { 1031 type identityref { 1032 base error-app-tag; 1033 } 1034 } 1035 leaf error-data-node { 1036 type instance-identifier; 1037 } 1038 leaf error-message { 1039 type string; 1040 } 1041 } 1042 } 1043 } 1045 5.1. Using SIDs in keys 1047 The yang-data extensions encoded using SIDs are carried in a CBOR map 1048 containing a single item pair. The key of this item is set to the 1049 SID assigned to the yang-data extension container, the value is set 1050 the CBOR encoding of this container as defined in Section 4.2. 1052 This example shows a serialization example of the yang-errors yang- 1053 data extension as defined in [I-D.ietf-core-comi] using SIDs as 1054 defined in Section 3.2. 1056 CBOR diagnostic notation: 1058 { 1059 1024 : { / error (SID 1024) / 1060 4 : 1011, / error-tag (SID 1028) / 1061 / = invalid-value (SID 1011) / 1062 1 : 1018, / error-app-tag (SID 1025) / 1063 / = not-in-range (SID 1018) / 1064 2 : 1740, / error-data-node (SID 1026) / 1065 / = timezone-utc-offset (SID 1740) / 1066 3 : "Maximum exceeded" / error-message (SID 1027) / 1067 } 1068 } 1070 CBOR encoding: 1072 A1 # map(1) 1073 19 0400 # unsigned(1024) 1074 A4 # map(4) 1075 04 # unsigned(4) 1076 19 03F3 # unsigned(1011) 1077 01 # unsigned(1) 1078 19 03FA # unsigned(1018) 1079 02 # unsigned(2) 1080 19 06CC # unsigned(1740) 1081 03 # unsigned(3) 1082 70 # text(16) 1083 4D6178696D756D206578636565646564 1085 5.2. Using names in keys 1087 The yang-data extensions encoded using names are carried in a CBOR 1088 map containing a single item pair. The key of this item is set to 1089 the namespace qualified name of the yang-data extension container, 1090 the value is set the CBOR encoding of this container as defined in 1091 Section 3.3. 1093 This example shows a serialization example of the yang-errors yang- 1094 data extension as defined in [I-D.ietf-core-comi] using names as 1095 defined Section 3.3. 1097 CBOR diagnostic notation: 1099 { 1100 "ietf-coreconf:error" : { 1101 "error-tag" : "invalid-value", 1102 "error-app-tag" : "not-in-range", 1103 "error-data-node" : "timezone-utc-offset", 1104 "error-message" : "Maximum exceeded" 1105 } 1106 } 1108 CBOR encoding: 1110 A1 # map(1) 1111 73 # text(19) 1112 696574662D636F7265636F6E663A6572726F72 # "ietf-coreconf:error" 1113 A4 # map(4) 1114 69 # text(9) 1115 6572726F722D746167 # "error-tag" 1116 6D # text(13) 1117 696E76616C69642D76616C7565 # "invalid-value" 1118 6D # text(13) 1119 6572726F722D6170702D746167 # "error-app-tag" 1120 6C # text(12) 1121 6E6F742D696E2D72616E6765 # "not-in-range" 1122 6F # text(15) 1123 6572726F722D646174612D6E6F6465 # "error-data-node" 1124 73 # text(19) 1125 74696D657A6F6E652D7574632D6F6666736574 1126 # "timezone-utc-offset" 1127 6D # text(13) 1128 6572726F722D6D657373616765 # "error-message" 1129 70 # text(16) 1130 4D6178696D756D206578636565646564 1132 6. Representing YANG Data Types in CBOR 1134 The CBOR encoding of an instance of a leaf or leaf-list schema node 1135 depends on the built-in type of that schema node. The following sub- 1136 section defines the CBOR encoding of each built-in type supported by 1137 YANG as listed in [RFC7950] section 4.2.4. Each subsection shows an 1138 example value assigned to a schema node instance of the discussed 1139 built-in type. 1141 6.1. The unsigned integer Types 1143 Leafs of type uint8, uint16, uint32 and uint64 MUST be encoded using 1144 a CBOR unsigned integer data item (major type 0). 1146 The following example shows the encoding of a 'mtu' leaf instance set 1147 to 1280 bytes. 1149 Definition example from [RFC8344]: 1151 leaf mtu { 1152 type uint16 { 1153 range "68..max"; 1154 } 1155 } 1157 CBOR diagnostic notation: 1280 1159 CBOR encoding: 19 0500 1161 6.2. The integer Types 1163 Leafs of type int8, int16, int32 and int64 MUST be encoded using 1164 either CBOR unsigned integer (major type 0) or CBOR negative integer 1165 (major type 1), depending on the actual value. 1167 The following example shows the encoding of a 'timezone-utc-offset' 1168 leaf instance set to -300 minutes. 1170 Definition example from [RFC7317]: 1172 leaf timezone-utc-offset { 1173 type int16 { 1174 range "-1500 .. 1500"; 1175 } 1176 } 1178 CBOR diagnostic notation: -300 1180 CBOR encoding: 39 012B 1182 6.3. The 'decimal64' Type 1184 Leafs of type decimal64 MUST be encoded using a decimal fraction as 1185 defined in [RFC7049] section 2.4.3. 1187 The following example shows the encoding of a 'my-decimal' leaf 1188 instance set to 2.57. 1190 Definition example from [RFC7317]: 1192 leaf my-decimal { 1193 type decimal64 { 1194 fraction-digits 2; 1195 range "1 .. 3.14 | 10 | 20..max"; 1196 } 1197 } 1199 CBOR diagnostic notation: 4([-2, 257]) 1201 CBOR encoding: C4 82 21 19 0101 1203 6.4. The 'string' Type 1205 Leafs of type string MUST be encoded using a CBOR text string data 1206 item (major type 3). 1208 The following example shows the encoding of a 'name' leaf instance 1209 set to "eth0". 1211 Definition example from [RFC8343]: 1213 leaf name { 1214 type string; 1215 } 1217 CBOR diagnostic notation: "eth0" 1219 CBOR encoding: 64 65746830 1221 6.5. The 'boolean' Type 1223 Leafs of type boolean MUST be encoded using a CBOR simple value 1224 'true' (major type 7, additional information 21) or 'false' (major 1225 type 7, additional information 20). 1227 The following example shows the encoding of an 'enabled' leaf 1228 instance set to 'true'. 1230 Definition example from [RFC7317]: 1232 leaf enabled { 1233 type boolean; 1234 } 1236 CBOR diagnostic notation: true 1238 CBOR encoding: F5 1240 6.6. The 'enumeration' Type 1242 Leafs of type enumeration MUST be encoded using a CBOR unsigned 1243 integer (major type 0) or CBOR negative integer (major type 1), 1244 depending on the actual value. Enumeration values are either 1245 explicitly assigned using the YANG statement 'value' or automatically 1246 assigned based on the algorithm defined in [RFC7950] section 9.6.4.2. 1248 The following example shows the encoding of an 'oper-status' leaf 1249 instance set to 'testing'. 1251 Definition example from [RFC7317]: 1253 leaf oper-status { 1254 type enumeration { 1255 enum up { value 1; } 1256 enum down { value 2; } 1257 enum testing { value 3; } 1258 enum unknown { value 4; } 1259 enum dormant { value 5; } 1260 enum not-present { value 6; } 1261 enum lower-layer-down { value 7; } 1262 } 1263 } 1265 CBOR diagnostic notation: 3 1267 CBOR encoding: 03 1269 Values of 'enumeration' types defined in a 'union' type MUST be 1270 encoded using a CBOR text string data item (major type 3) and MUST 1271 contain one of the names assigned by 'enum' statements in YANG. The 1272 encoding MUST be enclosed by the enumeration CBOR tag as specified in 1273 Section 9.3. 1275 Definition example from [RFC7950]: 1277 type union { 1278 type int32; 1279 type enumeration { 1280 enum unbounded; 1281 } 1282 } 1284 CBOR diagnostic notation: 44("unbounded") 1286 CBOR encoding: D8 2C 69 756E626F756E646564 1288 6.7. The 'bits' Type 1290 Keeping in mind that bit positions are either explicitly assigned 1291 using the YANG statement 'position' or automatically assigned based 1292 on the algorithm defined in [RFC7950] section 9.7.4.2, each element 1293 of type bits could be seen as a set of bit positions (or offsets from 1294 position 0), that have a value of ether 1, which represents the bit 1295 being set or 0, which represents that the bit is not set. 1297 Leafs of type bits MUST be encoded either using a CBOR array or byte 1298 string (major type 2). In case CBOR array representation is used, 1299 each element is either a positive integer (major type 0 with value 0 1300 being disallowed) that can be used to calculate the offset of the 1301 next byte string, or a byte string (major type 2) that carries the 1302 information whether certain bits are set or not. The initial offset 1303 value is 0 and each unsigned integer modifies the offset value of the 1304 next byte string by the integer value multiplied by 8. For example, 1305 if the bit offset is 0 and there is an integer with value 5, the 1306 first byte of the byte string that follows will represent bit 1307 positions 40 to 47 both ends included. If the byte string has a 1308 second byte, it will carry information about bits 48 to 55 and so on. 1309 Within each byte, bits are assigned from least to most significant. 1310 After the byte string, the offset is modified by the number of bytes 1311 in the byte string multiplied by 8. Bytes with no bits set at the 1312 end of the byte string are removed. An example follows. 1314 The following example shows the encoding of an 'alarm-state' leaf 1315 instance with the 'critical', 'warning' and 'indeterminate' flags 1316 set. 1318 typedef alarm-state { 1319 type bits { 1320 bit unknown; 1321 bit under-repair; 1322 bit critical; 1323 bit major; 1324 bit minor; 1325 bit warning { 1326 position 8; 1327 } 1328 bit indeterminate { 1329 position 128; 1330 } 1331 } 1332 } 1334 leaf alarm-state { 1335 type alarm-state; 1336 } 1338 CBOR diagnostic notation: [h'0401', 14, h'01'] 1340 CBOR encoding: 83 42 0401 0E 41 01 1342 In a number of cases the array would only need to have one element - 1343 a byte string with a small number of bytes inside. For this case, it 1344 is expected to omit the array element and have only the byte array 1345 that would have been inside. To illustrate this, let us consider the 1346 same example yang definition, but this time encoding only 'under- 1347 repair' and 'critical' flags. The result would be 1349 CBOR diagnostic notation: h'06' 1351 CBOR encoding: 41 06 1353 Elements in the array MUST be either byte strings or positive 1354 unsigned integers, where byte strings and integers MUST alternate, 1355 i.e., adjacent byte strings or adjacent integers are an error. An 1356 array with a single byte string MUST instead by encoded as just that 1357 byte string. An array with a single positive integer is an error. 1359 Values of 'bit' types defined in a 'union' type MUST be encoded using 1360 a CBOR text string data item (major type 3) and MUST contain a space- 1361 separated sequence of names of 'bit' that are set. The encoding MUST 1362 be enclosed by the bits CBOR tag as specified in Section 9.3. 1364 The following example shows the encoding of an 'alarm-state' leaf 1365 instance defined using a union type with the 'under-repair' and 1366 'critical' flags set. 1368 Definition example: 1370 leaf alarm-state-2 { 1371 type union { 1372 type alarm-state; 1373 type bits { 1374 bit extra-flag; 1375 } 1376 } 1377 } 1379 CBOR diagnostic notation: 43("under-repair critical") 1381 CBOR encoding: D8 2B 75 756E6465722D72657061697220637269746963616C 1383 6.8. The 'binary' Type 1385 Leafs of type binary MUST be encoded using a CBOR byte string data 1386 item (major type 2). 1388 The following example shows the encoding of an 'aes128-key' leaf 1389 instance set to 0x1f1ce6a3f42660d888d92a4d8030476e. 1391 Definition example: 1393 leaf aes128-key { 1394 type binary { 1395 length 16; 1396 } 1397 } 1399 CBOR diagnostic notation: h'1F1CE6A3F42660D888D92A4D8030476E' 1401 CBOR encoding: 50 1F1CE6A3F42660D888D92A4D8030476E 1403 6.9. The 'leafref' Type 1405 Leafs of type leafref MUST be encoded using the rules of the schema 1406 node referenced by the 'path' YANG statement. 1408 The following example shows the encoding of an 'interface-state-ref' 1409 leaf instance set to "eth1". 1411 Definition example from [RFC8343]: 1413 typedef interface-state-ref { 1414 type leafref { 1415 path "/interfaces-state/interface/name"; 1416 } 1417 } 1419 container interfaces-state { 1420 list interface { 1421 key "name"; 1422 leaf name { 1423 type string; 1424 } 1425 leaf-list higher-layer-if { 1426 type interface-state-ref; 1427 } 1428 } 1429 } 1431 CBOR diagnostic notation: "eth1" 1433 CBOR encoding: 64 65746831 1435 6.10. The 'identityref' Type 1437 This specification supports two approaches for encoding identityref, 1438 a YANG Schema Item iDentifier as defined in Section 3.2 or a name as 1439 defined in [RFC7951] section 6.8. 1441 6.10.1. SIDs as identityref 1443 When schema nodes of type identityref are implemented using SIDs, 1444 they MUST be encoded using a CBOR unsigned integer data item (major 1445 type 0). (Note that no delta mechanism is employed for SIDs as 1446 identityref.) 1448 The following example shows the encoding of a 'type' leaf instance 1449 set to the value 'iana-if-type:ethernetCsmacd' (SID 1880). 1451 Definition example from [RFC7317]: 1453 identity interface-type { 1454 } 1456 identity iana-interface-type { 1457 base interface-type; 1458 } 1460 identity ethernetCsmacd { 1461 base iana-interface-type; 1462 } 1464 leaf type { 1465 type identityref { 1466 base interface-type; 1467 } 1468 } 1470 CBOR diagnostic notation: 1880 1472 CBOR encoding: 19 0758 1474 6.10.2. Name as identityref 1476 Alternatively, an identityref MAY be encoded using a name as defined 1477 in Section 3.3. When names are used, identityref MUST be encoded 1478 using a CBOR text string data item (major type 3). If the identity 1479 is defined in different module than the leaf node containing the 1480 identityref data node, the namespace qualified form MUST be used. 1481 Otherwise, both the simple and namespace qualified forms are 1482 permitted. Names and namespaces are defined in Section 3.3. 1484 The following example shows the encoding of the identity 'iana-if- 1485 type:ethernetCsmacd' using its namespace qualified name. This 1486 example is described in Section 6.10.1. 1488 CBOR diagnostic notation: "iana-if-type:ethernetCsmacd" 1490 CBOR encoding: 78 1b 1491 69616E612D69662D747970653A65746865726E657443736D616364 1493 6.11. The 'empty' Type 1495 Leafs of type empty MUST be encoded using the CBOR null value (major 1496 type 7, additional information 22). 1498 The following example shows the encoding of a 'is-router' leaf 1499 instance when present. 1501 Definition example from [RFC8344]: 1503 leaf is-router { 1504 type empty; 1505 } 1507 CBOR diagnostic notation: null 1509 CBOR encoding: F6 1511 6.12. The 'union' Type 1513 Leafs of type union MUST be encoded using the rules associated with 1514 one of the types listed. When used in a union, the following YANG 1515 datatypes are enclosed by a CBOR tag to avoid confusion between 1516 different YANG datatypes encoded using the same CBOR major type. 1518 o bits 1520 o enumeration 1522 o identityref 1524 o instance-identifier 1526 See Section 9.3 for the assigned value of these CBOR tags. 1528 As mentioned in Section 6.6 and in Section 6.7, 'enumeration' and 1529 'bits' are encoded as CBOR text string data item (major type 3) when 1530 defined within a 'union' type. 1532 The following example shows the encoding of an 'ip-address' leaf 1533 instance when set to "2001:db8:a0b:12f0::1". 1535 Definition example from [RFC7317]: 1537 typedef ipv4-address { 1538 type string { 1539 pattern '(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3} 1540 ([0-9][1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\p{N} 1541 \p{L}]+)?'; 1542 } 1543 } 1545 typedef ipv6-address { 1546 type string { 1547 pattern '((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a 1548 -fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0 1549 -9]|[01]?[0-9]?[0-9])\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0 1550 -9]?[0-9])))(%[\p{N}\p{L}]+)?'; 1551 pattern '(([^:]+:){6}(([^:]+:[^:]+)|(.*\..*)))|((([^:]+:)*[^:]+) 1552 ?::(([^:]+:)*[^:]+)?)(%.+)?'; 1553 } 1554 } 1556 typedef ip-address { 1557 type union { 1558 type ipv4-address; 1559 type ipv6-address; 1560 } 1561 } 1563 leaf address { 1564 type inet:ip-address; 1565 } 1567 CBOR diagnostic notation: "2001:db8:a0b:12f0::1" 1569 CBOR encoding: 74 323030313A6462383A6130623A313266303A3A31 1571 6.13. The 'instance-identifier' Type 1573 This specification supports two approaches for encoding an instance- 1574 identifier, one based on YANG Schema Item iDentifier as defined in 1575 Section 3.2 and one based on names as defined in Section 3.3. 1577 6.13.1. SIDs as instance-identifier 1579 SIDs uniquely identify a schema node. In the case of a single 1580 instance schema node, i.e. a schema node defined at the root of a 1581 YANG module or submodule or schema nodes defined within a container, 1582 the SID is sufficient to identify this instance. 1584 In the case of a schema node member of a YANG list, a SID is combined 1585 with the list key(s) to identify each instance within the YANG 1586 list(s). 1588 Single instance schema nodes MUST be encoded using a CBOR unsigned 1589 integer data item (major type 0) and set to the targeted schema node 1590 SID. 1592 Schema nodes member of a YANG list MUST be encoded using a CBOR array 1593 data item (major type 4) containing the following entries: 1595 o The first entry MUST be encoded as a CBOR unsigned integer data 1596 item (major type 0) and set to the targeted schema node SID. 1598 o The following entries MUST contain the value of each key required 1599 to identify the instance of the targeted schema node. These keys 1600 MUST be ordered as defined in the 'key' YANG statement, starting 1601 from top level list, and follow by each of the subordinate 1602 list(s). 1604 Examples within this section assume the definition of a schema node 1605 of type 'instance-identifier': 1607 Definition example from [RFC7950]: 1609 container system { 1610 ... 1611 leaf reporting-entity { 1612 type instance-identifier; 1613 } 1615 leaf contact { type string; } 1617 leaf hostname { type inet:domain-name; } } ~~~~ 1619 *First example:* 1621 The following example shows the encoding of the 'reporting-entity' 1622 value referencing data node instance "/system/contact" (SID 1741). 1624 Definition example from [RFC7317]: 1626 container system { 1628 leaf contact { 1629 type string; 1630 } 1632 leaf hostname { 1633 type inet:domain-name; 1634 } 1635 } 1637 CBOR diagnostic notation: 1741 1639 CBOR encoding: 19 06CD 1641 *Second example:* 1643 The following example shows the encoding of the 'reporting-entity' 1644 value referencing list instance "/system/authentication/user/ 1645 authorized-key/key-data" (SID 1734) for user name "bob" and 1646 authorized-key "admin". 1648 Definition example from [RFC7317]: 1650 list user { 1651 key name; 1653 leaf name { 1654 type string; 1655 } 1656 leaf password { 1657 type ianach:crypt-hash; 1658 } 1660 list authorized-key { 1661 key name; 1663 leaf name { 1664 type string; 1665 } 1666 leaf algorithm { 1667 type string; 1668 } 1669 leaf key-data { 1670 type binary; 1671 } 1672 } 1673 CBOR diagnostic notation: [1734, "bob", "admin"] 1675 CBOR encoding: 1677 83 # array(3) 1678 19 06C6 # unsigned(1734) 1679 63 # text(3) 1680 626F62 # "bob" 1681 65 # text(5) 1682 61646D696E # "admin" 1684 *Third example:* 1686 The following example shows the encoding of the 'reporting-entity' 1687 value referencing the list instance "/system/authentication/user" 1688 (SID 1730) corresponding to user name "jack". 1690 CBOR diagnostic notation: [1730, "jack"] 1692 CBOR encoding: 1694 82 # array(2) 1695 19 06C2 # unsigned(1730) 1696 64 # text(4) 1697 6A61636B # "jack" 1699 6.13.2. Names as instance-identifier 1701 An "instance-identifier" value is encoded as a string that is 1702 analogical to the lexical representation in XML encoding; see 1703 Section 9.13.2 in [RFC7950]. However, the encoding of namespaces in 1704 instance-identifier values follows the rules stated in Section 3.3, 1705 namely: 1707 o The leftmost (top-level) data node name is always in the namespace 1708 qualified form. 1710 o Any subsequent data node name is in the namespace qualified form 1711 if the node is defined in a module other than its parent node, and 1712 the simple form is used otherwise. This rule also holds for node 1713 names appearing in predicates. 1715 For example, 1717 /ietf-interfaces:interfaces/interface[name='eth0']/ietf-ip:ipv4/ip 1718 is a valid instance-identifier value because the data nodes 1719 "interfaces", "interface", and "name" are defined in the module 1720 "ietf-interfaces", whereas "ipv4" and "ip" are defined in "ietf-ip". 1722 The resulting xpath MUST be encoded using a CBOR text string data 1723 item (major type 3). 1725 *First example:* 1727 This example is described in Section 6.13.1. 1729 CBOR diagnostic notation: "/ietf-system:system/contact" 1731 CBOR encoding: 1733 78 1c 2F696574662D73797374656D3A73797374656D2F636F6E74616374 1735 *Second example:* 1737 This example is described in Section 6.13.1. 1739 CBOR diagnostic notation: 1741 "/ietf-system:system/authentication/user[name='bob']/authorized-key 1742 [name='admin']/key-data" 1744 CBOR encoding: 1746 78 59 1747 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1748 74696F6E2F757365725B6E616D653D27626F62275D2F617574686F72697A 1749 65642D6B65790D0A5B6E616D653D2761646D696E275D2F6B65792D64617461 1751 *Third example:* 1753 This example is described in Section 6.13.1. 1755 CBOR diagnostic notation: 1757 "/ietf-system:system/authentication/user[name='jack']" 1759 CBOR encoding: 1761 78 33 1762 2F696574662D73797374656D3A73797374656D2F61757468656E74696361 1763 74696F6E2F757365725B6E616D653D27626F62275D 1765 7. Content-Types 1767 The following Content-Type is defined: 1769 application/yang-data+cbor; id=name: This Content-Type represents a 1770 CBOR YANG document containing one or multiple data node values. 1771 Each data node is identified by its associated namespace qualified 1772 name as defined in Section 3.3. 1774 FORMAT: CBOR map of name, instance-value 1776 The message payload of Content-Type 'application/yang-data+cbor' 1777 is encoded using a CBOR map. Each entry within the CBOR map 1778 contains the data node identifier (i.e. its namespace qualified 1779 name) and the associated instance-value. Instance-values are 1780 encoded using the rules defined in Section 4 1782 8. Security Considerations 1784 The security considerations of [RFC7049] and [RFC7950] apply. 1786 This document defines an alternative encoding for data modeled in the 1787 YANG data modeling language. As such, this encoding does not 1788 contribute any new security issues in addition of those identified 1789 for the specific protocol or context for which it is used. 1791 To minimize security risks, software on the receiving side SHOULD 1792 reject all messages that do not comply to the rules of this document 1793 and reply with an appropriate error message to the sender. 1795 9. IANA Considerations 1797 9.1. Media-Types Registry 1799 This document adds the following Media-Type to the "Media Types" 1800 registry. 1802 +----------------+----------------------------+-----------+ 1803 | Name | Template | Reference | 1804 +----------------+----------------------------+-----------+ 1805 | yang-data+cbor | application/yang-data+cbor | RFC XXXX | 1806 +----------------+----------------------------+-----------+ 1808 // RFC Ed.: replace RFC XXXX with this RFC number and remove this 1809 note. 1811 9.2. CoAP Content-Formats Registry 1813 This document adds the following Content-Format to the "CoAP Content- 1814 Formats", within the "Constrained RESTful Environments (CoRE) 1815 Parameters" registry. 1817 +---------------------------------+--------------+------+-----------+ 1818 | Media Type | Content | ID | Reference | 1819 | | Coding | | | 1820 +---------------------------------+--------------+------+-----------+ 1821 | application/yang-data+cbor; | | TBD1 | RFC XXXX | 1822 | id=name | | | | 1823 +---------------------------------+--------------+------+-----------+ 1825 // RFC Ed.: replace TBD1 with assigned IDs and remove this note. // 1826 RFC Ed.: replace RFC XXXX with this RFC number and remove this note. 1828 9.3. CBOR Tags Registry 1830 This specification requires the assignment of CBOR tags for the 1831 following YANG datatypes. These tags are added to the CBOR Tags 1832 Registry as defined in section 7.2 of [RFC7049]. 1834 +-----+------------------+-----------------------------+-----------+ 1835 | Tag | Data Item | Semantics | Reference | 1836 +-----+------------------+-----------------------------+-----------+ 1837 | 43 | text string | YANG bits datatype | [this] | 1838 | | | ; see Section 6.7. | | 1839 | 44 | text string | YANG enumeration datatype | [this] | 1840 | | | ; see Section 6.6. | | 1841 | 45 | unsigned integer | YANG identityref datatype | [this] | 1842 | | or text string | ; see Section 6.10. | | 1843 | 46 | unsigned integer | YANG instance-identifier | [this] | 1844 | | or text string | datatype; see Section 6.13. | [this] | 1845 | | or array | | | 1846 | 47 | unsigned integer | YANG Schema Item iDentifier | | 1847 | | | ; see Section 3.2. | [this] | 1848 +-----+------------------+-----------------------------+-----------+ 1850 // RFC Ed.: replace [this] with RFC number and remove this note 1852 10. Acknowledgments 1854 This document has been largely inspired by the extensive works done 1855 by Andy Bierman and Peter van der Stok on [I-D.ietf-core-comi]. 1856 [RFC7951] has also been a critical input to this work. The authors 1857 would like to thank the authors and contributors to these two drafts. 1859 The authors would also like to acknowledge the review, feedback, and 1860 comments from Ladislav Lhotka and Juergen Schoenwaelder. 1862 11. References 1864 11.1. Normative References 1866 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 1867 Requirement Levels", BCP 14, RFC 2119, 1868 DOI 10.17487/RFC2119, March 1997, 1869 . 1871 [RFC5234] Crocker, D., Ed. and P. Overell, "Augmented BNF for Syntax 1872 Specifications: ABNF", STD 68, RFC 5234, 1873 DOI 10.17487/RFC5234, January 2008, 1874 . 1876 [RFC6241] Enns, R., Ed., Bjorklund, M., Ed., Schoenwaelder, J., Ed., 1877 and A. Bierman, Ed., "Network Configuration Protocol 1878 (NETCONF)", RFC 6241, DOI 10.17487/RFC6241, June 2011, 1879 . 1881 [RFC7049] Bormann, C. and P. Hoffman, "Concise Binary Object 1882 Representation (CBOR)", RFC 7049, DOI 10.17487/RFC7049, 1883 October 2013, . 1885 [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", 1886 RFC 7950, DOI 10.17487/RFC7950, August 2016, 1887 . 1889 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 1890 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 1891 May 2017, . 1893 [RFC8610] Birkholz, H., Vigano, C., and C. Bormann, "Concise Data 1894 Definition Language (CDDL): A Notational Convention to 1895 Express Concise Binary Object Representation (CBOR) and 1896 JSON Data Structures", RFC 8610, DOI 10.17487/RFC8610, 1897 June 2019, . 1899 11.2. Informative References 1901 [I-D.ietf-core-comi] 1902 Veillette, M., Stok, P., Pelov, A., Bierman, A., and I. 1903 Petrov, "CoAP Management Interface", draft-ietf-core- 1904 comi-09 (work in progress), March 2020. 1906 [I-D.ietf-core-sid] 1907 Veillette, M., Pelov, A., and I. Petrov, "YANG Schema Item 1908 iDentifier (SID)", draft-ietf-core-sid-13 (work in 1909 progress), June 2020. 1911 [RFC7228] Bormann, C., Ersue, M., and A. Keranen, "Terminology for 1912 Constrained-Node Networks", RFC 7228, 1913 DOI 10.17487/RFC7228, May 2014, 1914 . 1916 [RFC7317] Bierman, A. and M. Bjorklund, "A YANG Data Model for 1917 System Management", RFC 7317, DOI 10.17487/RFC7317, August 1918 2014, . 1920 [RFC7951] Lhotka, L., "JSON Encoding of Data Modeled with YANG", 1921 RFC 7951, DOI 10.17487/RFC7951, August 2016, 1922 . 1924 [RFC8040] Bierman, A., Bjorklund, M., and K. Watsen, "RESTCONF 1925 Protocol", RFC 8040, DOI 10.17487/RFC8040, January 2017, 1926 . 1928 [RFC8259] Bray, T., Ed., "The JavaScript Object Notation (JSON) Data 1929 Interchange Format", STD 90, RFC 8259, 1930 DOI 10.17487/RFC8259, December 2017, 1931 . 1933 [RFC8343] Bjorklund, M., "A YANG Data Model for Interface 1934 Management", RFC 8343, DOI 10.17487/RFC8343, March 2018, 1935 . 1937 [RFC8344] Bjorklund, M., "A YANG Data Model for IP Management", 1938 RFC 8344, DOI 10.17487/RFC8344, March 2018, 1939 . 1941 [RFC8348] Bierman, A., Bjorklund, M., Dong, J., and D. Romascanu, "A 1942 YANG Data Model for Hardware Management", RFC 8348, 1943 DOI 10.17487/RFC8348, March 2018, 1944 . 1946 Authors' Addresses 1947 Michel Veillette (editor) 1948 Trilliant Networks Inc. 1949 610 Rue du Luxembourg 1950 Granby, Quebec J2J 2V2 1951 Canada 1953 Email: michel.veillette@trilliantinc.com 1955 Ivaylo Petrov (editor) 1956 Acklio 1957 1137A avenue des Champs Blancs 1958 Cesson-Sevigne, Bretagne 35510 1959 France 1961 Email: ivaylo@ackl.io 1963 Alexander Pelov 1964 Acklio 1965 1137A avenue des Champs Blancs 1966 Cesson-Sevigne, Bretagne 35510 1967 France 1969 Email: a@ackl.io