Re: [netmod] xpath expressions in JSON

Robert Wilton <rwilton@cisco.com> Thu, 11 October 2018 09:46 UTC

Return-Path: <rwilton@cisco.com>
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 84B23130DD0 for <netmod@ietfa.amsl.com>; Thu, 11 Oct 2018 02:46:19 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -14.5
X-Spam-Level:
X-Spam-Status: No, score=-14.5 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIMWL_WL_MED=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_HI=-5, SPF_PASS=-0.001, URIBL_BLOCKED=0.001, USER_IN_DEF_DKIM_WL=-7.5] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (1024-bit key) header.d=cisco.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 on46jkPZqqeE for <netmod@ietfa.amsl.com>; Thu, 11 Oct 2018 02:46:14 -0700 (PDT)
Received: from aer-iport-3.cisco.com (aer-iport-3.cisco.com [173.38.203.53]) (using TLSv1.2 with cipher DHE-RSA-SEED-SHA (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 04554130E1C for <netmod@ietf.org>; Thu, 11 Oct 2018 02:46:13 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=24568; q=dns/txt; s=iport; t=1539251174; x=1540460774; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to; bh=jTrVnBnal4XyAVI2DW65oQJAkhqnNqfpC4CqtjbdHwc=; b=ZNFDNWEUSZcw4vCzN+kw9APe2NeiuHPXgTmj9oU4eKZgnn+lI1fJuR4U c7HbWS2SLoLfDv5EfGH9AO7yczT454OYKKUUM1bB0nyBXOJpbs0DYdkUk pyUov+KL1MvS4TVZ9aOQnXq36H1VtjDKwcOl5gMMtMTnOZnRzpcDUsRwC 4=;
X-IronPort-Anti-Spam-Filtered: true
X-IronPort-Anti-Spam-Result: A0BCAACBGr9b/xbLJq0YAUAKGQEBAQEBAQEBAQEBAQcBAQEBAQGBZQKCaH8og3WIdY0/JZh6DRgBCoQDRgKEdTgWAQMBAQIBAQJtHAyFOgEBAQMBASEERwsQCQIYIAcDAgInHxEGAQkDBgIBAReDBQGCAQ+IboFCm017Mx+EWIRfBYtcgUE/gTkMgl+DGwEBgTYVgxeCVwKIPYV2j10JkE4GF4FPh1aGbIkUhkqGNIFZIYFVMxoIGxU7gmyBdokhhT8+MIxhAQE
X-IronPort-AV: E=Sophos;i="5.54,368,1534809600"; d="scan'208,217";a="7098672"
Received: from aer-iport-nat.cisco.com (HELO aer-core-3.cisco.com) ([173.38.203.22]) by aer-iport-3.cisco.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2018 09:46:11 +0000
Received: from [10.63.23.158] (dhcp-ensft1-uk-vla370-10-63-23-158.cisco.com [10.63.23.158]) by aer-core-3.cisco.com (8.15.2/8.15.2) with ESMTP id w9B9kBkq029336; Thu, 11 Oct 2018 09:46:11 GMT
To: Andy Bierman <andy@yumaworks.com>, Martin Bjorklund <mbj@tail-f.com>
Cc: NetMod WG <netmod@ietf.org>
References: <20181010.155915.278994099457235212.mbj@tail-f.com> <3B614CF4-9545-4C31-BEF4-CDFBF72AA045@cisco.com> <CABCOCHT32pSP3raNj6pP3BY9ji4DnOoOAaKVY7QyfV4tqqp9KA@mail.gmail.com> <20181011.083904.763170181197608903.mbj@tail-f.com> <CABCOCHQ58Z0TpVLGVcw_TT-OG+1pWQERyCnU7NFO_Gob7JLLcA@mail.gmail.com>
From: Robert Wilton <rwilton@cisco.com>
Message-ID: <7fe38670-7275-b99c-5e80-cb0243f1dd43@cisco.com>
Date: Thu, 11 Oct 2018 10:46:11 +0100
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1
MIME-Version: 1.0
In-Reply-To: <CABCOCHQ58Z0TpVLGVcw_TT-OG+1pWQERyCnU7NFO_Gob7JLLcA@mail.gmail.com>
Content-Type: multipart/alternative; boundary="------------13133C8EBC547982A0C6732D"
Content-Language: en-US
X-Outbound-SMTP-Client: 10.63.23.158, dhcp-ensft1-uk-vla370-10-63-23-158.cisco.com
X-Outbound-Node: aer-core-3.cisco.com
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/dWT-HXizoJdsHQsmsHtut1Z-ftw>
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: Thu, 11 Oct 2018 09:46:20 -0000


On 11/10/2018 10:21, Andy Bierman wrote:
>
>
> On Wed, Oct 10, 2018 at 11:39 PM, Martin Bjorklund <mbj@tail-f.com 
> <mailto:mbj@tail-f.com>> wrote:
>
>     Andy Bierman <andy@yumaworks.com <mailto:andy@yumaworks.com>> wrote:
>     > On Wed, Oct 10, 2018 at 6:59 PM, Reshad Rahman (rrahman)
>     <rrahman@cisco.com <mailto:rrahman@cisco.com>>
>     > wrote:
>     >
>     > > On 2018-10-10, 9:59 AM, "netmod on behalf of Martin Bjorklund" <
>     > > netmod-bounces@ietf.org <mailto:netmod-bounces@ietf.org> on
>     behalf of mbj@tail-f.com <mailto:mbj@tail-f.com>> wrote:
>     > >
>     > >     Ladislav Lhotka <lhotka@nic.cz <mailto:lhotka@nic.cz>> wrote:
>     > >     > Martin Bjorklund <mbj@tail-f.com
>     <mailto:mbj@tail-f.com>> writes:
>     > >     >
>     > >     > > Hi,
>     > >     > >
>     > >     > > While reviewing restconf-notif, I saw this example:
>     > >     > >
>     > >     > >    {
>     > >     > >       "ietf-subscribed-notifications:input": {
>     > >     > >          "stream": "NETCONF",
>     > >     > >          "stream-xpath-filter": "/ds:foo/",
>     > >     > >          "dscp": "10"
>     > >     > >       }
>     > >     > >    }
>     > >     > >
>     > >     > > Note the "stream-xpath-filter". It has a prefix in the
>     XPath
>     > > string.
>     > >     > > How are prefixes declared when JSON is used?
>     > >     > >
>     > >     > > The leaf "stream-xpath-filter" says:
>     > >     > >
>     > >     > >               o  The set of namespace declarations are
>     those in
>     > > scope on
>     > >     > >                  the 'stream-xpath-filter' leaf element.
>     > >     > >
>     > >     > > (I think I provided that text...)
>     > >     > >
>     > >     > > This assumes that the encoding is XML, or at leas that
>     the encoding
>     > >     > > can somehow transfer namespace declarations.
>     > >     >
>     > >     > It can't. There are two options:
>     > >     >
>     > >     > 1. have different representations of this value in XML
>     and JSON,
>     > >     >    analogically to instance indentifiers (sec. 6.11 in
>     RFC 7951).
>     > >     >
>     > >     > 2. use a module name rather than a prefix in XML, too.
>     > >     >
>     > >     > I would suggest #2.
>     > > <RR> But that means making non-backwards compatible change to
>     the XML
>     > > representation?
>     > >
>     >
>     > Not really. It means NETMOD WG would be creating its own special
>     variant of
>     > XPath.
>
>     Not at all.  What I propose is perfectly fine, legal XPath 1.0.
>
>     XPath 1.0 says that an XPath expression is evaluated in a context.
>     One item in the context is a set of mappings from <prefix> to <uri>,
>     where <prefix> is used to lookup prefixes used in the XPath
>     expression, e.g. in "/foo:interfaces" "foo" is the prefix.
>
>     It is perfectly fine to say that the prefix mapping set is this:
>
>        "ietf-interfaces" -> "urn:ietf:params:xml:ns:yang:ietf-interfaces"
>        "ietf-ip"         -> "urn:ietf:params:xml:ns:yang:ietf-ip"
>
>     and use that to evaluate the expression
>
>       /ietf-interfaces:interfaces/ietf-interfaces:interface/ietf-ip/ipv4
>
>
>
>
> The XPath expression is normally parsed within an XML instance document.
> There are "xmlns" attributes present that map the prefix to a 
> namespace URI.
> These mappings will not be present in the JSON at all.
>
> A custom XPath implementation is required to magically identify the prefix
> as a module name and magically find the namespace URI for the module name.
> A normal XPath implementation will not find any namespace mapping for 
> the prefixes.
>
> An XPath expression has no concept of the "current module" inherited 
> from the parent
> like the JSON encoding. This is problematic for predicates
>
>    /ietf-interfaces:interfaces/interface[name='eth0']
>
> XPath says the missing prefixes for 'interface' and 'name' are simply 
> missing (no namespace).
> The JSON encoding says "ietf-interfaces" is used for 'interfaces'. and 
> 'interface'.
> There is no specification for the 'name' node inside a predicate.
>
> So you must mean the full module name will be used at every node:
>
>  /ietf-interfaces:interfaces/ietf-interfaces:interface[ietf-interfaces:name='eth0']
Hum, that is going to make these expressions very long, and not 
particularly human readable.

The XPath 1.0 spec that YANG using is effectively obsoleted by newer 
(much more complex) versions.  I doubt that this will be liked, but my 
view is that the longer term solution here is for a bespoke "YANG Path" 
language to be specified, closely based on XPath 1.0, but fixing some of 
the issues that we have using XPath for YANG constraints (e.g. it is 
easy to get them wrong), and removing some of stuff that isn't helpful 
(e.g. node tests, processing instructions, etc).

Thanks,
Rob


>
>
>
>
>     /martin
>
>
> Andy
>
>
>     >
>     >
>     > >     Hmm, so you mean change the leaf "stream-xpath-filter" to say:
>     > >
>     > >              o  The set of namespace declarations has one
>     member for each
>     > >                 YANG module supported by the server.  This
>     member maps
>     > >                 from the YANG module name to the YANG module
>     namespace.
>     > >
>     > >                 This means that in the XPath expression, the
>     module name
>     > >                 serves as the prefix.
>     > >
>     > >     .... and then also give an example of this.
>     > >
>     > >     This is probably what we need to do in all places where
>     yang:xpath1.0
>     > >     is used, going forward.  Maybe even define a new type
>     > >     yang:xpath1.0-2 (name?) with the set of namespace declarations
>     > >     built-in.
>     > >
>     >
>     >
>     > We should avoid making off-the-shelf implementations of
>     standards like
>     > XPath unusable.
>     > At the very least this should be only available if the server
>     supports it
>     > (with a capability URI)
>     >
>     >
>     >
>     > > <RR> So we need an update to RFC7951?
>     > >
>     > > Regards,
>     > > Reshad.
>     > >
>     > >
>     >
>     > Andy
>     >
>     >
>     > >
>     > >     /martin
>     > >
>     > >
>     > >
>     > >
>     > >
>     > >     >
>     > >     > Lada
>     > >     >
>     > >     > >
>     > >     > > How is this supposed to work with JSON?
>     > >     > >
>     > >     > >
>     > >     > > /martin
>     > >     > >
>     > >     > > _______________________________________________
>     > >     > > netmod mailing list
>     > >     > > netmod@ietf.org <mailto:netmod@ietf.org>
>     > >     > > https://www.ietf.org/mailman/listinfo/netmod
>     <https://www.ietf.org/mailman/listinfo/netmod>
>     > >     >
>     > >     > --
>     > >     > Ladislav Lhotka
>     > >     > Head, CZ.NIC Labs
>     > >     > PGP Key ID: 0xB8F92B08A9F76C67
>     > >     >
>     > >
>     > >     _______________________________________________
>     > >     netmod mailing list
>     > > netmod@ietf..org <mailto:netmod@ietf.org>
>     > > https://www.ietf.org/mailman/listinfo/netmod
>     <https://www.ietf.org/mailman/listinfo/netmod>
>     > >
>     > >
>     > > _______________________________________________
>     > > netmod mailing list
>     > > netmod@ietf.org <mailto:netmod@ietf.org>
>     > > https://www.ietf.org/mailman/listinfo/netmod
>     <https://www.ietf.org/mailman/listinfo/netmod>
>     > >
>
>
>
>
> _______________________________________________
> netmod mailing list
> netmod@ietf.org
> https://www.ietf.org/mailman/listinfo/netmod