libyang  0.16.105
YANG data modeling language library
Default Values

libyang provides support for work with default values as defined in RFC 6243. This document defines 4 modes for handling default nodes in a data tree, libyang adds the fifth mode:

  • 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 LYP_WD_EXPLICIT option.
  • trim - Data nodes containing the schema default value are removed. This mode is applied using LYP_WD_TRIM option.
  • report-all - All the missing default data are added into the data tree. This mode is represented by LYP_WD_ALL option.
  • report-all-tagged - In this case, all the missing default data are added as in case of the report-all mode, but additionally all the nodes (existing as well as added) containing the schema default value are tagged (see the note below). libyang uses LYP_WD_ALL_TAG option for this mode.
  • report-implicit-tagged - The last mode is similar to the previous one, except only the added nodes are tagged. This is the libyang's extension and it is represented by LYP_WD_IMPL_TAG option.

libyang automatically adds/maintain the default nodes when a data tree is being parsed or validated. Note, that in a modified data tree (via e.g. lyd_insert() or lyd_free()), 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 lyd_validate() call.

The implicit (default) nodes, created by libyang, are marked with the ::lyd_node#dflt flag which applies to the leafs and leaf-lists. In case of containers, the flag means that the container holds only a default node(s) or it is an empty container (according to YANG 1.1 spec, all such containers are part of the accessible data tree).

The presence of the default nodes during the data tree lifetime is affected by the LYD_OPT_ flag used to parse/validate the tree:

  • #LYD_OPT_DATA - all the default nodes are present despite they are configuration or status nodes
  • #LYD_OPT_CONFIG - only the configuration data nodes are added into the tree
  • #LYD_OPT_GET, #LYD_OPT_GETCONFIG, #LYD_OPT_EDIT - no default nodes are added
  • #LYD_OPT_RPC, #LYD_OPT_RPCREPLY, #LYD_OPT_NOTIF - the default nodes from the particular subtree are added

The with-default modes described above are supported when the data tree is being printed with the LYP_WD_ printer flags. Note, that in case of LYP_WD_ALL_TAG and LYP_WD_IMPL_TAG modes, the XML/JSON attributes are printed only if the context includes the ietf-netconf-with-defaults schema. Otherwise, these modes have the same result as LYP_WD_ALL. The presence of empty containers (despite they were added explicitly or implicitly as part of accessible data tree) depends on LYP_KEEPEMPTYCONT option.

To get know if the particular leaf or leaf-list node contains default value (despite implicit or explicit), you can use lyd_wd_default() function.

Functions List

  • lyd_wd_default()
  • lyd_parse_mem()
  • lyd_parse_fd()
  • lyd_parse_path()
  • lyd_parse_xml()
  • lyd_validate()
  • lyd_print_mem()
  • lyd_print_fd()
  • lyd_print_file()
  • lyd_print_path()
  • lyd_print_clb()