Hello,
I’m looking for some help/advice on how to reference a choice in YANG.
I have a two containers “elements” and “sub-elements” each containing a list (element-instance and sub-element-instance). Each element must be of a type (choice elemnent–type), and each sub-element must belong to an existing element and has different attributes depending on which element it belongs to.
For each sub-element, I have defined a “belongs-to-element-name” and “belongs-to-element-type” leafs and I need to constrain these to values based on the existing elements.
It seems that I cannot use a leafref or a must statement to constrain the value of the “belongs-to-element-type” leaf to whatever choice was made in the elements list. (Note: I need to use the choice in both containers as in my model each choice case calls other modules and attributes through a uses statement).
I have attached a sample use-case below. Any suggestions on how to make this work?
Thanks,
Mariusz
SAMPLE YANG USE-CASE:
container configuration {
list configuration-branch {
key "key-1 key-2 key-3 key-4 key-5 key-6";
leaf key-1 {type string;}
leaf key-2 {type string;}
leaf key-3 {type string;}
leaf key-4 {type string;}
leaf key-5 {type string;}
leaf key-6 {type string;}
container elements {
list element-instance {
key element--name;
leaf element--name {type string;}
choice element--type {
case element-type-1 {
leaf element-type-1-attribute {type string;}
}
case element-type-2 {
leaf element-type-2-attribute {type string;}
}
case element-type-3 {
leaf element-type-3-attribute {type string;}
}
case element-type-4 {
leaf element-type-4-attribute {type string;}
}
}
}
}
container sub-elements {
list sub-element-instance {
key sub-element--name;
leaf sub-element--name {type string;}
leaf belongs-to-element-name {
type leafref {
path "../../../../configuration-branch"
+ "[key-1=current()/../../../key-1][key-2=current()/../../../key-2][key-3=current()/../../../key-3]"
+ "[key-4=current()/../../../key-4][key-5=current()/../../../key-5][key-6=current()/../../../key-6]"
+ "/elements/element-instance/element--name";
}
}
leaf belongs-to-element-type {
type leafref {
path "../../../../configuration-branch"
+ "[key-1=current()/../../../key-1][key-2=current()/../../../key-2][key-3=current()/../../../key-3]"
+ "[key-4=current()/../../../key-4][key-5=current()/../../../key-5][key-6=current()/../../../key-6]"
+ "/elements/element-instance[name=current()/../belongs-to-element-name]/element--type";
}
must "../belongs-to-subsystem-type=../subsystem--type";
}
choice element--type {
case element-type-1 {
leaf element-type-1-sub-element-attribute {type string;}
}
case element-type-2 {
leaf element-type-2-sub-element-attribute {type string;}
}
case element-type-3 {
leaf element-type-3-sub-element-attribute {type string;}
}
case element-type-4 {
leaf element-type-4-sub-element-attribute {type string;}
}
}
}
}
}
}