Re: [core] YANG to CBOR mapping

Carsten Bormann <cabo@tzi.org> Thu, 10 March 2016 09:32 UTC

Return-Path: <cabo@tzi.org>
X-Original-To: core@ietfa.amsl.com
Delivered-To: core@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 950F112D5D9 for <core@ietfa.amsl.com>; Thu, 10 Mar 2016 01:32:55 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.62
X-Spam-Level:
X-Spam-Status: No, score=-2.62 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01] autolearn=ham autolearn_force=no
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 GjWB5CnJ_z5j for <core@ietfa.amsl.com>; Thu, 10 Mar 2016 01:32:53 -0800 (PST)
Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 9B1FE12D617 for <core@ietf.org>; Thu, 10 Mar 2016 01:32:52 -0800 (PST)
Received: from mfilter31-d.gandi.net (mfilter31-d.gandi.net [217.70.178.162]) by relay3-d.mail.gandi.net (Postfix) with ESMTP id E43B4A80DF; Thu, 10 Mar 2016 10:32:50 +0100 (CET)
X-Virus-Scanned: Debian amavisd-new at mfilter31-d.gandi.net
Received: from relay3-d.mail.gandi.net ([IPv6:::ffff:217.70.183.195]) by mfilter31-d.gandi.net (mfilter31-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id lZzt36SE_206; Thu, 10 Mar 2016 10:32:49 +0100 (CET)
X-Originating-IP: 93.204.214.47
Received: from nar.local (p5DCCD62F.dip0.t-ipconnect.de [93.204.214.47]) (Authenticated sender: cabo@cabo.im) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id BAF8AA80E4; Thu, 10 Mar 2016 10:31:58 +0100 (CET)
Message-ID: <56E13F0C.7020504@tzi.org>
Date: Thu, 10 Mar 2016 10:31:56 +0100
From: Carsten Bormann <cabo@tzi.org>
User-Agent: Postbox 4.0.8 (Macintosh/20151105)
MIME-Version: 1.0
To: consultancy@vanderstok.org
References: <125ea14670116bd8cbc275a2b1b011f9@xs4all.nl>
In-Reply-To: <125ea14670116bd8cbc275a2b1b011f9@xs4all.nl>
X-Enigmail-Version: 1.2.3
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 8bit
Archived-At: <http://mailarchive.ietf.org/arch/msg/core/Jdg1yYuL_ldpqm6CnaDO1fiN_B4>
Cc: Core <core@ietf.org>
Subject: Re: [core] YANG to CBOR mapping
X-BeenThere: core@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
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, 10 Mar 2016 09:32:55 -0000

Hi Peter,

> The SID and and hash are both numbers, why not map them both to unsigned
> integer (major type 0)?

SIDs benefit from compression by delta encoding (turning them into
signed integers in the actual delta).
Delta encoding does not make sense for hashes (just spreads the numbers
further out).
So it is useful to be able to *distinguish* the two, specifically before
the delta encoding kicks in.

One way that came up for this in discussions about how to best use CBOR
for YANG data representation is to represent the hashes as binary
strings.  E.g., if the hash value is 1234567890, what might have been

1a 499602d2 # unsigned(1234567890)

becomes h'499602d2' or

44          # bytes(4)
   499602d2 # "I\x96\x02\xD2"

Since hashes are evenly distributed in the 30-bit space, there is no
change in the number of bytes needed (except maybe for the p = 1/16384
case that the hash happens to be < 65536).

With this way of distinguishing identifiers, in the end, we can have a
mapping of CBOR data types to identifiers:

CBOR type     meaning
integer       delta encoded SID
byte string   hash
text string   native YANG identifier

(It is then a matter of design and/or deployment which of these kinds of
identifiers are actually used in a specific instance.)

> The server does not care how these numbers are produced, it only needs
> to map the number to the memory locations in the server.

Exactly.

Grüße, Carsten