Re: [netmod] xpath expressions in JSON

Andy Bierman <andy@yumaworks.com> Thu, 11 October 2018 16:25 UTC

Return-Path: <andy@yumaworks.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 42299130EA6 for <netmod@ietfa.amsl.com>; Thu, 11 Oct 2018 09:25:28 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -1.899
X-Spam-Level:
X-Spam-Status: No, score=-1.899 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=yumaworks-com.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 KOBMC42wtBYp for <netmod@ietfa.amsl.com>; Thu, 11 Oct 2018 09:25:24 -0700 (PDT)
Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) (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 EB7AC130E96 for <netmod@ietf.org>; Thu, 11 Oct 2018 09:25:23 -0700 (PDT)
Received: by mail-lf1-x12b.google.com with SMTP id w21-v6so7146626lff.6 for <netmod@ietf.org>; Thu, 11 Oct 2018 09:25:23 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yumaworks-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=jYaUGPxdFsVirh2FyUGluNyoIGiBVdpZW3wS9EguPzM=; b=jSV8xD+PmiEvuz0dYIiCfJN0bhvZiZ1KenyQaaIjP2Xrk5JN32FXHtuy83YSGEOp60 WtaPgdvwNWnuL3NYLSIdAFu4kbAvLodJuhjWNa8srEMDfPWFDKqKtTkxxn93QZmdNCDR FzqrphKd4zC6attl9qi6OJYx3oYy5ntbJPv3tG/8ZWE7konw3Z1k6psq0rhSBW27apk2 jUpsYBdW2hcBght92H9JfN44V+twYiiu/yf0vZ4mfSYNPpz0vpoKMGg/mXJngMjYoz+R v9M4fz9u4wuM5oV/68PGr/fUMvu5Vfvd0g+FS3LD7GfujJ/AnAwflggdSHK/17X+tcWb ZdLg==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=jYaUGPxdFsVirh2FyUGluNyoIGiBVdpZW3wS9EguPzM=; b=Zyg/a7rJxbCZ1JIml1lsgPTdkQXu5DDbL/s4JCjw/Iw7DvRoJLhkx64s/OfBuoQILK bIlslbKauBT99J8Azq0A5C1qt3EUp3y59ZbHm5wbn9vZfWa5s7PbLGrvoQtXzCJhPpi3 GnqHkqanqEUuLi4Es53W8wm7UcSSHAAOYhtGfwtB3cqxFEDbwQMllGKj6RtdGIrbVSSp gs0OvjqHuLUTHpCL8kHQT8tA5Ugq8X1YmGVoTz5EUd6n3VQIVu/5lo773r6DKI1VGp2Y 8MpZUCp+HIApunV+z1Og0q+YtNlNfbbKzKlP5p5lLuYV843lwnrrtwia79VFF+TEhQvh /H/A==
X-Gm-Message-State: ABuFfoiMtROF9vHygYtOOs42R/aPLEg6PhoVq6fQFKTHFMMwTLr4sB82 9ljdwBCKugLidY2JrdS0p1bf9DWl6JqHrSFpvo287g==
X-Google-Smtp-Source: ACcGV63VFtY7n+xDdPvWVJ5XYTdLqqzwCtEZ3boZQ8USMN6KXg5UpnjEEo2Wcb5ylL/XLwZDd/GiBxWAT4VGbX94vEA=
X-Received: by 2002:a19:7709:: with SMTP id s9-v6mr1596145lfc.84.1539275121876; Thu, 11 Oct 2018 09:25:21 -0700 (PDT)
MIME-Version: 1.0
Received: by 2002:a19:f811:0:0:0:0:0 with HTTP; Thu, 11 Oct 2018 09:25:20 -0700 (PDT)
In-Reply-To: <20181011.181652.1065283062766537981.mbj@tail-f.com>
References: <7a9b1a5f-db66-7431-a2c7-82acebb2082b@cisco.com> <BE8F576F-2A56-44D8-8554-6576B9CDB0F8@cisco.com> <b84a4e2d-0f63-6b53-3dcc-70bf9ad96cbd@cisco.com> <20181011.181652.1065283062766537981.mbj@tail-f.com>
From: Andy Bierman <andy@yumaworks.com>
Date: Thu, 11 Oct 2018 09:25:20 -0700
Message-ID: <CABCOCHSoxR5ys8i2EtyZEwsYohm_c7kidwDjDnqBZGNKgOiK+A@mail.gmail.com>
To: Martin Bjorklund <mbj@tail-f.com>
Cc: Robert Wilton <rwilton@cisco.com>, NetMod WG <netmod@ietf.org>
Content-Type: multipart/alternative; boundary="000000000000d9f63c0577f66a9c"
Archived-At: <https://mailarchive.ietf.org/arch/msg/netmod/6XR2LNILiutWMF4_fzLIVVOLhek>
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 16:25:28 -0000

On Thu, Oct 11, 2018 at 9:16 AM, Martin Bjorklund <mbj@tail-f.com> wrote:

> Robert Wilton <rwilton@cisco.com> wrote:
> > Hi Reshad,
> >
> > Please see RW: inline.
> >
> >
> > On 11/10/2018 16:34, Reshad Rahman (rrahman) wrote:
> > >
> > > Hi Rob,
> > >
> > > *From: *netmod <netmod-bounces@ietf.org> on behalf of "Robert Wilton
> -X
> > > *(rwilton - ENSOFT LIMITED at Cisco)" <rwilton@cisco.com>
> > > *Date: *Thursday, October 11, 2018 at 7:17 AM
> > > *To: *Martin Bjorklund <mbj@tail-f.com>
> > > *Cc: *"netmod@ietf.org" <netmod@ietf.org>
> > > *Subject: *Re: [netmod] xpath expressions in JSON
> > >
> > > On 11/10/2018 11:50, Martin Bjorklund wrote:
> > >
> > >     Robert Wilton <rwilton@cisco.com><mailto:rwilton@cisco.com>wrote:
> > >
> > >         On 11/10/2018 11:21, Martin Bjorklund wrote:
> > >
> > >             Andy Bierman
> > >             <andy@yumaworks.com><mailto:andy@yumaworks.com>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.
> > >
> > >             I disagree.  You need an XPath implementation + custom
> > >             code to set up
> > >
> > >             the environment.
> > >
> > >         This is OK, but can we just use the JSON encoding instance
> > >         identifier
> > >
> > >         format exactly?  I.e .RFC 7951 section 6.11.
> > >
> > >         So "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/
> enabled"
> > >
> > >         can trivially be expanded to:
> > >
> > >         "/ietf-interfaces:interfaces/ietf-interfaces:interface/
> ietf-ip:ipv4/ietf-ip:enabled",
> > >
> > >         and then interpreted with the context:
> > >
> > >              "ietf-interfaces" ->
> > >         "urn:ietf:params:xml:ns:yang:ietf-interfaces"
> > >
> > >            "ietf-ip"         -> "urn:ietf:params:xml:ns:yang:ietf-ip"
> > >
> > >     *this* would require a custom XPath implementation.
> > >
> > > Why?  I.e. how is this different from stating "Custom code is needed
> > > to connect things together"?
> > >
> > >
> > >     and it is not obvious what the rules for the "auto-assignment" of
> > >
> > >     prefixes would be.  For example:
> > >
> > >       /ietf-interfaces//ietf-ip:address[../foo]
> > >
> > >     what is the prefix for "foo"?
> > >
> > > OK, so here the module for "../foo" would need to be specified.
> > >
> > > Perhaps the rule that I'm looking for is the module name may be
> > > omitted when it matches the parent node module, and can easily be
> > > inferred.  I.e. so that for any XPath string, it is possible to
> > > trivially expand it without any additional schema context.
> > >
> > > It just seems to be that requiring the long hand of
> > > "/ietf-interfaces:interfaces/ietf-interfaces:interface/
> ietf-ip:ipv4/ietf-ip:enabled"
> > > seems like it will get very verbose, and I wonder whether we are
> > > introducing yet another Xpath format to YANG.
> > > <RR> I’m willing to live with verbosity if it avoids the need of
> > > another format.
> > >
> > RW:
> >
> > This is already looks like another format:
>
> Again, it is *not* another format!
>
>
> >
> > Xpath filters used in Netconf use explicit namespaces, e.g. rfc6241
> > sec 8.9.5.1
> >
> >          <filter xmlns:t="http://example.com/schema/1.2/config"
> >                  type="xpath"
> >                  select="/t:top/t:users/t:user[t:name='fred']"/>
> >         </get-config>
>
> In this case, the prefix-string -> uri mapping is taken from the XML
> namespace declaration in the XML document.
>
>
> > The standard JSON encoding for instance-data (IIRC, the same scheme is
> > used for CBOR) uses the module-name but omits it where it matches the
> > parent (e.g.
> >
> > "/ietf-interfaces:interfaces/interface/ietf-ip:ipv4/enabled")
>
> Do you mean instance-identifier?  If so, it is a special type that
> happens to share the syntax with XPath, and the JSON syntax is defined
> in RFC 7951 section 6.11.
>
> >
> > RFC 8040 query parameter is as described below, but having looked at
> > the examples I'm not really sure how that is meant to work :-)
>
> In this case, the prefix-string -> uri mapping is given in the
> document.
>
>
> We use XPath in various different places, and each place MUST specify
> the evaluation context.
>
>

You are right.
Our custom XPath code needs to be told to get prefix mappings from XML or
YANG import-stmts
already, so 1 more internal mapping directly to module name is not going to
require
any significant changes to XPath processing.

More importantly, it does not require any redefinition of the XPath
standard.


>
>
> /martin
>

Andy


>
>
> > > Finally, I'm trying to figure out have RFC 8040 query parameter (sect
> > > 4.8.4), which also uses XPath expressions is meant to work.  That
> > > states:
> > >
> > >
> > > 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.
> > >
> > >
> > > Yet the examples in section 8.3.6 don't seem to use namespace prefixes
> > > in very many places, e.g. why is it "/example-mod:event1/name='joe'"
> > > and not "/example-mod:event1/example-mod:name='joe'"?  Is the example
> > > wrong, or otherwise what am I missing? :-)
> > >
> > > <RR> Section 8.3.6 of which document?
> > >
> > RFC 8040.
> >
> > Thanks,
> > Rob
> >
> > > Regards,
> > >
> > > Reshad.
> > >
> > >
> > > Thanks,
> > > Rob
> > >
> > >
> > >
> > >     /martin
> > >
> > >         Thanks,
> > >
> > >         Rob
> > >
> > >             There is no standard XPath implementation that can just
> > >             take an XML
> > >
> > >             instance document + YANG module and figure out what to
> > >             do.  Custom
> > >
> > >             code is needed to connect things together.  This proposal
> > >             doesn't
> > >
> > >             change this.
> > >
> > >             /martin
> > >
> > >                 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']
> > >
> > >                     /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
> > >
> > >                                  >
> > >
> > >                                  > --
> > >
> > >                                  > 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
> > >
> > >                             ______________________________
> _________________
> > >
> > >                             netmod mailing list
> > >
> > >                             netmod@ietf.org<mailto:netmod@ietf.org>
> > >
> > >                             https://www.ietf.org/mailman/
> listinfo/netmod
> > >
> > >             _______________________________________________
> > >
> > >             netmod mailing list
> > >
> > >             netmod@ietf.org<mailto:netmod@ietf.org>
> > >
> > >             https://www.ietf.org/mailman/listinfo/netmod
> > >
> > >             ..
> > >
> > >     .
> > >
> > >
> > >
> >
> _______________________________________________
> netmod mailing list
> netmod@ietf.org
> https://www.ietf.org/mailman/listinfo/netmod
>