
YANG Automation Uses
The YANG language includes many ways to specify conditions for database validity, which traditionally are only documented in description statements and external developer documentation.
Even with all the machine-readable properties defined in YANG (see the YANG-based Automation section), there are many standard and non-standard extensions to YANG, to increase the ability to automate tool behavior related to YANG data models.
YANG supports external statements, which allows anybody to add new statements to the standard syntax, in a way that allows all tools to either use the extension or skip over the extension. A YANG 1.1 compliant tool MAY ignore any external statement, but it MUST be able to at least parse it and ignore it.
Extension statements are used two ways in YANG:
Metadata associated with other YANG statements
Abstract data structure definitions
YANG Extensions as Metadata
The main mechanism available in YANG for tool automation is the extension statement, when used to define metadata that is associated with the parent statement. This is usually a data definition statement, but it could be any YANG statement.
Servers and clients and other tools can code to the metadata instead of hard-wired to specific YANG identifiers. All objects using the same metadata get the same treatment.
Define the YANG extension (or use an existing one)
extension my-extension { description " - Define the purpose of the extension - Define an argument if needed - Define which parent statements are allowed - Provide an example of the statement usage "; }
Use the extension as an external statement in other YANG statements
container data1 { ex:my-extension; leaf leaf1 { type string; } // ... }
Parse and save the extension statements as metadata in the server
Use the metadata to control various server and protocol behavior
YANG Extensions as Abstract Data
YANG is very useful for defining data structures that can be used within client and server implementations. They are also used to define file and artifact representations of YANG data.
Unfortunately, plain YANG data definition statements (e.g., container, list) cannot be used because these statements define YANG and NMDA datastore contents. Only data structures for datastore contents can use these statements as top-level statements in YANG.
Note
Abstract data structure names cannot conflict with any other structure or plain YANG data definition statement.
Use the sx:structure extension as an external top level statement in a YANG module:
sx:structure mydata1 { leaf leaf1 { type string; } }
The server will automatically process the 'structure' extension and save a top-level object named 'mydata1'
Use the object access APIs to retrieve the obj_template_t for the data structure so it can be used within the program (e.g., parse input or generate output).