libyang  2.0.7
libyangisYANGdatamodellinglanguageparserandtoolkitwritten(andprovidingAPI)inC.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Default Values

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.

  • explicit - Only the explicitly set configuration data. But in the case of status data, missing default data are added into the tree. In libyang, this mode is represented by LYD_PRINT_WD_EXPLICIT option. This is the default with-defaults mode of the printer. The data nodes do not contain any additional metadata information.
  • trim - Data nodes containing the default value are removed. This mode is applied with LYD_PRINT_WD_TRIM option.
  • report-all - This mode provides all the default data nodes despite they were explicitly present in source data or they were added by libyang's validation process. This mode is activated by LYD_PRINT_WD_ALL option.
  • report-all-tagged - In this case, all the data nodes (implicit as well the explicit) containing the default value are printed and tagged (see the note below). Printers accept LYD_PRINT_WD_ALL_TAG option for this mode.
  • report-implicit-tagged - The last mode is similar to the previous one, except only the implicitly added nodes are tagged. This is the libyang's extension and it is activated by LYD_PRINT_WD_IMPL_TAG option.

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.

Functions List