Subject: Re: [netmod] [yang-doctors] question on leafref path.

From: Martin Bjorklund <[email-masked]>
Date: Sun, 01 Mar 2015 20:41:59 +0100 (CET)

Christian Hopps <[email-masked]> wrote:
> Hi,
> 
> I need to use a “path” in a leafref to refer to a router id inside 1
> of 2 possible containers. The 2 choices are “left” or “right” sides of
> a lambda. The lambda is identified by the channel.

This is not possible in YANG 1.0.  But you can do something like this:

        list connection {
          key "channel";
          leaf channel {
            type leafref {
              path "../../../lambda/channel";
            }
          }
          choice router-id {
            leaf left-router-id {
              type leafref {
                path <path-to-left-router-id>;
              }
            }
            leaf right-router-id {
              type leafref {
                path <path-to-right-router-id>;
              }
            }
          }

In YANG 1.1 it is possible to define a union of two leafrefs.

However, in this particular case, the leaf/right leafref doesn't
really add anything, since you have just one left router-id and one
right router-id per channel, and you already have a leafref to the
channel.  Thus, all you relaly need is an indication of which router-id
to pick in the channel.  But maybe the YANG model you gave was
simplified?

/martin

> 
> I’ve tried the following with “|” (I believe this is the valid xpath)
> and “*” (a guess) and neither works.
> 
>               //path
>               "../../../lambda[channel=current()/../channel]/left/router-id |
>               ../../../lambda[channel=current()/../channel]/right/router-id”;
> 
>               path "../../../lambda[channel=current()/../channel]/*/router-id”;
> 
> If I pick “left” or “right” only it works, but that’s not what I
> need. Any help on how to do this properly?
> 
> Thanks,
> Chris.
> 
> The actual yang is below:
> 
>     list link {
>       key "link-name";
>       leaf link-name {
>         type inet:uri;
>       }
>       list lambda {
>         key "channel";
>         leaf channel {
>           type uint8;
>         }
>         container left {
>           leaf router-id {
>             type leafref {
>               path "../../../../router/router-id";
>             }
>           }
>         }
>         container right {
>           leaf router-id {
>             type leafref {
>               path "../../../../router/router-id";
>             }
>           }
>         }
>       }
>       list site {
>         key "site-id";
>         leaf site-id {
>           type inet:uri;
>         }
>         list connection {
>           key "channel";
>           leaf channel {
>             type leafref {
>               path "../../../lambda/channel";
>             }
>           }
>           // Is there a way to xpath refer to left or right containers of the
>           lambda?
>           leaf router-id {
>             type leafref {
>               //path
>               "../../../lambda[channel=current()/../channel]/left/router-id |
>               ../../../lambda[channel=current()/../channel]/right/router-id";
>               path "../../../lambda[channel=current()/../channel]/*/router-id";
>             }
>           }
>         }
>       }
> 
> _______________________________________________
> yang-doctors mailing list
> [email-masked]
> https://www.ietf.org/mailman/listinfo/yang-doctors