Subject: [netmod] Referencing rpc input in rpc output using YANG

From: Xiao SHI <[email-masked]>
Date: Fri, 26 Sep 2014 01:16:27 -0400

Hi all,

I was trying to reference some rpc input data in rpc output, specifically:

Suppose I have an universe of nodes {A, B, C, D, E}, and my rpc input
contains a set of nodes I care about, and I'd like to make sure that my
output (rpc response) contains only the nodes that appeared in the input. I
tried to use leafref statement to model this restriction.

Here's my YANG model:
rpc my-rpc {
  input {
    container my-set {
      leaf-list nodes {
        type node;
      }
    }
  }
  output {
    list my-output {
      leaf nodes {
        type leafref {
          path "..."; // trying to refer to the nodes leaf-list in input.
        }
      }
    }
  }
}

It doesn't seem like I am allowed to refer to an rpc leaf? (When I used
pyang to validate, it throws an error saying the path references a rpc
node.) Should I try something other than leafref? I tried to use must
statment with XPATH expression, but I couldn't find an "in" operator in
XPATH.

I am fairly new to YANG, any help would be much appreciated.

Thank you!
Xiao

---

From: Martin Bjorklund <[email-masked]>
Date: Fri, 26 Sep 2014 08:37:14 +0200 (CEST)

Hi,

> tried to use leafref statement to model this restriction.

This constraint is not possible to express formally in YANG.

The only thing you can do is document this in the description clause.

/martin

---

From: Xiao SHI <[email-masked]>
Date: Sun, 28 Sep 2014 01:43:33 -0400

Hi Martin,

Thanks for your reply!

Just out of curiosity, is there a particular reason that leafref cannot
refer to things in rpc-input? Is this a design choice? Or would this be a
future feature?

Thanks,
Xiao

---

From: "Y. Richard Yang" <[email-masked]>
Date: Sun, 28 Sep 2014 15:44:33 -0400

I can guess that YANG constraints are focused only on the consistency of
the global "universe" of data, not each transaction. Hence, if one
considers rpc as the transactions part, not the universe part, then it is a
reasonable design. Is this a right way to understand the design?

Richard