Subject: Re: [yang-doctors] Question about absolute and relative paths in YANG

From: Italo Busi <[email-masked]>
Date: Thu, 16 Dec 2021 19:19:48 +0000

Martin, Lada,

Thanks a lot for your answer

Another concerns we had is that using relative paths within a grouping would  make quite difficult to re-use this grouping in multiple places within the YANG tree but we are not sure there is any work-around to avoid this

What do you think/suggest?

Italo

> -----Original Message-----
> From: Ladislav Lhotka [mailto:[email-masked]]
> Sent: martedì 16 novembre 2021 07:27
> To: Martin Björklund <[email-masked]>; Italo Busi <[email-masked]>
> Cc: [email-masked]; Zhenghaomian <[email-masked]>;
> [email-masked]
> Subject: Re: [yang-doctors] Question about absolute and relative paths in
> YANG
> 
> On 15. 11. 21 17:55, Martin Björklund wrote:
> > Hi,
> >
> > Italo Busi <[email-masked]> wrote:
> >> Any feedbacks/comments about this question?
> >>
> >> Thanks, Italo
> >>
> >> From: Italo Busi
> >> Sent: giovedì 23 settembre 2021 18:56
> >> To: [email-masked]
> >> Cc: Zhenghaomian <[email-masked]>; 'Aihua Guo'
> >> <[email-masked]>
> >> Subject: Question about absolute and relative paths in YANG
> >>
> >> Hi YANG doctors,
> >>
> >> I am quite active within the IETF CCAMP and TEAS WGs on YANG models
> >> for optical transport networks
> >>
> >> We are having some discussions about the use of absolute and relative
> >> paths in some of the drafts we are developing for IETF
> >>
> >> I have been told that YANG doctors prefer absolute paths to relative
> >> paths
> >
> > I don't recognize this preference.  Also I don't know if you refer to
> > XPath paths in must/when or something else.  I assume you mean XPath
> > paths.
> 
> It's a mystery to me how such myths can ever arise. :-)
> 
> >
> > IMO, a short relative path is often easier to read and understand, and
> > easier to get right.  In some cases it truly doesn't matter, and in
> > some other cases you must use one and not the other.
> >
> > In the examples below, I'd use a relative path.
> 
> +1
> 
> Lada
> 
> >
> >
> > /martin
> >
> >
> >
> >> We think it makes a lot of sense to use absolute paths whenever
> >> possible but there are some cases where we are not sure whether and
> >> how we could use absolute paths
> >>
> >> We would appreciate your opinions and suggestions about how to
> >> address these cases
> >>
> >> One case could be one of the augment statements defined in RFC8795
> >> (TE Topology model):
> >>
> >>    augment "/nw:networks/nw:network/nw:node/tet:te/"
> >>          + "tet:te-node-attributes/tet:connectivity-matrices/"
> >>          + "tet:label-restrictions/tet:label-restriction" {
> >>      when "../../../../../../nw:network-types/tet:te-topology/"
> >>         + "example-topology" {
> >>
> >> The intention is to say that this augmentation applies only to a
> >> specific network-types of this network instance. Using an absolute
> >> path the code could become:
> >>
> >>    augment "/nw:networks/nw:network/nw:node/tet:te/"
> >>          + "tet:te-node-attributes/tet:connectivity-matrices/"
> >>          + "tet:label-restrictions/tet:label-restriction" { when
> >> "/nw:networks/nw:network[nw:network-
> id=current()../../../../../../nw:network-id]/"
> >>     + "nw:network-types/tet:te-topology/"
> >>         + "example-topology" {
> >>
> >> It seems that using the absolute path is moving the issue on
> >> requiring a relative path to get the value of the network-id of this
> >> network
> >>
> >> Is there an alternative solution to avoid using relative path in this
> >> case?
> >>
> >> Another case we have considered is the definition of a grouping with
> >> a leaf that references another node within the same network. In this
> >> case, using a relative path or an absolution path embedding a
> >> relative path required to get the network-id of this network, would
> >> make quite difficult to re-use this grouping in multiple places
> >> within the YANG tree
> >>
> >> One work-around could be to use the refine statement, such as:
> >>
> >> grouping node-reference {
> >>    leaf network-ref {
> >>      type leafref {
> >>        path "/nw:networks/nw:network/nw:network-id"
> >>      }
> >>    }
> >>
> >>    leaf node-ref {
> >>      type leafref {
> >>        path "deref(../network-ref)/../nw:node/nw:nw:node-id"
> >>      }
> >>    }
> >> }
> >>
> >> augment "/nw:networks/nw:network/nw:node/tet:te/"
> >>        + "tet:te-node-attributes/tet:connectivity-matrices/"
> >>        + "tet:label-restrictions/tet:label-restriction" {
> >>    uses node-reference {
> >>      refine network-ref {
> >>        default current()/../../../../../../network-id;
> >>        must current() = current()/../../../../../../network-id;
> >>     }
> >>    }
> >>
> >> This work-around seems a bit weird but at least it should the need to
> >> use relative paths within the grouping but keep the requirement to
> >> use the relative paths in the refine statements
> >>
> >> Is there a better solution to avoid using relative path within the
> >> grouping?
> >>
> >> Thanks in advance for your help
> >>
> >> Italo
> >>
> > _______________________________________________
> > yang-doctors mailing list
> > [email-masked]
> > https://www.ietf.org/mailman/listinfo/yang-doctors
> >
> 
> --
> Ladislav Lhotka
> Head, CZ.NIC Labs
> PGP Key ID: 0xB8F92B08A9F76C67

---

From: Ladislav Lhotka <[email-masked]>
Date: Fri, 17 Dec 2021 09:45:48 +0100

> What do you think/suggest?

It depends, one always has to be careful when refering to entities outside the grouping. Relative paths may actually help in reusing the grouping in different modules, if the local context is similar.

Lada