The "when" and "if-feature" statements are both used to make an object conditional, but they are very different.
The "when" statement is used to make some instances of a YANG object subtree conditional,
based on values of other data in the server that can change at run-time.
container static-routes {
when "derived-from-or-self(../type, 'rt:static')" {
description
"This container is only valid for the 'static' routing
protocol.";
}
description
"Configuration of the 'static' pseudo-protocol.
Address-family-specific modules augment this node with
their lists of routes.";
}The YANG object "static-routes" is always present in the server object tree (if ietf-routing module loaded).
Data entries in the server will only have the container present if the corresponding "type" leaf is "static.
The "if-feature" statement is used to make all instances of a YANG object subtree conditional,
based on boot-time parameters that cannot be changed at run-time.
leaf default-rib {
if-feature "multiple-ribs";
type boolean;
default "true";
description
"This flag has the value of 'true' if and only if the RIB
is the default RIB for the given address family.
By default, control-plane protocols place their routes
in the default RIBs.";
}The leaf "default-rib" is only present in the server object tree if the ietf-routing module is loaded AND the "multiple-ribs" feature is supported by the server.
- If the feature is supported, then all instances of list "rib" will have this leaf present, or the default "true" will be used.
- If the feature is not supported, then no instances of list "rib" will have this leaf present, and no default value will be used.