Subject: [netmod] YANG 'when' with absolute path

From: tom petch <[email-masked]>
Date: Thu, 30 Dec 2021 12:29:38 +0000

Any one of many, many YANG modules from such as TEAS and CCAMP have dozens and dozens of augment, some more than a 100, almost all controlled by 'when'.  The 'when' are almost all performing the same test for a presence container for the network type but because the tree is ten deep and the augments take place at different levels and the 'when' use the relative form of the Xpath statement, then the 'when' take many different forms and it is not obvious that they are correct.

Is there a drawback to using the absolute form of the Xpath statement which would then always be the same?

Thus
           A YANG Data Model for Flexi-Grid Optical Networks
                   draft-ietf-ccamp-flexigrid-yang-11
has

       when "../../../../../../nw:network-types/tet:te-topology/"
          + "flexgt:flexi-grid-topology" {
       when "../../../../../nw:network-types/tet:te-topology/"
          + "flexgt:flexi-grid-topology" {
       when "../../../../nw:network-types/tet:te-topology/"
          + "flexgt:flexi-grid-topology" {

which could be 
       when "/nw:networks/nw:network/nw:network-types"
          + "/tet:te-topology/flexgt:flexi-grid-topology" {

if I understand aright.

Tom Petch

---

From: Martin Björklund <[email-masked]>
Date: Thu, 30 Dec 2021 14:24:25 +0100 (CET)

Hi,

>           + "/tet:te-topology/flexgt:flexi-grid-topology" {

This is not the same as the relative paths, since "nw:network" is a
list.  If there is one network with
nw:network-types/tet:te-topology/flexgt:flexi-grid-topology set, then
this expression always returns true!

/martin

> 
> if I understand aright.
> 
> Tom Petch
> _______________________________________________
> netmod mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/netmod

---

From: tom petch <[email-masked]>
Date: Thu, 30 Dec 2021 16:18:59 +0000

From: Martin Björklund <[email-masked]>
Sent: 30 December 2021 13:24

Hi,

<tp>
Martin

Aah shucks; thank you for putting me right.  I thought it was too obvious not to have been raised by a YANG Doctor previously:-(

/martin

---

From: Carsten Bormann <[email-masked]>
Date: Thu, 30 Dec 2021 17:49:10 +0100

On 2021-12-30, at 13:29, tom petch <[email-masked]> wrote:
> 
>       when "../../../../../../nw:network-types/tet:te-topology/“

I’m probably showing my ignorance about YANG again, but what is the reason this is not phrased as

      when "./ancestor::nw:network-types/tet:te-topology/“

?

Grüße, Carsten

---

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 31 Dec 2021 11:01:15 +0100

>       when "./ancestor::nw:network-types/tet:te-topology/“

Yes, this would work, with a minor correction:

    when "./ancestor::node()/nw:network-types/tet:te-topology"

because 'nw:network-types' isn't an ancestor of the context node. Also, the initial './' isn't actually needed, hence

    when "ancestor::node()/nw:network-types/tet:te-topology"

Lada

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

---

From: Andy Bierman <[email-masked]>
Date: Fri, 31 Dec 2021 07:38:31 -0800

>     when "./ancestor::node()/nw:network-types/tet:te-topology"

This is not equivalent to the original expression.

The ".."  location step stands for parent::node().
The node match has to occur at a specific ancestor level.

But "ancestor::node()" will match any ancestor node.

Andy

> because 'nw:network-types' isn't an ancestor of the context node. Also,
> the initial './' isn't actually needed, hence
>

---

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 31 Dec 2021 17:32:32 +0100

On 31. 12. 21 16:38, Andy Bierman wrote:
> 
> 
> On Fri, Dec 31, 2021 at 2:01 AM Ladislav Lhotka <[email-masked] 
> <mailto:[email-masked]>> wrote:
> 
>     Carsten Bormann <[email-masked] <mailto:[email-masked]>> writes:
> 
>      > On 2021-12-30, at 13:29, tom petch <[email-masked]
>     <mailto:[email-masked]>> wrote:
>      >>

It is not equivalent but will work fine in this case because there is 
only one ancestor having a 'nw:network-types' child. Unlike the absolute 
path, one is confined to the same 'nw:network' entry here.

It means slightly more work for an XPath processor but is IMO 
considerably more readable and less error-prone.

Lada

>     because 'nw:network-types' isn't an ancestor of the context node.
>     Also, the initial './' isn't actually needed, hence
> 
>      > [email-masked] <mailto:[email-masked]>
>     <https://www.ietf.org/mailman/listinfo/netmod>
> 
>     -- 
>     Ladislav Lhotka
>     Head, CZ.NIC Labs
>     [email-masked] <mailto:[email-masked]>
>     <https://www.ietf.org/mailman/listinfo/netmod>
> 
>

---

From: Carsten Bormann <[email-masked]>
Date: Fri, 31 Dec 2021 19:18:08 +0100

On 2021-12-31, at 17:32, Ladislav Lhotka <[email-masked]> wrote:
> 
> It means slightly more work for an XPath processor but is IMO considerably more readable and less error-prone.

The original phrasing with ../../../../../ etc. is in conflict with the powerful maxim “let the computer do the counting” (remember 12HHello World in FORTRAN?).

We had the same “relative-path” disease with the original use of (non-standard) relative JSON pointers in SDF.  Going to (the standard) absolute ones helped a lot, but actually finding the right node would be even better — can’t be done in RFC 6901 JSON Pointers though.

So my brain was just activated to this anti-pattern, and since XPath is infinitely more powerful than JSON Pointer, I just wanted to know how to avoid it.  Thank you!

Grüße, Carsten

---

From: Andy Bierman <[email-masked]>
Date: Fri, 31 Dec 2021 12:28:13 -0800

On Fri, Dec 31, 2021 at 10:18 AM Carsten Bormann <[email-masked]> wrote:

> The original phrasing with ../../../../../ etc. is in conflict with the
> powerful maxim “let the computer do the counting” (remember 12HHello World
> in FORTRAN?).
>
> We had the same “relative-path” disease with the original use of
> (non-standard) relative JSON pointers in SDF.  Going to (the standard)
> absolute ones helped a lot, but actually finding the right node would be
> even better — can’t be done in RFC 6901 JSON Pointers though.
>
> So my brain was just activated to this anti-pattern, and since XPath is
> infinitely more powerful than JSON Pointer, I just wanted to know how to
> avoid it.  Thank you!
>
>

IMO it is not safe to assume that the correct node will be selected
using the "ancestor" axis.

However the use of relative paths within groupings is probably worse.

Perhaps "Relocatable Groupings" is a feature already on the yang-next
wishlist?

Implicit node-set conversions and other XPath corner-cases can be less safe
than relative-expr and equality-expr expressions that compare a value
to a node-set.

 XPath is quite happy to accept an expression and do the totally wrong
thing.
(It's called robustness :-)

As Martin pointed out, relative paths are usually required for
testing a constraint within one list entry.

Andy