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

From: Italo Busi <[email-masked]>
Date: Thu, 23 Sep 2021 16:56:19 +0000

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

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