08-05-2020 10:24 AM - edited 08-05-2020 10:25 AM
Hi All,
I'm developing a service and one of the requirements is:
The primary IP address and mask is mandatory.
If the user entered the secondary IP address, then the secondary mask must be provided also.
I'm trying to implement this requirement using "when" statement but with no success. I don't know how can I do that.
The yang snippet:
list bvi { key id; uses ncs:service-data; ncs:servicepoint "bvi"; leaf id { type int32 { range "1..65535"; } mandatory true; } leaf device { type leafref { path "/ncs:devices/ncs:device/ncs:name"; } mandatory true; } leaf-list vrf-name { type leafref { path "deref(../device)/../ncs:config/ios:vrf/ios:vrf-list/ios:name"; } } leaf mtu { type int32 { range "1500..9212"; } } leaf primary-ipv4-address { type inet:ipv4-address; mandatory true; } leaf primary-mask { type inet:ipv4-address; mandatory true; } leaf secondary-ipv4-address { type inet:ipv4-address; } when "deref(../secondary-ipv4-address) != ''"; leaf secondary-mask { type inet:ipv4-address; mandatory true; } leaf ipv6-address { type inet:ipv6-address; mandatory true; } leaf mac-address { type string; default "1001.1111.1111"; } }
Can someone help me?
Thanks in advance!
Luciano Nunes
lnunesdo@cisco.com
Solved! Go to Solution.
08-05-2020 12:09 PM
You were close.
Try:
leaf secondary-mask {
when ../secondary-ipv4-address; type inet:ipv4-address; mandatory true; }
08-05-2020 12:24 PM
Hi Luciano,
You are pretty close, you need to move the when inside of the leaf that you are trying to control.
Here is a example - I just check for existence of sec-address:
leaf address {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP address";
}
mandatory true;
}
leaf mask {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP subnet mask";
}
mandatory true;
}
leaf sec-address {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP address";
}
}
leaf sec-mask {
when "../sec-address";
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP subnet mask";
}
mandatory true;
}
without specitying sec-addr, primary is successful:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0
[ok][2020-08-05 15:17:12]
If you specify sec-address, the sec-mask is mandatory:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address
Possible completions:
<A.B.C.D> - IP address
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
Possible completions:
<A.B.C.D> - IP subnet mask
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
(<A.B.C.D>): 255.255.255.0
[ok][2020-08-05 15:17:54]
08-05-2020 12:09 PM
You were close.
Try:
leaf secondary-mask {
when ../secondary-ipv4-address; type inet:ipv4-address; mandatory true; }
08-05-2020 12:24 PM
Hi Luciano,
You are pretty close, you need to move the when inside of the leaf that you are trying to control.
Here is a example - I just check for existence of sec-address:
leaf address {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP address";
}
mandatory true;
}
leaf mask {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP subnet mask";
}
mandatory true;
}
leaf sec-address {
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP address";
}
}
leaf sec-mask {
when "../sec-address";
type inet:ipv4-address {
tailf:info "A.B.C.D;;IP subnet mask";
}
mandatory true;
}
without specitying sec-addr, primary is successful:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0
[ok][2020-08-05 15:17:12]
If you specify sec-address, the sec-mask is mandatory:
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address
Possible completions:
<A.B.C.D> - IP address
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
Possible completions:
<A.B.C.D> - IP subnet mask
admin@ncs% set interface-mv if1 device iosxr-0 intf-iosxr GigabitEthernet 0/0/0/0 address 10.0.1.0 mask 255.255.255.0 sec-address 10.0.2.0 sec-mask
(<A.B.C.D>): 255.255.255.0
[ok][2020-08-05 15:17:54]
Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: