libyang
3.4.2
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
|
libyang provides support for work with default values as defined in RFC 6243. However, libyang context do not contains the ietf-netconf-with-defaults module on its own and caller is supposed to add this YANG module to enable full support of the with-defaults features described below. Without presence of the mentioned module in the context, the default nodes are still present and handled in the data trees, but the metadata providing the information about the default values cannot be used. It means that when parsing data, the default nodes marked with the metadata as implicit default nodes are handled as explicit data and when printing data tree, the expected nodes are printed without the ietf-netconf-with-defaults metadata.
The RFC document defines 4 modes for handling default nodes in a data tree, libyang adds the fifth mode and use them via Data printer flags when printing data trees.
Internally, libyang adds the default nodes into the data tree as part of the validation process. When parsing data from an input source, adding default nodes can be avoided only by avoiding the whole validation process. In case the ietf-netconf-with-defaults module is present in the context, the parser process also supports to recognize the implicit default nodes marked with the appropriate metadata.
Note, that in a modified data tree (via e.g. lyd_insert_*() or lyd_free_*() functions), some of the default nodes can be missing or they can be present by mistake. Such a data tree is again corrected during the next run of the validation process or manualy using lyd_new_implicit_*() functions.
The implicit (default) nodes, created by libyang, are marked with the LYD_DEFAULT flag in lyd_node.flags member Note, that besides leafs and leaf-lists, the flag can appear also in containers, where it means that the container holds only a default node(s) or it is implicitly added empty container (according to YANG 1.1 spec, all such containers are part of the accessible data tree). When printing data trees, the presence of empty containers (despite they were added explicitly or implicitly as part of accessible data tree) depends on LYD_PRINT_KEEPEMPTYCONT option.
To get know if the particular leaf or leaf-list node contains default value (despite implicit or explicit), you can use lyd_is_default() function.