module myyang {
namespace "http://example.com/myyang";
prefix myyang;
import tailf-common {
prefix tailf;
}
import ietf-inet-types {
prefix inet;
}
container mycontainer {
list application {
key "name";
leaf name {
type string;
}
leaf keyname {
type leafref { path "/port-map/port12"; }
}
leaf nat {
type leafref
{ path "/port-map[port12 = current()/../keyname]/protocol/protocol-name"; }
}
leaf protocol {
type leafref
{path "/app-pc[app-pcname= /port-map[port12 = current()/../keyname]/protocol1]/pc-name"; }
}
}
}
list app-pc {
key "app-pcname";
leaf app-pcname {
type string;
}
list pc-name {
key "pc";
leaf pc {
type string;
}
}
}
list port-map {
key "port12";
leaf port12 {
type inet:port-number;
}
leaf protocol1 {
type string;
}
list protocol {
key "protocol-name";
leaf protocol-name {
type string;
}
}
}
}
When I compile I get following error any help on the same ?
[root@localhost bin]# ./confdc -c myyang.yang
myyang.yang:26: error: bad argument value "/app-pc[app-pcname= /port-map[port12 = current()/../keyname]/protocol1]/pc-name", should be of type path-arg
[root@localhost bin]#
The syntax for a path argument is a subset of the XPath abbreviated
syntax. Predicates are used only for constraining the values for the
key nodes for list entries. Each predicate consists of exactly one
equality test per key, and multiple adjacent predicates MAY be
present if a list has multiple keys. The syntax is formally defined
by the rule "path-arg" in Section 12.
I.e. the key predicates are restricted to [<key-name> = current()/…/<path-without-predicates>], which your path argument doesn’t adhere to. I’m not sure I understand exactly what you are trying to achieve, but I think it should be possible by using a simpler leafref path combined with a ‘must’ expression.
That ABNF is the whole story for YANG, but there’s more to tell for ConfD. In ConfD, we also have the deref function. So, I wonder if you can explain a bit more @per. When I read the above ABNF, I am assumign that the path-key-expr production is actually this in ConfD: