Re: [netmod] xpath expressions in JSON

Ladislav Lhotka <lhotka@nic.cz> Tue, 23 October 2018 08:35 UTC

Return-Path: <lhotka@nic.cz>
X-Original-To: netmod@ietfa.amsl.com
Delivered-To: netmod@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 52D9B130EEA for <netmod@ietfa.amsl.com>; Tue, 23 Oct 2018 01:35:55 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -6.999
X-Spam-Level:
X-Spam-Status: No, score=-6.999 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_HI=-5, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=nic.cz
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 hEKX5JQTYMwQ for <netmod@ietfa.amsl.com>; Tue, 23 Oct 2018 01:35:51 -0700 (PDT)
Received: from mail.nic.cz (mail.nic.cz [217.31.204.67]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 71B6D130EE7 for <netmod@ietf.org>; Tue, 23 Oct 2018 01:35:51 -0700 (PDT)
Received: from birdie (unknown [IPv6:2001:718:1a02:1::380]) by mail.nic.cz (Postfix) with ESMTPSA id B8BCE6088F; Tue, 23 Oct 2018 10:35:49 +0200 (CEST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nic.cz; s=default; t=1540283749; bh=AWNqZcDK09YFqEBClH4IeMtLY/r3d//PYb1K+iFWKwE=; h=From:To:Date; b=E3lERG8pE4pRi5nhm5Qs0/dakMgci21t+Z01ELW0YVQ0x9I0cflItI7HGS3HSb0IO +iSfTDMsoamMYWWJcYMI9KLahzKst4ydtks5v3/mza6OQ/PIkqQcVDNBYh7UacAvFK gEx9izisrSjZe794OcWbqwOo5ItNRx2QUt72W+OU=
Message-ID: <356c8c17ccb4028d854039d6843aab9c15137442.camel@nic.cz>
From: Ladislav Lhotka <lhotka@nic.cz>
To: Martin Bjorklund <mbjorklu@cisco.com>
Cc: bill.wu@huawei.com, netmod@ietf.org
Date: Tue, 23 Oct 2018 10:35:49 +0200
In-Reply-To: <20181023.102335.1716554595193005306.mbjorklu@cisco.com>
References: <B8F9A780D330094D99AF023C5877DABA9B0BC6A0@nkgeml513-mbx.china.huawei.com> <20181023.084254.2257754077098127031.mbj@tail-f.com> <87d0s1azc8.fsf@nic.cz> <20181023.102335.1716554595193005306.mbjorklu@cisco.com>
Organization: CZ.NIC
Content-Type: text/plain; charset="UTF-8"
User-Agent: Evolution 3.30.2
Mime-Version: 1.0
Content-Transfer-Encoding: 8bit
X-Virus-Scanned: clamav-milter 0.99.2 at mail
X-Virus-Status: Clean
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/pdoXHY7-YfM0Oty4C8smHAxn_wo>
Subject: Re: [netmod] xpath expressions in JSON
X-BeenThere: netmod@ietf.org
X-Mailman-Version: 2.1.29
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: <https://mailarchive.ietf.org/arch/browse/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: Tue, 23 Oct 2018 08:35:55 -0000

On Tue, 2018-10-23 at 10:23 +0200, Martin Bjorklund wrote:
> Ladislav Lhotka <lhotka@nic.cz> wrote:
> > Martin Bjorklund <mbj@tail-f.com> writes:
> 
> > 
> 
> > > Qin Wu <bill.wu@huawei.com> wrote:
> 
> > >> -----邮件原件-----
> 
> > >> 发件人: netmod [mailto:netmod-bounces@ietf.org] 代表 Ladislav Lhotka
> 
> > >> 发送时间: 2018年10月22日 21:12
> 
> > >> 收件人: Martin Bjorklund
> 
> > >> 抄送: netmod@ietf.org
> 
> > >> 主题: Re: [netmod] xpath expressions in JSON
> 
> > >> 
> 
> > >> On Mon, 2018-10-22 at 14:56 +0200, Martin Bjorklund wrote:
> 
> > >> > Ladislav Lhotka <lhotka@nic.cz> wrote:
> 
> > >> > > Martin Bjorklund <mbj@tail-f.com> writes:
> 
> > >> > > 
> 
> > >> > > > Hi,
> 
> > >> > > >
> 
> > >> > > > Going back to the most urgent issue, what is this WG's 
> 
> > >> > > > recommendation for the subscribed-notifications draft in NETCONF 
> 
> > >> > > > wrt/ their usage of
> 
> > >> > > > yang:xpath1.0 in filters?
> 
> > >> > > >
> 
> > >> > > > To summarize:
> 
> > >> > > >
> 
> > >> > > > We already have
> 
> > >> > > >
> 
> > >> > > >   o  instance-identifier in XML uses prefixes from the XML document
> 
> > >> > > >   o  instance-identifier in JSON uses module names as prefixes
> 
> > >> > > >   o  XPath in NETCONF filter uses prefixes from the XML document
> 
> > >> > > >   o  XPath in JSON query filter uses module names as prefixes
> 
> > >> > > >
> 
> > >> > > >
> 
> > >> > > > Alternative A:
> 
> > >> > > > --------------
> 
> > >> > > >
> 
> > >> > > > Use different encodings for "stream-xpath-filter" as well, 
> 
> > >> > > > depending on if it is XML or JSON.
> 
> > >> > > >
> 
> > >> > > > We would do in SN:
> 
> > >> > > >
> 
> > >> > > >     o  If the node is encoded in XML, the set of namespace
> 
> > >> > > >        declarations are those in scope on the
> 
> > >> > > >        'stream-xpath-filter' leaf element.
> 
> > >> > > >
> 
> > >> > > >     o  If the node is encoded in JSON, the set of namespace
> 
> > >> > > >        declarations is the set of prefix and namespace pairs
> 
> > >> > > >        for all supported YANG modules, where the prefix is
> 
> > >> > > 
> 
> > >> > > Is "supported" the same as "implemented", or something else?
> 
> > >> > 
> 
> > >> > It should be "implemented".
> 
> > >> > 
> 
> > >> > > >        the YANG module name and the namespace is as defined
> 
> > >> > > >        by the "namespace" statement in the YANG module.
> 
> > >> > > >
> 
> > >> > > > Pro: the format is consistent within each encoding.
> 
> > >> > > >
> 
> > >> > > > Con: unclear how to handle other encodings.
> 
> > >> > > > Con: we keep using context-depending encodings.
> 
> > >> > > 
> 
> > >> > >   Con: XPath expressions in JSON can get pretty long (I assume it's
> not
> 
> > >> > >   just an instance identifier but may contain predicates etc.). We
> 
> > >> > >   cannot use the trick with the default namespace as in YANG, so all
> 
> > >> > >   data node names will have to carry the prefix.
> 
> > >> > 
> 
> > >> > Yes.
> 
> > >> > 
> 
> > >> > > > We could probably add that CBOR uses the same representation as
> JSON.
> 
> > >> > > >
> 
> > >> > > > Example in XML:
> 
> > >> > > >
> 
> > >> > > >   <stream-xpath-filter
> 
> > >> > > >       xmlns:if="urn:ietf:params:xml:ns:yang:ietf-interfaces"
> 
> > >> > > >       xmlns:ip="urn:ietf:params:xml:ns:yang:ietf-ip">
> 
> > >> > > >     /if:interfaces/if:interface/ip:ipv4
> 
> > >> > > >   </stream-xpath-filter>
> 
> > >> > > >
> 
> > >> > > > Example in JSON:
> 
> > >> > > >
> 
> > >> > > >   "stream-xpath-filter":
> 
> > >> > > >     "/ietf-interfaces:interfaces/ietf-interfaces:interface/ietf-
> ip:ipv4"
> 
> > >> > > >
> 
> > >> > > >
> 
> > >> > > >
> 
> > >> > > > Alternative B:
> 
> > >> > > > --------------
> 
> > >> > > >
> 
> > >> > > > Use a non-context depending encoding, with the module name as
> prefix.
> 
> > >> > > >
> 
> > >> > > > We would do in SN:
> 
> > >> > > >
> 
> > >> > > >     o  The set of namespace
> 
> > >> > > >        declarations is the set of prefix and namespace pairs
> 
> > >> > > >        for all supported YANG modules, where the prefix is
> 
> > >> > > >        the YANG module name and the namespace is as defined
> 
> > >> > > >        by the "namespace" statement in the YANG module.
> 
> > >> > > >
> 
> > >> > > > Pro: the format is independent from the protocol encoding
> 
> > >> > > >
> 
> > >> > > > Con: in XML, this leaf is treated differently from other XPath
> 
> > >> > > >      expressions, such as get-config filter and nacm rules.
> 
> > >> > > >
> 
> > >> > > > Example in XML:
> 
> > >> > > >
> 
> > >> > > >   <stream-xpath-filter>
> 
> > >> > > >     /ietf-interfaces:interfaces/ietf-interfaces:interface/ietf-
> ip:ipv4
> 
> > >> > > >   </stream-xpath-filter>
> 
> > >> > > >
> 
> > >> > > > Example in JSON:
> 
> > >> > > >
> 
> > >> > > >   "stream-xpath-filter":
> 
> > >> > > >     "/ietf-interfaces:interfaces/ietf-interfaces:interface/ietf-
> ip:ipv4"
> 
> > >> > > >
> 
> > >> > > >
> 
> > >> > > > My proposal is A.  I think it is more important with consistency 
> 
> > >> > > > within each encoding than across encodings.
> 
> > >> > > 
> 
> > >> > > I would suggest to consider declaring prefixes & namespaces 
> 
> > >> > > explicitly in the data, as in the schema mount document. It is 
> 
> > >> > > independent of encoding and the expressions can be kept short. In 
> 
> > >> > > fact, one of the namespaces can be declared as default, so this use 
> 
> > >> > > of XPath would then be very similar to YANG.
> 
> > >> > 
> 
> > >> > Ok, so this is another alternative that works today, and achieves the 
> 
> > >> > goal of being encoding-independent.  It is still context-dependent 
> 
> > >> > though.
> 
> > >> 
> 
> > >> Yes, every module that uses XPath in data will have to deal with this.
> There may potentially be multiple independent prefix declarations (this is
> actually a con). 
> 
> > >> 
> 
> > >> > 
> 
> > >> > BTW, when used in filters, it is nice to let an unprefixed name to 
> 
> > >> > match any namespace; i.e., treat "foo" as syntactic sugar for
> 
> > >> > "local-name(.) = 'foo'".  ("*:foo" is not legal...)
> 
> > >> 
> 
> > >> Hmm, I think this is a bad idea because it departs even further from the
> original XPath semantics. Such chameleon names should IMO be pretty rare, and
> if they are needed, local-name() is always available.
> 
> > >> 
> 
> > >> [Qin]: Agree with Lada, Referencing RFC8407, section 4.6.2, I think the
> below guideline is relevant.
> 
> > >> "
> 
> > >> The "local-name" function SHOULD NOT be used to reference local names
> 
> > >>    outside of the YANG module that defines the must or when expression
> 
> > >>    containing the "local-name" function.  Example of a "local-name"
> 
> > >>    function that should not be used:
> 
> > >> 
> 
> > >>       /*[local-name()='foo']
> 
> > >
> 
> > > This guideline is for must/when expressions *within* YANG modules.
> 
> > >
> 
> > > I'm talking about a different use case, namely filtering.  It is
> 
> > > pretty convenient for users to send a filter:
> 
> > >
> 
> > >   /interfaces/interface[name='eth0'/ipv4
> 
> > 
> 
> > This is impossible if we want to call it XPath. With an explicit
> 
> > namespace/prefix declaration, for example
> 
> > 
> 
> >   "namespace": [
> 
> >     {
> 
> >       "prefix": "if",
> 
> >       "uri": "urn:ietf:params:xml:ns:yang:ietf-interfaces",
> 
> >       "default": true
> 
> >     },
> 
> >     {
> 
> >       "prefix": "ip",
> 
> >       "uri": "urn:ietf:params:xml:ns:yang:ietf-ip"
> 
> >     }
> 
> >   ]
> 
> > 
> 
> > it would be
> 
> > 
> 
> >   /interfaces/interface[name='eth0']/ip:ipv4
> 
> > 
> 
> > which is not too bad either.
> 
> 
> Well, "ncc myhost --get -x /interfaces/interface[name='eth0']/ipv4" is
> a one-liner; if I also have to specify the namespace list for every
> filter, it suddenly is not that convenient.

But this is an UI issue. I am not against any aid provided by client tools, what
I am talking about is the "oficial" lexical representation of that data type,
that is also exchanged in protocols. The above expression breaks XPath rules.

Lada

> 
> 
> /martin
-- 
Ladislav Lhotka
Head, CZ.NIC Labs
PGP Key ID: 0xB8F92B08A9F76C67