YANG constraints are used to automate the validation of complicated system configuration. All YANG constraints must be validated before a configuration change can take effect.
YANG constraints include:
Must statements (referential integrity)
When statements (conditional data nodes)
Leafref statements (cross references)
Below are some examples of YANG constraints using the ietf-interface YANG module from RFC 7223.
This module can be augmented by the module ex-vlan.yang found in RFC 7223 Appendix C.
The vlan-tagging leaf is only added to the interface entry if the “when” statement conditions are met.
This augment statement only adds the base-interface leaf when the interface-type is “l2vlan”.
The leaf base-interface has a leafref to interface eth0 which MUST have vlan-tagging = 'true'.
The ietf-interface YANG module after all of these YANG constraints have been validated. Below is the YANG structure:
+--rw interfaces
| +--rw interface* [name]
| +--rw name string
| +--rw description? string
| +--rw type identityref
| +--rw enabled? boolean
| +--rw link-up-down-trap-enable? enumeration
Via augments:
| +--rw vlan-tagging? boolean
| +--rw base-interface? leafref
| +--rw vlan-id? uint16