Re: [core] [netmod] CBOR YANG encoding of union & bits [draft-ietf-core-yang-cbor-12]

Ivaylo Petrov <ivaylo@ackl.io> Thu, 04 June 2020 15:50 UTC

Return-Path: <ivaylo@ackl.io>
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 E0D2C3A0909 for <core@ietfa.amsl.com>; Thu, 4 Jun 2020 08:50:46 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.898
X-Spam-Level:
X-Spam-Status: No, score=-1.898 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=unavailable autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=ackl-io.20150623.gappssmtp.com
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 qwGV4KkPIGme for <core@ietfa.amsl.com>; Thu, 4 Jun 2020 08:50:44 -0700 (PDT)
Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 5335B3A03EA for <core@ietf.org>; Thu, 4 Jun 2020 08:50:44 -0700 (PDT)
Received: by mail-wm1-x32e.google.com with SMTP id u13so5741488wml.1 for <core@ietf.org>; Thu, 04 Jun 2020 08:50:44 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ackl-io.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=n5EbQLdl9znD/hPbNSCWc07SPoCyrZz4TFuZUNUOD5Y=; b=tau6C1GVloYy9dxMwJSKwa1XtyIQLMNEqspQn8fe4h5J88YOg2lxbHuY4yq1aelT1q UvFPR631PIJ3puD4bRnACHuljVFxv4iuB3VWkysOvVwcz7JBjcxPLZ/R0EPc/JKH7Pyr 357uorTJiqy7zrnFWrPUpe1MrGB/nBI1FlMXeqiaZiK5UBWqAjVEnBxtleO76CrMe7XV y/GFb0JaeZ4c5q6qG5uspVQhlszMuFsvFRj+VyMumAMUE0r1fjgg+nrFvoepaj2NAt0+ FUi9zXLHSfENfsoUSn+KC2xsyM7IXHoHSiJdbOlvKviDCM6IcFtLV02qlozr29n1DR35 Qi0A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=n5EbQLdl9znD/hPbNSCWc07SPoCyrZz4TFuZUNUOD5Y=; b=Tq/h1x+H4c63nusv/cKwjV4D3/n20UvOJBj06JpEhtU1PpGWBkUwiBQdY1l4IcHVTH 5RYssPcnjKEfdHUHQYzF0ITogyvwYNmnAphogZ00UzsWZ/v5kNuqEkMMY7HA/ts3i/bu 2HyTKLryvqzN3h6wdpc3M6rdExjOMVf9JoSEOezHys8u6aeVefhuGrcV6474k/lywKta xIYBc4vkuwUN0m5Na5bjoqetgwTEeNx321rLZ+aNtuubNdgDPXwY95SYnMYcU/h/YrkS 06BgW8itFandqyzS8wEmC/dS6fi6OH4hk8uFDIWAR/zIj3QH2N59buU2d7mb/ijNNNBH Dieg==
X-Gm-Message-State: AOAM532F+8hNjkzpK4v/aNTmALHXHtD63o2TlrG3hxBW19mbzDQ9Iaep nfkn97mdYqPLrBGy2EPd2YVOgUtClR90nBerR3EZQg==
X-Google-Smtp-Source: ABdhPJwDcixokV7oVkHiaKWwCkUu4OxuivPn6qxU7SqFzUh818k+QcWi+8BYTdnN0ZKCA1VtMeBvbYsJXBP6WTNViN4=
X-Received: by 2002:a1c:9d53:: with SMTP id g80mr4899826wme.13.1591285839189; Thu, 04 Jun 2020 08:50:39 -0700 (PDT)
MIME-Version: 1.0
References: <BY5PR11MB4355C26250C9CF46713C9956B5A40@BY5PR11MB4355.namprd11.prod.outlook.com> <D66596CE-7F5C-4562-89A4-48FCE96D0E18@tzi.org> <28486.1588785684@localhost> <CABCOCHRRDYDomEPctAHaHf+MxS2qXab1J4o=_LUEWcJ2=by5Ww@mail.gmail.com> <8F06BFE6-CE7C-4D10-AC61-24AAA2807E45@tzi.org> <CABCOCHRUCK_FpwSCnOOy8fBCX_HeAWQeFvJEyZy2hUL4L2WhrQ@mail.gmail.com> <CABCOCHQOWoPozsYOfVEDy_TYw-YF5H9TZ2eydcOpj-g2d3ysNQ@mail.gmail.com> <000701d62560$d681d790$838586b0$@augustcellars.com> <20200508181307.xxx7am5cis6k6asv@anna.jacobs.jacobs-university.de>
In-Reply-To: <20200508181307.xxx7am5cis6k6asv@anna.jacobs.jacobs-university.de>
From: Ivaylo Petrov <ivaylo@ackl.io>
Date: Thu, 04 Jun 2020 17:50:13 +0200
Message-ID: <CAJFkdRzFBTXXxst-EVeB3tMKtbMWTdET-Ma4Fd4WBjYHgM7JrA@mail.gmail.com>
To: Juergen Schoenwaelder <j.schoenwaelder@jacobs-university.de>, Jim Schaad <ietf@augustcellars.com>, Andy Bierman <andy@yumaworks.com>, Carsten Bormann <cabo@tzi.org>, NetMod WG <netmod@ietf.org>, core <core@ietf.org>
Content-Type: multipart/alternative; boundary="0000000000002e6a0005a7441b4d"
Archived-At: <https://mailarchive.ietf.org/arch/msg/core/H-v4Wo64tz9hkqIASAxwzJiByeY>
Subject: Re: [core] [netmod] CBOR YANG encoding of union & bits [draft-ietf-core-yang-cbor-12]
X-BeenThere: core@ietf.org
X-Mailman-Version: 2.1.29
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, 04 Jun 2020 15:50:48 -0000

