Subject: [netmod] yang nested list reference question

From: Juergen Schoenwaelder <[email-masked]>
Date: Fri, 23 Jan 2015 12:56:00 +0100

Hi,

lets say I have a list 'a' (keyed by n) with a nested list 'b' (keyed
by m):

  list a {
    key n;
    leaf n;

    list b {
      key m;
      leaf m;
    }
  }

I now want to refer to a list element of list 'b' within list 'a'.
What is the best way to express this?

I could do this:

  list c {
    key x;
    leaf x;

    leaf aref { type leafref { path /a/n; } }
    leaf bref { type leafref { path /a/b/m; } }
  }

  What is the best way to constrain the leafrefs so that they are
  forced to point to a 'b' within an 'a' element?

Alternatively, I could consider using an instance-identifier:

  list c {
    key x;
    leaf x;

    leaf bref { type instance-identifier; }
  }

  What is the best way to restrict the instance-identifier so that it
  has to point to a 'b' element?

Are there other approaches?

I think this is a rather common modeling problem and perhaps we can
come up with a best practice pattern for this? If so, I am happy to
add it to my pattern collection I-D.

/js

-- 
Juergen Schoenwaelder           Jacobs University Bremen gGmbH
Phone: +49 421 200 3587         Campus Ring 1, 28759 Bremen, Germany
Fax:   +49 421 200 3103         <http://www.jacobs-university.de/>

---

From: Martin Bjorklund <[email-masked]>
Date: Fri, 23 Jan 2015 13:06:48 +0100 (CET)

>   forced to point to a 'b' within an 'a' element?

 leaf bref {
   type leafref {
     path "/a[n = current()/../aref]/b/m";
   }
 }

Note that this special syntax with current() is allowed by a leafref;
and the reason is to handle this common use case.

See RFC 6020, section 9.9.5.

With a third key (and more), this syntax still works, but gets
clumsy.  This is why I have suggested to use:

   path "deref(../aref)/../b/m";

as an optional syntax to leafref path.

/martin