Re: [netmod] attributes in draft-lhotka-netmod-yang-json

Ladislav Lhotka <lhotka@nic.cz> Sun, 23 March 2014 15:26 UTC

Return-Path: <lhotka@nic.cz>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (ietfa.amsl.com [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id F24E51A6FD1 for <netmod@ietfa.amsl.com>; Sun, 23 Mar 2014 08:26:10 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.9
X-Spam-Level:
X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5 tests=[BAYES_00=-1.9] 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 GR5LF0CxaaP4 for <netmod@ietfa.amsl.com>; Sun, 23 Mar 2014 08:26:09 -0700 (PDT)
Received: from trail.lhotka.name (trail.lhotka.name [77.48.224.143]) by ietfa.amsl.com (Postfix) with ESMTP id C1E871A6FD0 for <netmod@ietf.org>; Sun, 23 Mar 2014 08:26:08 -0700 (PDT)
Received: from localhost (localhost [127.0.0.1]) by trail.lhotka.name (Postfix) with ESMTP id 348C554050C; Sun, 23 Mar 2014 16:26:07 +0100 (CET)
Received: from trail.lhotka.name ([127.0.0.1]) by localhost (trail.lhotka.name [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g0SDCNPQ6XNI; Sun, 23 Mar 2014 16:26:02 +0100 (CET)
Received: from localhost (unknown [172.29.2.202]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by trail.lhotka.name (Postfix) with ESMTPSA id 36FFE540192; Sun, 23 Mar 2014 16:26:01 +0100 (CET)
From: Ladislav Lhotka <lhotka@nic.cz>
To: Martin Bjorklund <mbj@tail-f.com>
In-Reply-To: <20140323.110741.449355686.mbj@tail-f.com>
References: <m2bnwy7j0c.fsf@nic.cz> <CABCOCHRFjzj40nWtckJRPCbxCMSwojadRh0rBb27qMRyHx8MHA@mail.gmail.com> <m2ob0xb697.fsf@nic.cz> <20140323.110741.449355686.mbj@tail-f.com>
User-Agent: Notmuch/0.17~rc2+11~g2de8ce9 (http://notmuchmail.org) Emacs/24.3.50.2 (x86_64-apple-darwin13.0.0)
Date: Sun, 23 Mar 2014 16:26:00 +0100
Message-ID: <m2ha6paqd3.fsf@nic.cz>
MIME-Version: 1.0
Content-Type: text/plain
Archived-At: http://mailarchive.ietf.org/arch/msg/netmod/LfgvAHzHNJX5ZenFT6XcehukHsQ
Cc: netmod@ietf.org
Subject: Re: [netmod] attributes in draft-lhotka-netmod-yang-json
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: NETMOD WG list <netmod.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/netmod>, <mailto:netmod-request@ietf.org?subject=unsubscribe>
List-Archive: <http://www.ietf.org/mail-archive/web/netmod/>
List-Post: <mailto:netmod@ietf.org>
List-Help: <mailto:netmod-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/netmod>, <mailto:netmod-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sun, 23 Mar 2014 15:26:11 -0000

Martin Bjorklund <mbj@tail-f.com> writes:

> Ladislav Lhotka <lhotka@nic.cz> wrote:
>> Andy Bierman <andy@yumaworks.com> writes:
>> 
>> ...
>> 
>> >
>> > The attribute mapping needs to correspond to the XML attribute mapping.
>> > Attributes have string values, so the mapping above will not work.
>> 
>> I don't understand. XML schemas can define attribute values to be of other
>> types, too, not only string.
>> 
>> >
>> > Attributes can be qualified or unqualified.  If qualified, then the
>> > module-name
>> > is used as a prefix:
>> >
>> >   "foo" [ 1, 2, { "@foo-mod:owner":"admin1", "foo":3}, {
>> > "@foo-mod:owner":"admin2", "foo":4},
>> >
>> >
>> > This approach presumes the attribute has a YANG module name that defines
>> > the attribute,
>> > which is of course not allowed.
>> >
>> > RFC 6241 defines XML attributes for the <get> operation, using a hack
>> > called the  'get-filter-element-attributes' extension.
>> > http://www.netconfcentral.org/modules/ietf-netconf/2011-06-01#get-filter-element-attributes.56
>> 
>> This is another extension that violates the rule stated in RFC 6020,
>> sec. 6.3.1:
>> 
>>    If a YANG compiler does not support a particular extension, which
>>    appears in a YANG module as an unknown-statement (see Section 12),
>>    the entire unknown-statement MAY be ignored by the compiler.
>> 
>> >
>> > The NETCONF-EX <get2> operation has a "with-metadata" parameter that uses
>> > identities
>> > to map attributes to YANG.
>> >
>> > I think a standard mechanism is needed to properly map attributes to JSON
>> > and XML.
>> 
>> I'd suggest to define two generic constructs:
>> 
>> 1. Metadata
>> 
>> Every JSON value (false / null / true / object / array / number / string) can
>> be changed into a "@tagged-value" object, e.g. the number 42 can become
>> 
>> {
>>   "@tagged-value" : {
>>     "@owner": "admin1",
>>     "@value": 42
>>   }
>> }
>> 
>> Multiple metadata key-value pairs may be present inside the "@tagged-value"
>> object.
>> 
>> 2. Properties
>> 
>> For a property "foo", every JSON value can be changed into a "@foo" object,
>> e.g.
>> 
>> {
>>   "@foo": 42
>> }
>> 
>> Such property objects may nest, e.g.
>> 
>> {
>>   "@bar":
>>   {
>>     "@foo": 42
>>   }
>> }
>>   
>> Both constructs work for list and leaf-list entries, and may be also combined.
>
> This makes both client and server programming much more complex.  The
> whole point of using JSON is supposedly that it maps well to built-in
> datastructures in modern languages.  This property makes parsing
> trivial, and makes it easy to get values.  For example:
>
>   res = json_parse(...)
>   if res['ssh']['enabled']:
>      ...
>
> now, with the proposed encoding, I have to be prepared for 'ssh' being
> a '@tagged-value', and '@enabled' being a tagged-value, and
> combinations thereof:
>
>   if res['ssh']['enabled']
>      or res['@tagged-value']['ssh']['enabled']
>      or res['@tagged-value']['ssh']['@tagged-value']['enabled']
>      or ...
>
> As I write this I realize that I don't really understand your
> proposal..., so the code above is not correct - but the point is the
> same; as soon as you allow multiple encodings you make coding much
> more complex.

I don't know whether the "enabled" parameter is a node in the data model or a global attribute that can be added to any instance. Show me the intended XML encoding.

What I was trying to achieve was to be able to turn any JSON value into an object where the value is present together with any number of tags.

Please check the examples in my response to Andy (and maybe ignore the "property" thing for the time being, it is just an optimization for a special case). 

>
> Maybe the original JSON mapping idea is the only one that works; i.e.,
> map pure YANG data to JSON.  No meta data.  A protocol that needs meta
> data should not use JSON; use XML instead.

I tend to agree, and that's why I've been relucant to address attributes in the draft. For "pure" YANG-based data JSON is an excellent fit (IMO better than XML) and some applications should be just fine with it.

Lada 

>
>
> /martin

-- 
Ladislav Lhotka, CZ.NIC Labs
PGP Key ID: E74E8C0C