Dear all,

Thank you for spotting this issue and discussing a possible solution. I
finally managed to dedicate enough time to try to properly understand it.
If my understanding is correct, the problem we are discussing is that in
some rare cases the proposed encoding of 'bits' might be really
inefficient. I have attempted to capture the discussed solution with this
change [1]. The proposed change is replacing the following text:

Leafs of type bits MUST be encoded using a CBOR byte string data item (major
type 2). Bits position are either explicitly assigned using the YANG
statement
'position' or automatically assigned based on the algorithm defined in
{{RFC7950}} section 9.7.4.2.

Bits position 0 to 7 are assigned to the first byte within the byte
string, bits 8 to 15 to the second byte, and subsequent bytes are assigned
similarly. Within each byte, bits are assigned from least to most
significant.

The following example shows the encoding of an 'alarm-state' leaf instance
with the 'under-repair' and 'critical' flags set.

Definition example from {{RFC8348}}:

~~~~ yang
typedef alarm-state {
  type bits {
    bit unknown;
    bit under-repair;
    bit critical;
    bit major;
    bit minor;
    bit warning;
    bit indeterminate;
  }
}

leaf alarm-state {
  type alarm-state;
}
~~~~

CBOR diagnostic notation: h'06'

CBOR encoding: 41 06


with

Keeping in mind that bit positions are either explicitly assigned using the
YANG statement 'position' or automatically assigned based on the algorithm
defined in {{RFC7950}} section 9.7.4.2, each element of type bits could be
seen
as a set of bit offsets that have a value of ether 1, which represents the
bit
being set or 0, which represents that the bit is not set.

Leafs of type bits MUST be encoded using a CBOR array where each element is
either an unsigned integer that can be used to calculate the offset, or a
byte
string (major type 2) that carries the information whether certain bits are
set
or not. The initial offset value is 0 and each unsigned integer modifies the
offset value of the next byte string by the integer value multiplied by 8.
For
example, if the bit offset is 0 and there is an integer with value 5, the
first
byte of the byte string that follows will represent bit positions 40 to 47
both
ends included. If the byte string has a second byte, it will carry
information
about bits 48 to 55 and so on. Within each byte, bits are assigned from
least
to most significant. After the byte string the offset is modified by the
number
of bytes in the byte string multiplied by 8. An example follows.

The following example shows the encoding of an 'alarm-state' leaf instance
with
the 'critical', 'warning' and 'indeterminate' flags set.

~~~~ yang
typedef alarm-state {
  type bits {
    bit unknown;
    bit under-repair;
    bit critical;
    bit major;
    bit minor;
    bit warning {
      position 8;
    }
    bit indeterminate {
      position 128;
    }
  }
}

leaf alarm-state {
  type alarm-state;
}
~~~~

CBOR diagnostic notation: [h'0401', 14, h'01']

CBOR encoding: 83 42 0401 0E 41 01

Having two consecutive unsigned integers, byte strings or having elements
that
are neither unsigned integer nor byte string inside the array SHOULD be
considered an error.


Please let me know if I have managed to capture the essence of the problem
and the proposed solution or if you believe this could be written in a more
clear way.

Thanks,
Ivaylo

[1]:
https://github.com/core-wg/yang-cbor/commit/6bcea062224537c2e792756818898f764b03d5b7


On Fri, May 8, 2020 at 8:13 PM Juergen Schoenwaelder <
j.schoenwaelder@jacobs-university.de> wrote:

> On Fri, May 08, 2020 at 10:48:06AM -0700, Jim Schaad wrote:
>
> > Does yang consider that there is a difference between a bit being
> > present and zero and a bit being absent?
>
> In YANG every bit in the bit set is either 0 or 1. The xml / json
> encodings send the position of the 1 bits (actually the names bound to
> the position). All other bits default to 0.
>
> /js
>
> --
> Juergen Schoenwaelder           Jacobs University Bremen gGmbH
> Phone: +49 421 200 3587         Campus Ring 1 | 28759 Bremen | Germany
> Fax:   +49 421 200 3103         <https://www.jacobs-university.de/>
>
> _______________________________________________
> core mailing list
> core@ietf.org
> https://www.ietf.org/mailman/listinfo/core
>