libyang  3.7.5
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Parsing YANG Modules

YANG module parsers allow to read YANG module from a specific format. libyang supports the following module formats:

  • YANG

    Basic YANG schemas format described in RFC 6020 and RFC 7951 (so both YANG 1.0 and YANG 1.1 versions are supported).

  • YIN

    Alternative XML-based format to YANG - YANG Independent Notation. The details can be found in RFC 6020 and RFC 7951.

When the context is created, it already contains the following YANG modules, which are implemented internally by libyang:

  • ietf-yang-metadata@2016-08-05
  • yang@2020-06-17
  • ietf-inet-types@2013-07-15
  • ietf-yang-types@2013-07-15
  • ietf-datastores@2018-02-14
  • ietf-yang-library@2019-01-04

The yang module is the libyang's internal module to provide namespace and definitions of for various YANG attributes described in RFC 7951 (such as insert attribute for edit-config's data).

Other modules can be added to the context manually with the functions listed below. Besides them, it is also possible to use ly_ctx_load_module() which tries to find the required module automatically - using ly_module_imp_clb or automatic search in working directory and in the context's search directories. For details, see how the context works.

YANG modules are loaded in two steps. First, the input YANG/YIN data are parsed into lysp_* structures that reflect the structure of the input module and submodule(s). Mostly just syntax checks are done, no reference or type checking is performed in this step. If the module is supposed to be implemented, not just imported by another module, the second step is to compile it. The compiled tree may significantly differ from the source (parsed) tree structure. All the references are resolved, groupings are instantiated, types are resolved (and compiled by joining all the relevant restrictions when derived from another types) and many other syntactical checks are done.

There is the main parsing function lys_parse() working with the libyang input handler. However, to simplify some of the use-cases, it is also possible to use other functions accepting input data from various sources.

Functions List