[core] YANG list to CBOR mapping
peter van der Stok <stokcons@xs4all.nl> Thu, 19 November 2015 10:05 UTC
Return-Path: <stokcons@xs4all.nl>
X-Original-To: core@ietfa.amsl.com
Delivered-To: core@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 1849F1B3139 for <core@ietfa.amsl.com>; Thu, 19 Nov 2015 02:05:55 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.601
X-Spam-Level:
X-Spam-Status: No, score=-2.601 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=ham
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WeumoqM0tBSM for <core@ietfa.amsl.com>; Thu, 19 Nov 2015 02:05:53 -0800 (PST)
Received: from lb1-smtp-cloud3.xs4all.net (lb1-smtp-cloud3.xs4all.net [194.109.24.22]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id EE4621B2B04 for <core@ietf.org>; Thu, 19 Nov 2015 02:05:52 -0800 (PST)
Received: from webmail.xs4all.nl ([194.109.20.214]) by smtp-cloud3.xs4all.net with ESMTP id jN5r1r00F4d84Ai01N5rXr; Thu, 19 Nov 2015 11:05:51 +0100
Received: from [2001:983:a264:1:5cbf:6d13:c88d:6742] by webmail.xs4all.nl with HTTP (HTTP/1.1 POST); Thu, 19 Nov 2015 11:05:51 +0100
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"; format="flowed"
Content-Transfer-Encoding: 8bit
Date: Thu, 19 Nov 2015 11:05:51 +0100
From: peter van der Stok <stokcons@xs4all.nl>
To: Core <core@ietf.org>
Organization: vanderstok consultancy
Mail-Reply-To: consultancy@vanderstok.org
Message-ID: <170106a36217a736a4b55991c4a5cf6a@xs4all.nl>
X-Sender: stokcons@xs4all.nl (+pvqFLLFY7kaovOsj26bTG5EOFEWE8kw)
User-Agent: XS4ALL Webmail
Archived-At: <http://mailarchive.ietf.org/arch/msg/core/Kd7ZqxXePNvaHhKnNkIkdV_EwpQ>
Cc: lhotka@nic.cz
Subject: [core] YANG list to CBOR mapping
X-BeenThere: core@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
Reply-To: consultancy@vanderstok.org
List-Id: "Constrained RESTful Environments \(CoRE\) Working Group list" <core.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/core>, <mailto:core-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/core/>
List-Post: <mailto:core@ietf.org>
List-Help: <mailto:core-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/core>, <mailto:core-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 19 Nov 2015 10:05:55 -0000
Hi CoOL authors, This e_mail complements my earlier e-mail on YANG to CBOR mapping, and explains the proposed list encoding. Both the draft yang-json and the CoOL draft encode a list as an array. In the yang-json case as a JSON array, and in the CoOL case as major type 4 of major type 5 objects. This encoding prevents the selection of list instances on the basis of the key values from the payload alone. In CoMI the list is encoded as a major type 5 of major type 5 objects. This deviation from the yang-json mapping is motivated by the wish to transport individual list instances and identify the instances in the payload from the key values. This is especially important in case of PATCH operation on list instances. Two cases are to be looked at: (1) the list definition specifies one or more key elements, and (2) the list definition does not specify a key element. We will start with a list containing key elements. It is the wish to transport only those list elements with a unique key value, either to support a PATCH or a FETCH command. Therefore it is required that the payload allows the selection and identification of these list element on the basis of their key values. Using the diagnostic JSON notation used for CBOR diagnostics, the payload containing a number of elements with key values should look like a JSON object with the structure list-name: {key: value}. Both key and value are composed of JSON objects separated by commas. For example consider the following YANG list specification: module foo { namespace http://example.com/book; prefix “fo”; revision 2015-06-07; list B { key “key1 key2”; leaf key1 {type string;} leaf key2 {type string;} leaf coll {type int32;} leaf counter {type int32;} } } Consider the transport of two instances specified by <“key1” = “book1”, “key2” = “author2”> and by <“key1” = “book5”, “key2” = “author3”> out of a larger set of instances. The representation is different from the yang-json one for the reasons explained above. The payload will look like: {"B" :{ {"key1" : "book1", "key2" : "author2"} : {"coll" : 500, "counter": 66} , {"key1" : "book5", "key2" : "author3"} : {"coll" : 444, "counter": 11} } } Which translated to CBOR yields: a1 # map(1) 61 # text(1) 42 # "B" a2 # map(2) a2 # map(2) 64 # text(4) 6b657931 # "key1" 65 # text(5) 626f6f6b31 # "book1" 64 # text(4) 6b657932 # "key2" 67 # text(7) 617574686f7232 # "author2" a2 # map(2) 64 # text(4) 636f6c6c # "coll" 19 01f4 # unsigned(500) 67 # text(7) 636f756e746572 # "counter" 18 42 # unsigned(66) a2 # map(2) 64 # text(4) 6b657931 # "key1" 65 # text(5) 626f6f6b35 # "book5" 64 # text(4) 6b657932 # "key2" 67 # text(7) 617574686f7233 # "author3" a2 # map(2) 64 # text(4) 636f6c6c # "coll" 19 01bc # unsigned(444) 67 # text(7) 636f756e746572 # "counter" 0b # unsigned(11) The corresponding yang-json draft encoding - that allows transport of a selection of instances- does not specify the key fields and would have looked like: {"B" : [ {"key1" : "book1", "key2" : "author2”, "coll" : 500, "counter": 66 } , {"key1" : "book5", "key2" : "author3", "coll" : 444, "counter": 11, } ] } Suppose there are no key elements specified. In that case it is impossible to specify the wanted list elements, and always the whole list must be transported. In the case of a list without key specification is is best to use major type 4 composed of major type 5 to transport the list, as is specified in yang-json draft. Consider the following YANG list Module foo{ Namespace http://example.com/book; Prefix “bo” Revision 2015-06-7 List B { Leaf title {type string;} Leaf author {type string;} Leaf coll {type int32} Leaf counter {type int32} } } Suppose the list contains two elements. The transport payload of the two elements looks like: {"B" :[ {"title" : "book1", "author" : "author2", "coll" : 500, "counter": 66} , {"title" : "book5", "author" : "author3", “coll" : 444, "counter": 11} ] } This payload is identical to the yang-json payload. Which yields the corresponding CBOR code. a1 # map(1) 61 # text(1) 42 # "B" 82 # array(2) a4 # map(4) 65 # text(5) 7469746c65 # "title" 65 # text(5) 626f6f6b31 # "book1" 66 # text(6) 617574686f72 # "author" 67 # text(7) 617574686f7232 # "author2" 64 # text(4) 636f6c6c # "coll" 19 01f4 # unsigned(500) 67 # text(7) 636f756e746572 # "counter" 18 42 # unsigned(66) a4 # map(4) 65 # text(5) 7469746c65 # "title" 65 # text(5) 626f6f6b35 # "book5" 66 # text(6) 617574686f72 # "author" 67 # text(7) 617574686f7233 # "author3" 64 # text(4) 636f6c6c # "coll" 19 01bc # unsigned(444) 67 # text(7) 636f756e746572 # "counter" 0b # unsigned(11) -- Peter van der Stok vanderstok consultancy mailto: consultancy@vanderstok.org
- [core] YANG list to CBOR mapping peter van der Stok
- Re: [core] YANG list to CBOR mapping Michel Veillette
- Re: [core] YANG list to CBOR mapping Michel Veillette
- Re: [core] YANG list to CBOR mapping peter van der Stok
- Re: [core] YANG list to CBOR mapping Michel Veillette
- Re: [core] YANG list to CBOR mapping Carsten Bormann
- Re: [core] YANG list to CBOR mapping peter van der Stok