YANG Object Modeling - amybuck/SONiC-NAS GitHub Wiki

This information describes how the SONiC NAS Host-Adapter uses YANG data models to define the contents of objects used to configure and retrieve information from the system using the SONiC Object Library APIs.

A YANG model consists of types (typedef, groupings, and enums), containers (container, list, choice, and case), and properties (leaf and leaf-list). See YANG - A Data Modeling Language for the Network Configuration Protocol for more information.

Each property in the YANG container is an object attribute. List containers nested in a YANG model are treated as multiple instances of embedded attributes. CPS also supports defining a separate CPS object from each nested container.

Using YANG-modeled data, the SONiC Object Library YANG parser generates:

  • A C/C++ header file containing:
  • YANG model name
  • Type definitions extracted from the model
  • Enumerations found in the model
  • Enumeration of any YANG container or properties (leaf, leaf-list, container, list, and so on) found in the model
  • A Python C extension library containing CPS object metadata and YANG name-to-SONiC Object Library ID mapping information

In a C/C++ application, include the generated C header to use the object key and attribute identifiers to create or delete objects and set values for each attribute. In a Python application, use the YANG module, and object and attribute names directly. The SONiC Object Library Python engine automatically uses the extension library to derive the corresponding identifiers for these names.

Python values present in the top-level dictionary:

  • data — Python dictionary containing the actual values of an object. Each element in the dictionary is a key-value pair, where the key is an attribute name and the value is a byte array or another dictionary. Depending on the object, the data dictionary may contain other dictionaries and a CPS key_data attribute that contains the instance keys for the object.
  • key — String that indicates the CPS key as a string or an alias.
  • operation — Indicates whether an object is related to a set, delete, create, or action transaction (used when events are received).

Object Dictionary Support

The object dictionary APIs access metadata for each YANG model. The dictionary contains the following items for each YANG class or attribute:

  • Static key of the element (including the elements hierarchy)
  • Type of element
  • Documentation associated with the element
  • Model type (attribute, attribute-list, or object)
  • Unique attribute identifier

You can access the SONiC Object Library object dictionary in both C/C++ and Python.

Examples