I am in the process of learning OpenDayLight and Yang and can't figure out how to put a constraint on a leaf node. I have a leaf node (vpn-id). When the l3vpn-type node equals 'bgp', I want data for this one to be allowed for vpn-id. If the leaf node does not equal 'bgp' and the vpn-id is entered I want to throw an error. I have tested this in OpenDayLight and it always allows me to save the data no matter what the data has in it.
Also, I am having a hard time finding Yang examples so I can teach myself. Suggestions are welcome.
module DaveTest {
namespace "urn:aaa:ddd:DaveTest";
prefix dave-module;
description "Dave testing file";
revision "2017-04-17" {
description "Initial version.";
}
container testing-vars {
list test-list {
key "vpn-transaction-id l3vpn-type";
unique "vpn-transaction-id";
leaf vpn-transaction-id {
type string;
}
leaf l3vpn-type {
type enumeration {
enum "bgp";
enum "static";
enum "gre tunnel";
}
mandatory true;
}
leaf vpn-id {
when "../l3vpn-type = 'bgp'";
type string;
}
}
}