Yuma Developer Manual
YANG-Based Unified Modular Automation Tools
Server Instrumentation Library Development
Version 1.15
Last Updated: July 20, 2011
Table Of Contents
Yuma Developer Manual
1 Preface
1.1 Legal Statements
1.2.1 WEB Sites
1.2.2 Mailing Lists
1.3 Conventions Used in this Document
2.1 Introduction
2.1.1 Intended Audience
2.1.2 What does Yuma Do?
2.1.3 What is a Yuma Root?
2.1.4 Searching Yuma Roots
2.1.5 What is a SIL?
2.1.6 Basic Development Steps
2.2.1 src/ncx Directory
2.2.2 src/platform Directory
2.2.3 src/agt Directory
2.2.4 src/mgr Directory
2.2.5 src/subsys Directory
2.2.6 src/netconfd Directory
2.2.7 src/yangcli Directory
2.2.8 src/yangdiff Directory
2.2.9 src/yangdump Directory
2.3 Server Design
2.3.1 YANG Native Operation
2.3.2 YANG Object Tree
2.3.3 YANG Data Tree
2.3.4 Service Layering
2.3.5 Session Control Block
2.3.6 Server Message Flows
2.3.7 Main ncxserver Loop
2.3.8 SIL Callback Functions
2.4 Server Operation
2.4.1 Initialization
2.4.2 Loading Modules and SIL Code
2.4.3 Core Module Initialization
2.4.4 Startup Configuration Processing
2.4.5 Process an Incoming <rpc> Request
2.4.6 Edit the Database
2.4.7 Save the Database
2.5.1 ietf-inet-types.yang
2.5.2 ietf-netconf-monitoring.yang
2.5.3 ietf-with-defaults.yang
2.5.4 ietf-yang-types.yang
2.5.5 nc-notifications.yang
2.5.6 notifications.yang
2.5.7 yuma-app-common.yang
2.5.8 yuma-interfaces.yang
2.5.9 yuma-mysession.yang
2.5.10 yuma-nacm.yang
2.5.11 yuma-ncx.yang
2.5.12 yuma-netconf.yang
2.5.13 yuma-proc.yang
2.5.14 yuma-system.yang
2.5.15 yuma-types.yang
3.1.1 Object Node Types
3.1.2 Object Node Template (obj_template_t)
3.1.3 obj_template_t Access Functions
3.2 Data Tree
3.2.1 Data Node Types
3.2.2 Yuma Data Node Edit Variables (val_editvars_t)
3.2.3 Yuma Data Nodes (val_value_t)
3.2.4 val_value_t Access Macros
3.2.5 val_value_t Access Functions
3.2.6 SIL Utility Functions
4.3 Cleanup
5.1.1 RPC Callback Initialization
5.1.2 RPC Message Header
5.1.3 SIL Support Functions For RPC Operations
5.1.4 RPC Validate Callback Function
5.1.5 RPC Invoke Callback Function
5.1.6 RPC Post Reply Callback Function
5.2.1 Database Template (cfg_template_t)
5.2.2 Database Access Functions
5.2.3 Database Callback Initialization and Cleanup
5.2.4 Example SIL Database Edit Callback Function
5.2.5 Database Edit Validate Callback Phase
5.2.6 Database Edit Apply Callback Phase
5.2.7 Database Edit Commit Callback Phase
5.2.8 Database Edit Rollback Callback Phase
5.2.9 Database Virtual Node Get Callback Function
5.3 Notifications
5.3.1 Notification Send Function
5.4.1 Timer Callback Function
5.4.2 Timer Access Functions
5.4.3 Example Timer Callback Function
6.1 Programs and Libraries Needed
6.2 SIL Makefile
6.2.1 Target Platforms
6.2.2 Build Targets
6.2.3 Command Line Build Options
6.2.4 Example SIL Makefile
Copyright 2009 - 2011, Andy Bierman, All Rights Reserved.
This document assumes you have successfully set up the software as described in the printed document:
Yuma Installation Guide
Yuma Quickstart Guide
Other documentation includes:
Yuma User Manual
Yuma netconfd Manual
Yuma yangcli Manual
Yuma yangdiff Manual
To obtain additional support you may join the yuma-users group on sourceforge.net and send email to this e-mail address:
yuma-users@lists.sourceforge.net
The SourceForge.net Support Page for Yuma can be found at this WEB page:
http://sourceforge.net/projects/yuma/support
There are several sources of free information and tools for use with YANG and/or NETCONF.
The following section lists the resources available at this time.
Netconf Central
Yuma Home Page
Free information on NETCONF and YANG, tutorials, on-line YANG module validation and documentation database
Yuma SourceFource OpenSource Project
http://sourceforge.net/projects/yuma/
Download Yuma source and binaries; project forums and help
Yang Central
Free information and tutorials on YANG, free YANG tools for download
NETCONF Working Group Wiki Page
Free information on NETCONF standardization activities and NETCONF implementations
NETCONF WG Status Page
http://tools.ietf.org/wg/netconf/
IETF Internet draft status for NETCONF documents
libsmi Home Page
Free tools such as smidump, to convert SMIv2 to YANG
NETCONF Working Group
http://www.ietf.org/html.charters/netconf-charter.html
Technical issues related to the NETCONF protocol are discussed on the NETCONF WG mailing list. Refer to the instructions on the WEB page for joining the mailing list.
NETMOD Working Group
Technical issues related to the YANG language and YANG data types are discussed on the NETMOD WG mailing list. Refer to the instructions on the WEB page for joining the mailing list.
The following formatting conventions are used throughout this document:
Documentation Conventions
|
Convention |
Description |
|
--foo |
CLI parameter foo |
|
<foo> |
XML parameter foo |
|
foo |
yangcli command or parameter |
|
$FOO |
Environment variable FOO |
|
$$foo |
yangcli global variable foo |
|
some text |
Example command or PDU |
|
some text |
Plain text |
Refer to section 3 of the Yuma User Manual for a complete introduction to Yuma Tools.
This section focuses on the software development aspects of NETCONF, YANG, and the netconfd server.
This document is intended for developers of server instrumentation library software, which can be used with the programs in the Yuma suite. It covers the design and operation of the netconfd server, and the development of server instrumentation library code, intended for use with the netconfd server.
The Yuma Tools suite provides automated support for development and usage of network management information. Refer to the Yuma User Guide for an introduction to the YANG data modeling language and the NETCONF protocol.
This section describes the Yuma development environment and the basic tasks that a software developer needs to perform, in order to integrate YANG module instrumentation into a device.
This manual contains the following information:
Yuma Development Environment
Yuma Runtime Environment
Yuma Source Code Overview
Yuma Server Instrumentation Library Development Guide
Yuma Tools programs are written in the C programming language, using the 'gnu99' C standard, and should be easily integrated into any operating system or embedded device that supports the Gnu C compiler.
The Yuma Tools programs will search for some types of files in default locations
YANG Modules: The 'modules' sub-directory is used as the root of the YANG module library.
Client Scripts: The yangcli program looks in the 'scripts' sub-directory for user scripts.
Program Data: The yangcli and netconfd programs look for saved data structures in the 'data' sub-directory.
1) $HOME Directory
The first Yuma root checked when searching for files is the directory identified by the $HOME environment variable. If a '$HOME/modules', '$HOME/data'. and/or '$HOME/scripts' directory exists, then it will be checked for the specified file(s).
2) The $YUMA_HOME Directory
The second Yuma root checked when searching for files is the directory identified by the $YUMA_HOME environment variable. This is usually set to private work directory, but a shared directory could be used as well. If a '$YUMA_HOME/modules', '$YUMA_HOME/data'. and/or '$YUMA_HOME/scripts' directory exists, then it will be checked for the specified file(s).
3) The $YUMA_INSTALL Directory
The last Yuma root checked when searching for files is the directory identified by the $YUMA_INSTALL environment variable. If it is not set, then the default value of '/usr/share/yuma' is used instead. This is usually set to the public directory where all users should find the default modules. If a '$YUMA_INSTALL/modules', '$YUMA_INSTALL/data'. and/or '$YUMA_INSTALL/scripts' directory exists, then it will be checked for the specified file(s).
A SIL is a Server Instrumentation Library. It contains the 'glue code' that binds YANG content (managed by the netconfd server), to your networking device, which implements the specific behavior, as defined by the YANG module statements.
The netconfd server handles all aspects of the NETCONF protocol operation, except data model semantics that are contained in description statements. The server uses YANG files directly, loaded at boot-time or run-time, to manage all NETCONF content, operations, and notifications.
Callback functions are used to hook device and data model specific behavior to database objects and RPC operations. The yangdump program is used to generate the initialization, cleanup, and 'empty' callback functions for a particular YANG module. The callback functions are then completed (by you), as required by the YANG module semantics. This code is then compiled as a shared library and made available to the netconfd server. The 'load' command (via CLI, configuration file, protocol operation) is used (by the operator) to activate the YANG module and its SIL.
The steps needed to create server instrumentation for use within Yuma are as follows:
Create the YANG module data model definition, or use an existing YANG module.
Validate the YANG module with the yangdump program and make sure it does not contain any errors. All warnings should also be examined to determine if they indicate data modeling bugs or not.
Example toaster.yang
Make sure the $YUMA_HOME environment variable is defined, and pointing to your Yuma development tree.
Create a SIL development subtree
Generate the directory structure and the Makefile with the make_sil-_ir script, installed in the /usr/bin directory. This step will also call yangdump to generate the initial H and C files file the SIL.
Example: mydir> make_sil_dir toaster
Use your text editor to fill in the device-specific instrumentation for each object, RPC method, and notification. Almost all possible NETCONF-specific code is either handled in the central stack, or generated automatically. so this code is responsible for implementing the semantics of the YANG data model.
Compile your code
Use the 'make' command in the SIL 'src' directory. This should generate a library file in the SIL 'lib' directory.
Example: mydir/toaster/src> make
Install the SIL library so it is available to the netconfd server.
Use the 'make install' command in the SIL 'src' directory.
Example: mydir/toaster/src> make install
Run the netconfd server (or build it again if linking with static libraries)
Load the new module
Be sure to add a 'load' command to the configuration file if the module should be loaded upon each reboot.
yangcli Example: load toaster
The netconfd server will load the specified YANG module and the SIL and make it available to all sessions.
This section describes the files that are contained in the yuma-source package.
The important C include files are copied into /usr/include/yuma when the yuma-dev package is installed. The full set of installation sources is installed in /usr/share/yuma/src, if the yuma-source package is installed. Yuma tools will check the $YUMA_HOME/src sub-tree before checking this default installation location. This allows a working copy of the Yuma sources to be used instead of the installation copy, in case it has been modified for a particular embedded system (for example).
This section lists the files that are included within the netconf/src directory.
This directory contains the code that is used to build the libncx.so binary shared library that is used by all Yuma Tools programs. It handles many of the core NETCONF/YANG data structure support, including all of the YANG/YIN, XML, and XPath processing. The following table describes the purpose of each file. Refer to the actual include file (e.g., ncx.h in /usr/include/yuma) for more details on each external function in each C source module.
src/ncx C Modules
|
C Module |
Description |
|
b64 |
Encoding and decoding the YANG binary data type. |
|
blob |
Encoding and decoding the SQL BLOB data type. |
|
bobhash |
Implementation of the BOB hash function. |
|
cap |
NETCONF capability definitions and support functions |
|
cfg |
NETCONF database data structures and configuration locking support. |
|
cli |
CLI parameter parsing data driven by YANG definitions. |
|
conf |
Text .conf file encoding and decoding, data driven by YANG definitions. |
|
def_reg |
Hash-driven definition registry for quick lookup support of some data structures. Contains back-pointers to the actual data. |
|
dlq |
Double linked queue support |
|
ext |
YANG extension data structure support |
|
grp |
YANG grouping data structure support |
|
help |
Automatic help text, data-driven by YANG definitions |
|
log |
System logging support |
|
ncx_appinfo |
Yuma Netconf Extensions (NCX) support |
|
ncx |
YANG module data structure support, and some utilities |
|
ncx_feature |
YANG feature and if-feature statement data structure support |
|
ncx_list |
Support for the ncx_list_t data structure, used for YANG bits and ncx:xsdlist data types. |
|
ncxmod |
File Management: Controls finding and searching for YANG/YIN files, data files, and script files |
|
ncx_num |
Yuma ncx_num_t data structure support. Used for processing value nodes and XPath numbers. |
|
ncx_str |
Yuma string support. |
|
obj |
Yuma object (obj_template_t) data structure access |
|
obj_help |
Automated object help support used with help module |
|
op |
NETCONF operations definitions and support functions |
|
rpc |
NETCONF <rpc> and <rpc-reply> data structures and support functions |
|
rpc_err |
NETCONF <rpc-error> data structures and support functions. |
|
runstack |
Script execution stack support for yangcli scripts |
|
send_buff |
NETCONF send buffer function |
|
ses |
NETCONF session data structures and session access functions |
|
ses_msg |
Message buffering support for NETCONF sessions |
|
status |
Error code definitions and error support functions |
|
tk |
Token chain data structures used for parsing YANG, XPath and other syntaxes. |
|
top |
Top-level XML node registration support. The <rpc> and <hello> elements are registered by the server. The <hello>, <rpc-reply> , and <notification> elements are registered by the client. |
|
tstamp |
Time and date stamp support functions |
|
typ |
YANG typedef data structures and access functions |
|
val |
Yuma value tree data structures and access functions |
|
val_util |
High-level utilities for some common SIL tasks related to the value tree. |
|
var |
User variable support, used by yangcli and (TBD) XPath |
|
xml_msg |
XML message data structures and support functions |
|
xmlns |
XML Namespace registry |
|
xml_util |
XML parse and utility functions |
|
xml_val |
High level support functions for constructing XML-ready val_value_t data structures |
|
xml_wr |
XML output support functions and access-control protected message generation support |
|
xpath1 |
XPath 1.0 implementation |
|
xpath |
XPath data structures and support functions |
|
xpath_wr |
Support for generating XPath expression content within an XML instance document |
|
xpath_yang |
Special YANG XPath construct support, such as path expressions and instance identifiers |
|
yang |
YANG definitions and general support functions |
|
yang_ext |
YANG parsing and validation of the extension statement |
|
yang_grp |
YANG parsing and validation of the grouping statement |
|
yang_obj |
YANG parsing and validation of the rpc, notification, and data definition statements |
|
yang_parse |
Top level YANG parse and validation support |
|
yang_typ |
YANG typedef and type statement support |
|
yin |
YANG to YIN mapping definitions |
|
yinyang |
YIN to YANG translation |
This directory contains platform support include files and Makefile support files. It is used by all Yuma C modules to provide an insulating layer between Yuma programs and the hardware platform that is used. For example the m__getMem, m__getObj, and m__freeMem macros are used instead of malloc and free functions directly.
The following table describes the files that are contained in this directory:
src/platform Files
|
File |
Description |
|
curversion.h |
File generated during the build process to get the SVNVERSION number |
|
platform.profile |
Included by Makefiles for build support |
|
platform.profile.cmn |
Included by Makefiles for build support |
|
platform.profile.depend |
Included by Makefiles for dependency generation support |
|
procdefs.h |
Platform definitions. Contains basic data types and macros used throughout the Yuma code. All C files include this file before any other Yuma files. |
|
setversion.sh |
Shell script to generate the curversion.h file |
This directory contains the NETCONF server implementation and built-in module SIL code. A static library called libagt.a is built and statically linked within the netconfd program.
The following table describes the C modules contained in this directory:
src/agt C Modules
|
C Module |
Description |
|
agt_acm |
NETCONF access control implementation. Contains the yuma-nacm module SIL callback functions. |
|
agt |
Server initialization and cleanup control points. Also contains the agt_profile_t data structure. |
|
agt_cap |
Server capabilities. Generates the server <capabilities> element content. |
|
agt_cb |
SIL callback support functions. |
|
agt_cli |
Server CLI and .conf file control functions. |
|
agt_connect |
Handles the internal <ncx-connect> message sent from the netconf-subsystem to the netconfd server. |
|
agt_hello |
Handles the incoming client <hello> message and generates the server <hello> message. |
|
agt_if |
Yuma Interfaces module implementation. Contains the yuma-interfaces module SIL callback functions. |
|
agt_ncx |
NETCONF protocol operation implementation. Contains the yuma-netconf module SIL callback functions. |
|
agt_ncxserver |
Implements the ncxserver loop, handling the IO between the server NETCONF sessions and the netconf-subsystem thin client program. |
|
agt_not |
NETCONF Notifications implementation. Contains the notifications and nc-notifications modules SIL callback functions. |
|
agt_proc |
/proc system monitoring implementation. Contains the yuma-proc module SIL callback functions. |
|
agt_rpc |
NETCONF RPC operation handler |
|
agt_rpcerr |
NETCONF <rpc-error> generation |
|
agt_ses |
NETCONF session support and implementation of the Yuma Session extensions. Contains the yuma-mysession module SIL callback functions. |
|
agt_signal |
Server signal handling support |
|
agt_state |
Standard NETCONF monitoring implementation. Contains the ietf-netconf-monitoring SIL callback functions. |
|
agt_sys |
Server system monitoring and notification generation. Contains the yuma-system module SIL callback functions. |
|
agt_timer |
SIL periodic timer callback support functions |
|
agt_top |
Server registration and dispatch of top-level XML messages |
|
agt_tree |
Subtree filtering implementation |
|
agt_util |
SIL callback utilities |
|
agt_val |
Server validation, commit, and rollback support for NETCONF database operations |
|
agt_val_parse |
Incoming <rpc> and <config> content parse and complete YANG constraint validation |
|
agt_xml |
Server XML processing interface to ncx/xml_util functions |
|
agt_xpath |
XPath filtering implementation |
This module contains the NETCONF client support code. It handles all the basic NETCONF details so a simple internal API can be used by NETCONF applications such as yangcli. A static library called libmgr.a is built and statically linked within the yangcli program.
The following table describes the C modules contained in this directory:
src/mgr C Modules
|
C Module |
Description |
|
mgr |
Client initialization and cleanup control points. Also contains manager session control block data structure support functions. |
|
mgr_cap |
Generate the client NETCONF <capabilities> element content |
|
mgr_hello |
Handles the incoming server <hello> message and generates the client <hello> message. |
|
mgr_io |
Handles SSH server IO support for client NETCONF sessions |
|
mgr_not |
Handles incoming server <notification> messages |
|
mgr_rpc |
Generate <rpc> messages going to the NETCONF server and process incoming <rpc-reply> messages from the NETCONF server. |
|
mgr_ses |
Handles all aspects of client NETCONF sessions. |
|
mgr_signal |
Client signal handler |
|
mgr_top |
Client registration and dispatch of top-level XML messages |
|
mgr_val_parse |
Incoming <rpc-reply>, <notification>, and <config> content parse and complete YANG constraint validation. |
|
mgr_xml |
Client XML processing interface to ncx/xml_util functions |
This directory contains the netconf-subsystem program. This is a thin-client application that just transfers input and output between the SSH server and the NETCONF server. It contains one C source module called netconf-subsystem. This is a stand-alone binary that is part of the yuma-server package. It is installed in the /usr/sbin/ directory.
This directory contains the netconfd program, which implements the NETCONF server. It contains one C module called netconfd, which defines the NETCONF server 'main' function. This is a stand-alone binary that is part of the yuma-server package. It is installed in the /usr/sbin/ directory.
This directory contains the yangcli program, which is the Yuma NETCONF client program. This is a stand-alone binary that is part of the yuma-client package. It is installed in the /usr/bin/ directory.
The following table describes the C modules contained in this directory:
src/yangcli C Modules
|
C Module |
Description |
|
yangcli |
NETCONF client program, provides interactive and script-based CLI, based on YANG modules. |
|
yangcli_autoload |
Uses the server capabilities from the <hello> message to automatically load any missing YANG modules from the server, and apply all features and deviations. |
|
yang_autolock |
Provides protocol exchange support for the high-level get-locks and release-locks commands |
|
yangcli_cmd |
Main local command processor |
|
yangcli_list |
Implements yangcli 'list' command |
|
yangcli_save |
Implements yangcli 'save' command |
|
yangcli_show |
Implements yangcli 'show' command |
|
yangcli_tab |
Implements context-sensitive tab word completion |
|
yangcli_util |
Utilities used by other yangcli C modules |
This directory contains the yangdiff program, which is the Yuma YANG module compare program. This is a stand-alone binary that is part of the yuma-client package. It is installed in the /usr/bin/ directory.
The following table describes the C modules contained in this directory:
src/yangdiff
|
C Module |
Description |
|
yangdiff |
YANG module semantic compare program |
|
yangdiff_grp |
Implements semantic diff for YANG grouping statement |
|
yangdiff_obj |
Implements semantic diff for YANG data definition statements |
|
yangdiff_typ |
Implements semantic diff for YANG typedef and type statements |
|
yangdiff_util |
Utilities used by the other yangdiff C modules |
This directory contains the yangdump program, which is the Yuma YANG compiler program. This is a stand-alone binary that is part of the yuma-client package. It is installed in the /usr/bin/ directory.
The following table describes the C modules contained in this directory:
src/yangdump C Modules
|
C Module |
Description |
|
c |
Implements SIL C file generation |
|
c_util |
Utilities used for SIL code generation |
|
h |
Implements SIL H file generation |
|
html |
Implements YANG to HTML translation |
|
sql |
Implements SQL generation for YANG module WEB Docs |
|
xsd |
Implements YANG to XSD translation |
|
xsd_typ |
Implements YANG typedef/type statement to XSD simpleType and complexType statements |
|
xsd_yang |
YANG to XSD translation utilities |
|
yangdump |
YANG module compiler |
|
yangdump_util |
Utilities used by all yangdump C modules |
|
yangyin |
Implements YANG to YIN translation |
This section describes the basic design used in the netconfd server.
Initialization:
The netconfd server will process the YANG modules, CLI parameters, config file parameters, and startup device NETCONF database, then wait for NETCONF sessions.
ncxserver Loop:
The SSH2 server will listen for incoming connections which request the 'netconf' subsystem.
When a new session request is received, the netconf-subsystem program is called, which opens a local connection to the netconfd server, via the ncxserver loop. NETCONF <rpc> requests are processed by the internal NETCONF stack. The module-specific callback functions (blue boxes) can be loaded into the system at build-time or run-time. This is the device instrumentation code, also called a server implementation library (SIL). For example, for libtoaster, this is the code that controls the toaster hardware.
Cleanup:
If the <shutdown> or <reboot> operations are invoked, then the server will cleanup. For a reboot, the init cycle is started again, instead of exiting the program.
Yuma uses YANG source modules directly to implement NETCONF protocol operations automatically within the server. The same YANG parser is used by all Yuma programs. It is located in the 'ncx' source directory (libncx.so). There are several different parsing modes, which is set by the application.
In the 'server mode', the descriptive statements, such as 'description' and 'reference' are discarded upon input. Only the machine-readable statements are saved. All possible database validation, filtering, processing, initialization, NV-storage, and error processing is done, based on these machine readable statements.
For example, in order to set the platform-specific default value for some leaf, instead of hard-coded it into the server instrumentation, the default is stored in YANG data instead. The YANG file can be altered, either directly (by editing) or indirectly (via deviation statements), and the new or altered default value specified there.
In addition, range statements, patterns, XPath expressions, and all other machine-readable statements are all processed automatically, so the YANG statements themselves are like server source code.
YANG also allows vendor and platform-specific deviations to be specified, which are like generic patches to the common YANG module for whatever purpose needed. YANG also allows annotations to be defined and added to YANG modules, which are specified with the 'extension' statement. Yuma uses some extensions to control some automation features, but any module can define extensions, and module instrumentation code can access these annotation during server operation, to control device behavior.
There are CLI parameters that can be used to control parser behavior such as warning suppression, and protocol behavior related to the YANG content, such as XML order enforcement and NETCONF protocol operation support. These parameters are stored in the server profile, which can be customized for each platform.
The YANG statements found in a module are converted to internal data structures.
For NETCONF and database operations, a single tree of obj_template_t data structures is maintained by the server. This tree represents all the NETCONF data that is supported by the server. It does not represent any actual data structure instances. It just defines the data instances that are allowed to exist on the server.
Raw YANG vs. Cooked YANG:
Some of the nodes in this tree represent the exact YANG statements that the data modeler has used, such as 'augment', 'refine', and 'uses', but these noeds are not used directly in the object tree. They exist in the object tree, but they are processed to produce a final set of YANG data statements, translated into 'cooked' nodes in the object tree. If any deviation statements are used by server implementation of a YANG data node (to change it to match the actual platform implementation of the data node), then these are also 'patched' into the cooked YANG nodes in the object tree.
A YANG data tree represents the instances of 1 or more of the objects in the object tree.
Each NETCONF database is a separate data tree. A data tree is constructed for each incoming message as well. The server has automated functions to process the data tree, based on the desired NETCONF operation and the object tree node corresponding to each data node.
Every NETCONF node (including database nodes) are distinguished with XML Qualified Names (QName). The YANG module namespace is used as the XML namespace, and the YANG identifier is used as the XML local name.
Each data node contains a pointer back to its object tree schema node. The value tree is comprised of the val_value_t structure. Only real data is actually stored in the value tree. For example, there are no data tree nodes for choices and cases. These are conceptual layers, not real layers, within the data tree.
The NETCONF server engine accesses individual SIL callback functions through the data tree and object tree. Each data node contains a pointer to its corresponding object node.
Each data node may have several different callback functions stored in the object tree node. Usually, the actual configuration value is stored in the database, However, virtual data nodes are also supported. These are simply placeholder nodes within the data tree, and usually used for non-configuration nodes, such as counters. Instead of using a static value stored in the data node, a callback function is used to retrieve the instrumentation value each time it is accessed.
All of the major server functions are supported by service layers in the 'agt' or 'ncx' libraries:
Memory management: macros in platform/procdefs.h are used instead of using direct heap functions. The macros m__getMem or m__getObj are used by Yuma code to allocate memory. Both of these functions increment a global counter called malloc_count. The macro m__free is used to delete all malloced memory. This macro increments a global counter called free_count. When a Yuma program exists, it checks if malloc_count equals free_count, and if not, generates an error message. If this occurs, the MEMTRACE=1 parameter can be added to the make command to activate 'mtrace' debugging.
Queue management: APIs in ncx/dlq.h are used for all double-linked queue management.
XML namespaces: XML namespaces (including YANG module namespaces) are managed with functions in ncx/xmlns.h. An internal 'namespace ID is used internally instead of the actual URI.
XML parsing: XML input processing is found in ncx/xml_util.h data structures and functions.
XML message processing: XML message support is found in ncx/xml_msg.h data structures and functions.
XML message writing with access control: XML message generation is controlled through API functions located in ncx/xml_wr.h. High level (value tree output) and low-level (individual tag output) XML output functions are provided, which hide all namespace, indentation, and other details. Access control is integrated into XML message output to enforce the configured data access policies uniformly for all RPC operations and notifications. The access control model cannot be bypassed by any dynamically loaded module server instrumentation code.
XPath Services: All NETCONF XPath filtering, and all YANG XPath-based constraint validation, is handled with common data structures and API functions. The XPath 1.0 implementation is native to the server, and uses the object and value trees directly to generate XPath results for NETCONF and YANG purposes. NETCONF uses XPath differently than XSLT, and libxml2 XPath processing is memory intensive. These functions are located in ncx/xpath.h, ncx/xpath1.h, and ncx/xpath_yang.h. XPath filtered <get> responses are generated in agt/agt_xpath.c.
Logging service: Encapsulates server output to a log file or to the standard output, filtered by a configurable log level. Located in ncx/log.h. In addition, the macro SET_ERROR() in ncx/status.h is used to report programming errors to the log.
Session management: All server activity is associated with a session. The session control block and API functions are located in ncx/ses.h. All input, output, access control, and protocol operation support is controlled through the session control block (ses_cb_t).
Timer service: A periodic timer service is available to SIL modules for performing background maintenance within the main service loop. These functions are located in agt/agt_timer.h.
Connection management: All TCP connections to the netconfd server are controlled through a main service loop, located in agt/agt_ncxserver.c. It is expected that the 'select' loop in this file will be replaced in embedded systems. The default netconfd server actually listens for local <ncx-connect> connections on an AF_LOCAL socket. The openSSH server listens for connections on port 830 (or other configured TCP ports), and the netconf-subsystem thin client acts as a conduit between the SSH server and the netconfd server.
Database management: All configuration databases use a common configuration template, defined in ncx/cfg.h. Locking and other generic database functions are handled in this module. The actual manipulation of the value tree is handled by API functions in ncx/val.h, ncx/val_util.h, agt/agt_val_parse.h, and agt/agt_val.h.
NETCONF operations: All standard NETCONF RPC callback functions are located in agt/agt_ncx.c. All operations are completely automated, so there is no server instrumentation APIs in this file.
NETCONF request processing: All <rpc> requests and replies use common data structures and APIs, found in ncx/rpc.h and agt/agt_rpc.h. Automated reply generation, automatic filter processing, and message state data is contained in the RPC message control block.
NETCONF error reporting: All <rpc-error> elements use common data structures defined in ncx/rpc_err,h and agt/agt_rpcerr.h. Most errors are handled automatically, but 'description statement' semantics need to be enforced by the SIL callback functions. These functions use the API functions in agt/agt_util.h (such as agt_record_error) to generate data structures that will be translated to the proper <rpc-error> contents when a reply is sent.
YANG module library management: All YANG modules are loaded into a common data structure (ncx_module_t) located in ncx/ncxtypes.h. The API functions in ncx/ncxmod.h (such as ncxmod_load_module) are used to locate YANG modules, parse them, and store the internal data structures in a central library. Multiple versions of the same module can be loaded at once, as required by YANG.
Once a NETCONF session is started, it is assigned a session control block for the life of the session. All NETCONF and system activity in driven through this interface, so the ncxserver loop can be replaced in an embedded system.
Each session control block (ses_scb_t) controls the input and output for one session, which is associated with one SSH user name. Access control (see yuma-nacm.yang) is enforced within the context of a session control block. Unauthorized return data is automatically removed from the response. Unauthorized <rpc> or database write requests are automatically rejected with an 'access-denied' error-tag.
The user preferences for each session are also stored in this data structure. They are initially derived from the server default values, but can be altered with the <set-my-session> operation and retrieved with the <get-my-session> operation.
The netconfd server provides the following type of components:
NETCONF session management
NETCONF/YANG database management
NETCONF/YANG protocol operations
Access control configuration and enforcement
RPC error reporting
Notification subscription management
Default data retrieval processing
Database editing
Database validation
Subtree and XPath retrieval filtering
Dynamic and static capability management
Conditional bbject management (if-feature, when)
Memory management
Logging management
Timer services
All NETCONF and YANG protocol operation details are handled automatically within the netconfd server. All database locking and editing is also handled by the server. There are callback functions available at different points of the processing model for your module specific instrumentation code to process each server request, and/or generate notifications. Everything except the 'description statement' semantics are usually handled
The server instrumentation stub files associated with the data model semantics are generated automatically with the yangdump program. The developer fills in server callback functions to activate the networking device behavior represented by each YANG data model.
The ncxserver loop does very little, and it is designed to be replaced in an embedded server that has its own SSH server:
A client request to start an SSH session results in an SSH channel being established to an instance of the netconf-subsystem program.
The netconf-subsystem program will open a local socket (/tmp/ncxserver.sock) and send a proprietary <ncxconnect> message to the netconfd server, which is listening on this local socket with a select loop (in agt_ncxserver.c).
When a valid <ncxconnect> message is received by netconfd, a new NETCONF session is created.
After sending the <ncxconnect> message, the netconf-subsystem program goes into 'transfer mode', and simply passes input from the SSH channel to the netconfd server, and passes output from the netconfd server to the SSH server.
The ncxserver loop simply waits for input on the open connections, with a quick timeout. Each timeout, the server checks if a reboot, shutdown, signal, or other event occurred that needs attention.
Notifications may also be sent during the timeout check, if any events are queued for processing. The --max-burst configuration parameter controls the number of notifications sent to each notification subscription, during this timeout check.
Input <rpc> messages are buffered, and when a complete message is received (based on the NETCONF End-of-Message marker), it is processed by the server and any instrumentation module callback functions that are affected by the request.
When the agt_ncxserver_run function in agt/agt_ncxserver.c is replaced within an embedded system, the replacement code must handle the following tasks:
Call agt_ses_new_session in agt/agt_ses.c when a new NETCONF session starts.
Call ses_accept_input in ncx/ses.c with the correct session control block when NETCONF data is received.
Call agt_ses_process_first_ready in agt/agt_ses.c after input is received. This should be called repeatedly until all serialized NETCONF messages have been processed.
Call agt_ses_kill_session in agt/agt_ses.c when the NETCONF session is terminated.
The following functions are used for sending NETCONF responses, if responses are buffered instead of sent directly (streamed).
ses_msg_send_buffs in ncx/ses_msg.c is used to output any queued send buffers.
The following functions need to be called periodically:
agt_shutdown_requested in agt/agt_util.c to check if the server should terminate or reboot
agt_ses_check_timeouts in agt/agt_ses.c to check for idle sessions or sessions stuck waiting for a NETCONF <hello> message.
agt_timer_handler in agt/agt_timer.c to process server and SIL periodic callback functions.
send_some_notifications in agt/agt_ncxserver.c to process some outgoing notifications.
Top Level: The top-level incoming messages are registered, not hard-wired, in the server message processing design. The agt_ncxserver module accepts the <ncxconnect> message from netconf-subsystem. The agt_rpc module accepts the NETCONF <rpc> message. Additional messages can be supported by the server using the top_register_node function.
All RPC operations are implemented in a data-driven fashion by the server. Each NETCONF operation is handled by a separate function in agt_ncx.c. Any proprietary operation can be automatically supported, using the agt_rpc_register_method function.
Note: Once the YANG module is loaded into the server, all RPC operations defined in the module are available. If no SIL code is found, these will be dummy 'no-op' functions. This mode can be used to provide some server simulation capability for client applications under development.
All database operations are performed in a structured manner, using special database access callback functions. Not all database nodes need callback functions. One callback function can be used for each 'phase', or the same function can be used for multiple phases. The agt_cb_register_callback function in agt/agt_cb.c is used by SIL code to hook into NETCONF database operations.
This section briefly describes the server internal behavior for some basic NETCONF operations.
The file netconfd/netconfd.c contains the initial 'main' function that is used to start the server.
The common services support for most core data structures is located in 'libncx.so'. The 'ncx_init' function is called to setup these data structures. This function also calls the bootstrap_cli function in ncx/ncx.c, which processes some key configuration parameters that need to be set right away, such as the logging parameters and the module search path.
Most of the actual server code is located in the 'agt' directory. The 'agt_init1' function is called to initialize core server functions. The configuration parameters are processed, and the server profile is completed.
The agt_profile_t data structure in agt/agt.h is used to contain all the vendor-related boot-time options, such as the database target (candidate or running). The init_server_profile function can be edited if the Yuma default values are not desired. This will insure the proper factory defaults for server behavior are used, even if no configuration parameters are provided.
The function init_server_profile in agt/agt.c is used to set the factory defaults for the server behavior.
The agt_init1 function also loads the core NETCONF protocol, netconfd CLI, and YANG data type modules.
Note: netconfd uses yuma-netconf.yang, not ietf-netconf.yang to support a data-driven implementation. The only difference is that the yuma version adds some data structures and extensions (such as ncx:root), to automate processing of all NETCONF messages.
After the core definition modules are loaded successfully, the agt_cli_process_input function in agt/agt_cli.c is called to process any command line and/or configuration file parameters that have been entered.
Note: Any defaults set in the G module definitions will be added to the CLI parameter set. The val_set_by_default function in ncx/val.c can be used to check if the node is set by the server to the YANG default value. If not set, and the node has the YANG default value, then the client set this value explicitly. This is different than the val_is_default function in ncx/val.c, which just checks if the node contains the YANG default value.
All the configuration parameters are saved, and those that can be processed right away are handled. The agt_cli_get_valset function in agt/agt_cli.c can be used to retrieve the entire set of load-time configuration parameters.
YANG modules and their associated device instrumentation can be loaded dynamically with the --module configuration parameter. Some examples are shown below:
module=foo
module=bar
module=baz@2009-01-05
module=~/mymodules/myfoo.yang
The ncxmod_find_sil_file function in ncx/ncxmod.c is used to find the library code associated with the each module name. The following search sequence is followed:
Check the $YUMA_HOME/target/lib directory
Check each directory in the $YUMA_RUNPATH environment variable or --runpath configuration variable.
Check the /usr/lib/yuma directory
If the module parameter contains any sub-directories or a file extension, then it is treated as a file, and the module search path will not be used. Instead the absolute or relative file specification will be used.
If the first term starts with an environment variable or the tilde (~) character, and will be expanded first
If the 'at sign' (@) followed by a revision date is present, then that exact revision will be loaded.
If no file extension or directories are specified, then the module search path is checked for YANG and YIN files that match. The first match will be used, which may not be the newest, depending on the actual search path sequence.
The $YUMA_MODPATH environment variable or --modpath configuration parameter can be used to configure one or more directory sub-trees to be searched.
The $YUMA_HOME environment variable or --yuma-home configuration parameter can be used to specify the Yuma project tree to use if nothing is found in the currect directory or the module search path.
The $YUMA_INSTALL environment variable or default Yuma install location (/usr/share/yuma/modules) will be used as a last resort to find a YANG or YIN file.
The server processes --module parameters by first checking if a dynamic library can be found which has an 'soname' that matches the module name. If so, then the SIL phase 1 initialization function is called, and that function is expected to call the ncxmod_load_module function.
If no SIL file can be found for the module, then the server will load the YANG module anyway, and support database operations for the module, for provisioning purposes. Any RPC operations defined in the module will also be accepted (depending on access control settings), but the action will not actually be performed. Only the input parameters will be checked, and <or> or some <rpc-error> returned.
The agt_init2 function in agt/agt.c is called after the configuration parameters have been collected.
Initialize the core server code modules
Static device-specific modules can be added to the agt_init2 function after the core modules have been initialized
Any 'module' parameters found in the CLI or server configuration file are processed.
The agt_cap_set_modules function in agt/agt_cap.c is called to set the initial module capabilities for the ietf-netconf-monitoring module
After the static and dynamic server modules are loaded, the --startup (or --no-startup) parameter is processed by agt_init2 in agt/agt.c:
If the --startup parameter is used and includes any sub-directories, it is treated as a file and must be found, as specified.
Otherwise, the $YUMA_DATAPATH environment variable or --datapath configuration parameter can be used to determine where to find the startup configuration file.
If neither the --startup or --no-startup configuration parameter is present, then the data search path will be used to find the default startup-cfg.xml
The $YUMA_HOME environment variable or --yuma-home configuration parameter is checked if no file is found in the data search path. The $YUMA_HOME/data directory is checked if this parameter is set.
The $YUMA_INSTALL environment variable or default location (/etc/yuma/) is checked next, if the startup configuration is still not found.
It is a fatal error if a startup config is specified and it cannot be found.
As the startup configuration is loaded, any SIL callbacks that have been registered will be invoked for the association data present in the startup configuration file.. The edit operation will be OP_EDITOP_LOAD during this callback.
After the startup configuration is loaded into the running configuration database, all the stage 2 initialization routines are called. These are needed for modules which add read-only data nodes to the tree containing the running configuration. SIL modules may also use their 'init2' function to create factory default configuration nodes (which can be saved for the next reboot).
PARSE Phase: The incoming buffer is converted to a stream of XML nodes, using the xmlTextReader functions from libxml2. The agt_val_parse function is used to convert the stream of XML nodes to a val_value_t structure, representing the incoming request according to the YANG definition for the RPC operation. An rpc_msg_t structure is also built for the request.
VALIDATE Phase: If a message is parsed correctly, then the incoming message is validated according to the YANG machine-readable constraints. Any description statement constraints need to be checked with a callback function. The agt_rpc_register_method function in agt/agt_rpc.c is used to register callback functions.
INVOKE Phase: If the message is validated correctly, then the invoke callback is executed. This is usually the only required callback function. Without it, the RPC operation has no affect. This callback will set fields in the rpc_msg_t header that will allow the server to construct or stream the <rpc-reply> message back to the client.
REPLY Phase: Unless some catastrophic error occurs, the server will generate an <rpc-reply> response. If any <rpc-error> elements are needed, they are generated first. If there is any response data to send, that is generated or streamed (via callback function provided earlier) at this time. Any unauthorized data (according to to the yuma-nacm.yang module configuration) will be silently dropped from the message payload. If there were no errors and no data to send, then an <ok> resonse is generated.
POST_REPLY Phase: After the response has been sent, a rarely-used callback function can be invoked to cleanup any memory allocation or other data-model related tasks. For example, if the rpc_user1 or rpc_user2 pointers in the message header contain allocated memory then they need to be freed at this time.
Validate Phase: The server will determine the edit operation and the actual nodes in the target database (candidate or running) that will be affected by the operation. All of the machine-readable YANG statements which apply to the affected node(s) are tested against the incoming PDU and the target database. If there are no errors, the server will search for a SIL validate callback function for the affected node(s). If the SIL code has registered a database callback function for the node or its local ancestors, it will be invoked. This SIL callback function usually checks additional constraints that are contained in the YANG description statements for the database objects.
Test-Apply and Apply Phase: If the validate phase completes without errors, then the requested changes are applied to the target database. If the target database is the running configuration, or if the edit-config 'test-option' parameter is set to 'test-then-set' (the default if --with-validate=true), then the test-apply phase is executed first. This is essentially the same as the real apply phase, except that changes are made to a copy of the target database. Once all objects have been altered as requested, the entire test database is validated, including all cross-referential integrity tests. If this test completes without any errors, then the procedure is repeated on the real target database.
Note: This phase is used for the internal data tree manipulation and validation only. It is not used to alter device behavior. Resources may need to be reserved during the SIL apply callback, but the database changes are not activated at this time.
Commit or Rollback Phase: If the validate and apply phases complete without errors, then then the server will search for SIL commit callback functions for the affected node(s) in the target database. This SIL callback phase is used to apply the changes to the device and/or network. It is only called when a commit procedure is attempted. This can be due to a <commit> operation, or an <edit-config> or <copy-config> operation on the running database.
Note: If there are errors during the commit phase, then the backup configuration will be applied, and the server will search for a SIL callback to invoke with a 'rollback operation'. The same procedure is used for confirmed commit operations which timeout or canceled by the client.
The following bullets describe how the server saves configuration changes to non-volatile storage:
If the --with-startup=true parameter is used, then the server will support the :startup capability. In this case, the <copy-config> command needs to be used to cause the running configuration to be saved.
If the --with-startup=false parameter is used, then the server will not support the :startup capability. In this case, the database will be saved each time the running configuration is changed.
The <copy-config> or <commit> operations will cause the startup configuration file to be saved, even if nothing has changed. This allows an operator to replace a corrupted or missing startup configuration file at any time.
The database is saved with the agt_ncx_cfg_save function in agt/agt_ncx.c.
The with-defaults 'explicit' mode is used during the save operation to filter the database contents.
Any values that have been set by the client will be saved in NV-storage.
Any value set by the server to a YANG default value will not be saved in the database.
If the server create a node that does not have a YANG default value (e.g., containers, lists, keys), then this node will be saved in NV storage.
If the --startup=filespec parameter is used, then the server will save the database by overwriting that file. The file will be renamed to backup-cfg.xml first.
If the --no-startup parameter is used, or no startup file is specified and no default is found, then the server will create a file called 'startup-cfg.xml', in the following manner:
If the $YUMA_HOME variable is set, the configuration will be saved in $YUMA_HOME/data/startup-cfg.xml .
Otherwise, the configuration will be saved in $HOME/.yuma / startup-cfg.xml.
The database is saved as an XML instance document, using the <config> element in the NETCONF 'base' namespace as the root element. Each top-level YANG module supported by the server, which contains some explicit configuration data, will be saved as a child node of the <nc:config> element. There is no particular order to the top-level data model elements.
There are several YANG modules which are implemented within the server, and not loaded at run-time like a dynamic SIL module. Some of them are NETCONF standard modules and some are Yuma extension modules.
This module contains the standard YANG Internet address types. These types are available for commonly used management object types. A YANG module author should check this module first, before creating any new data types with the YANG typedef statement.
There are no accessible objects in this module, so there are no SIL callback functions. The YANG data-types are supported within the Yuma engine core modules, such as ncx/val.c and ncx/xml_wr.c.
The standard NETCONF Monitoring module is used to examine the capabilities, current state, and statistics related to the NETCONF server. The entire module is supported.
This module is also used to retrieve the actual YANG or YIN files (or URLs for them) that the server is using. Clients can use the <get-schema> RPC operation to retrieve the YANG or YIN files listed in the /netconf-state/schemas subtree. A client will normally check the <hello> message from the server for module capabilities, and use its own local copy of a server YANG module, if it can. If not, then the <get-schema> function can be used to retrieve the YANG module.
The agt/agt_state.c contains the SIL callback functions for this module.
The standard <with-defaults> extension to some NETCONF operations is defined in this module. This parameter is added to the <get>, <get-config>, and <copy-config> operations to let the client control how 'default leafs' are returned by the server. The Yuma server can be configured to use any of the default handling styles (report-all, trim, or explicit). The filtering of default nodes is handled automatically by the server support functions in agt/agt_util.c, and the XML write functions in ncx/xml_wr.c.
This module contains the standard YANG general user data types. These types are available for commonly used derived types. A YANG module author should check this module first, before creating any new data types with the YANG typedef statement.
There are no accessible objects in this module, so there are no SIL callback functions. The YANG data-types are supported within the Yuma engine core modules, such as ncx/val.c and ncx/xml_wr.c.
This module is defined in RFC 5277, the NETCONF Notifications specification. It contains the <replayComplete> and <notificationComplete> notification event definitions.
The file agt/agt_not.c contains the SIL support code for this module.
This module is defined in RFC 5277, the NETCONF Notifications specification. All of this RFC is supported in the server. This module contains the <create-subscription> RPC operation. The notification replay feature is controlled with the --eventlog-size configuration parameter. The <create-subscription> operation is fully supported, including XPath and subtree filters. The yuma-nacm module can be used to control what notification events a user is allowed to receive. The <create-subscription> filter allows the client to select which notification events it wants to receive.
The file agt/agt_not.c contains the SIL callback functions for this modules.
This module contains some common groupings of CLI parameters supported by some or all Yuma programs. Each program with CLI parameters defines its own module of CLI parameters (using the ncx:cli extension). The program name is used for the YANG module name as well (e.g., yangdump.yang or netconfd.yang).
The SIL callback functions for the common groupings in this module are found in ncx/val_util.c, such as the val_set_feature_parms function.
This module contains the Yuma interfaces table, which is just a skeleton configuration list, plus some basic interface counters. This module is intended to provide an example for embedded developers to replace this module with their own interfaces table. The Yuma table uses information in some files found in Unix systems which support the /proc/net/dev system file.
The file agt/agt_if.c contains the SIL callback functions for this module.
This module provides the Yuma proprietary <get-my-session> and <set-my-session> RPC operations. These are used by the client to set some session output preferences, such as the desired line length, indentation amount, and defaults handling behavior.
The file agt/agt_ses.c contains the SIL callback functions for this module.
This module contains the Yuma NETCONF Access Control Model implementation. It provides all user-configurable access control settings and also provides API functions to check if a specific access request should be allowed or not.
The file agt/agt_acm.c contains the SIL callback functions for this module.
This module provides the YANG language extension statements that are used by Yuma programs to automate certain parts of the NETCONF protocol, document generation, code generation, etc.
There are no SIL callback functions for this module. There are support functions within the src/ncx directory that include the obj_set_ncx_flags function in ncx/obj.c
The NETCONF protocol operations, message structures, and error information are all data-driven, based on the YANG statements in the yuma-netconf.yang module. The ietf-netconf.yang module is not used at this time because it does not contain the complete set of YANG statements needed. The yuma-netconf.yang version is a super-set of the IETF version. Only one YANG module can be associated with an XML namespace in Yuma. In a future version, the extra data structures will be moved to an annotation module.
The file agt/agt_ncx.c contains the SIL callback functions for this module.
This module is not advertised in the server capabilities. It is only used internally within the server.
This module provides some Unix /proc file-system data, in nested XML format. This module will not load if the files /proc/meminfo and /proc/cpuinfo are not found.
The file agt/agt_proc.c contains the SIL callback functions for this module.
This module contains the Yums /system data structure, providing basic server information, unix 'uname' data, and all the Yuma proprietary notification event definitions.
The file agt/agt_sys.c contains the SIL callback functions for this module.
This module provides some common data types that are used by other Yuma YANG modules.
There are no SIL callback functions for this module.
This section describes the basic design of the YANG object tree and the corresponding data tree that represents instances of various object nodes that the client or the server can create.
The object tree is a tree representation of all the YANG module rpc, data definition, and notification statements. It starts with a 'root' container. This is defined with a YANG container statement which has an ncx:root extension statement within it. The <config> parameter within the <edit-config> operation is an example of an object node which is treated as a root container. Each configuration database maintained by the server (e.g., <candidate> and <running>) has a root container value node as its top-level object.
A root container does not have any child nodes defined in it within the YANG file. However, the Yuma tools will treat this special container as if any top-level YANG data node is allowed to be a child node of the 'root' container type.
There are 14 different YANG object node types, and a discriminated union of sub-data structures contains fields common to each sub-type. Object templates are defined in ncx/obj.h.
YANG Object Types
|
object type |
description |
|
OBJ_TYP_ANYXML |
This object represents a YANG anyxml data node. |
|
OBJ_TYP_CONTAINER |
This object represents a YANG presence or non-presence container. |
|
OBJ_TYP_CONTAINER + ncx:root |
If the ncx:root extension is present within a container definition, then the object represents a NETCONF database root. No child nodes |
|
OBJ_TYP_LEAF |
This object represents a YANG leaf data node. |
|
OBJ_TYP_LEAF_LIST |
This object represents a YANG leaf-list data node. |
|
OBJ_TYP_LIST |
This object represents a YANG list data node. |
|
OBJ_TYP_CHOICE |
This object represents a YANG choice schema node. The only children allowed are case objects. This object does not have instances in the data tree. |
|
OBJ_TYP_CASE |
This object represents a YANG case schema node. This object does not have instances in the data tree. |
|
OBJ_TYP_USES |
This object represents a YANG uses schema node. The contents of the grouping it represents will be expanded into object tree. It is saved in the object tree even during operation, in order for the expanded objects to share common data. This object does not have instances in the data tree. |
|
OBJ_TYP_REFINE |
This object represents a YANG refine statement. It is used to alter the grouping contents during the expansion of a uses statement. This object is only allowed to be a child of a uses statement. It does not have instances in the data tree. |
|
OBJ_TYP_AUGMENT |
This object represents a YANG augment statement. It is used to add additional objects to an existing data structure. This object is only allowed to be a child of a uses statement or a child of a 'root' container. It does not have instances in the data tree, however any children of the augment node will generate object nodes that have instances in the data tree. |
|
OBJ_TYP_RPC |
This object represents a YANG rpc statement. It is used to define new <rpc> operations. This object will only appear as a child of a 'root' container. It does not have instances in the data tree. Only 'rpcio' nodes are allowed to be children of an RPC node. |
|
OBJ_TYP_RPCIO |
This object represents a YANG input or output statement. It is used to define new <rpc> operations. This object will only appear as a child of an RPC node. It does not have instances in the data tree. |
|
OBJ_TYP_NOTIF |
This object represents a YANG notification statement. It is used to define new <notification> event types. This object will only appear as a child of a 'root' container. It does not have instances in the data tree. |
The following typedef is used to represent an object tree node:
/* One YANG data-def-stmt */
typedef struct obj_template_t_ {
dlq_hdr_t qhdr;
obj_type_t objtype;
uint32 flags; /* see OBJ_FL_* definitions */
ncx_error_t tkerr;
grp_template_t *grp; /* non-NULL == in a grp.datadefQ */
/* 4 back pointers */
struct obj_template_t_ *parent;
struct obj_template_t_ *usesobj;
struct obj_template_t_ *augobj;
struct xpath_pcb_t_ *when; /* optional when clause */
dlq_hdr_t metadataQ; /* Q of obj_metadata_t */
dlq_hdr_t appinfoQ; /* Q of ncx_appinfo_t */
dlq_hdr_t iffeatureQ; /* Q of ncx_iffeature_t */
/* cbset is agt_rpc_cbset_t for RPC or agt_cb_fnset_t for OBJ */
void *cbset;
/* object namespace ID assigned at runtime
* this can be changed over and over as a
* uses statement is expanded. The final
* expansion into a real object will leave
* the correct value in place
*/
xmlns_id_t nsid;
union def_ {
obj_container_t *container;
obj_leaf_t *leaf;
obj_leaflist_t *leaflist;
obj_list_t *list;
obj_choice_t *choic;
obj_case_t *cas;
obj_uses_t *uses;
obj_refine_t *refine;
obj_augment_t *augment;
obj_rpc_t *rpc;
obj_rpcio_t *rpcio;
obj_notif_t *notif;
} def;
} obj_template_t;
The following table highlights the fields within the obj_template_t data structure:
obj_template_t Fields
|
Field |
Description |
|
qhdr |
Queue header to allow the object template to be stored in a child queue |
|
objtype |
enumeration to identify which variant of the 'def' union is present |
|
flags |
Internal state and properties |
|
tkerr |
Error message information |
|
grp |
back-pointer to parent group if this is a top-level data node within a grouping |
|
parent |
Parent node if any |
|
usesobj |
Back pointer to uses object if this is a top-level data node within an expanded grouping |
|
augobj |
Back pointer to augment object if this is a top-level data node within an expanded augment |
|
when |
XPath structure for YANG when statement |
|
metadataQ |
Queue of obj_template_t for any XML attributes (ncx:metadata) defined for this object node |
|
appinfoQ |
Queue of ncx_appinfo_t for any YANG extensions found defined within the object, that were not collected within a deeper appinfoQ (e.g., within a type statement) |
|
iffeatureQ |
Queue of ncx_iffeature_t for any if-feature statements found within this object node |
|
cbset |
Set of server callback functions for this object node. |
|
nsid |
Object node namespace ID assigned by xmlns.c |
|
def |
Union of object type specific nodes containing the rest of the YANG statements. Note that the server discards all descriptive statements such as description, reference, contact,. |
The file ncx/obj.h contains many API functions so that object properties do not have to be accessed directly. The following table highlights the most commonly used functions. Refer to the H file for a complete definition of each API function.
obj_template_t Access Functions
|
Function |
Description |
|
obj_find_template |
Find a top-level object template within a module |
|
obj_find_child |
Find the specified child node within a complex object template . Skips over any nodes without names (augment, uses, etc.) |
|
obj_first_child |
Get the first child node within a complex object template . Skips over any nodes without names. |
|
obj_next_child |
Get the next child node after the current specified child. Skips over any nodes without names. |
|
obj_first_child_deep |
Get the first child node within a complex object template . Skips over any nodes without names, and also any choice and case nodes. |
|
obj_next_child_deep |
Get the next child node after the current specified child. Skips over any nodes without names, and also any choice and case nodes. |
|
obj_find_case |
Find the specified case object child node within the specific complex object node. |
|
obj_find_type |
Check if a typ_template_t in the obj typedefQ hierarchy. |
|
obj_find_grouping |
Check if a grp_template_t in the obj typedefQ hierarchy. |
|
obj_find_key |
Find a specific key component by key leaf identifier name |
|
obj_first_key |
Get the first obj_key_t struct for the specified list object type |
|
obj_next_key |
Get the next obj_key_t struct for the specified list object type |
|
obj_gen_object_id |
Allocate and generate the YANG object ID for an object node |
|
obj_get_name |
Get the object name string |
|
obj_has_name |
Return TRUE if the object has a name field |
|
obj_has_text_content |
Return TRUE if the object has text content |
|
obj_get_status |
Get the YANG status for the object |
|
obj_get_description |
Get the YANG description statement for an object. Note that the server will always return a NULL pointer. |
|
obj_get_reference |
Get the YANG reference statement for an object. Note that the server will always return a NULL pointer. |
|
obj_get_config_flag |
Get the YANG config statement value for an object |
|
obj_get_typestr |
Get the name string for the type of an object |
|
obj_get_default |
Get the YANG default value for an object |
|
obj_get_default_case |
Get the name of the default case for a choice object |
|
obj_get_typdef |
Get the internal type definition for the leaf or leaf-list object |
|
obj_get_basetype |
Get the internal base type enumeration for an object |
|
obj_get_mod_prefix |
Get the module prefix for an object |
|
obj_get_mod_name |
Get the module name containing an object |
|
obj_get_mod_version |
Get the module revision date for the module containing an object. |
|
obj_get_nsid |
Get the internal XML namespace ID for an object |
|
obj_get_min_elements |
Get the YANG min-elements value for a list or leaf-list object |
|
obj_get_max_elements |
Get the YANG max-elements value for a list or leaf-list object |
|
obj_get_units |
Get the YANG units field for a leaf or leaf-list object |
|
obj_get_parent |
Get the parent object node for an object |
|
obj_get_presence_string |
Get the YANG presence statement for a container object |
|
obj_get_child_count |
Get the number of child nodes for a complex object. |
|
obj_get_fraction_digits |
Get the YANG fraction-digits statement for a decimal64 leaf or leaf-list object |
|
obj_is_leafy |
Return TRUE if the object is a leaf or leaf-list type |
|
obj_is_mandatory |
Return TRUE if the object is YANG mandatory |
|
obj_is_mandatory_when |
Return TRUE if the object is YANG mandatory, but first check if any when statements are FALSE first |
|
obj_is_cloned |
Return TRUE if the object is expanded from a grouping or augment statement |
|
obj_is_data_db |
Return TRUE if the object is defined within a YANG database definition |
|
obj_in_rpc |
Return TRUE if the object is defined within an RPC statement |
|
obj_in_notif |
Return TRUE if the object is defined within a notification statement |
|
obj_is_hidden |
Return TRUE if object contains the ncx:hidden extension |
|
obj_is_root |
Return TRUE if object contains the ncx:root extension |
|
obj_is_password |
Return TRUE if object contains the ncx:password extension |
|
obj_is_cli |
Return TRUE if object contains the ncx:cli extension |
|
obj_is_abstract |
Return TRUE if object contains the ncx:abstract extension |
|
obj_is_xpath_string |
Return TRUE if the object is a leaf or leaf-list containing an XPath string |
|
obj_is_schema_instance_string |
Return TRUE if the object is a leaf or leaf-list containing a schema instance identifier string |
|
obj_is_secure |
Return TRUE if object contains the nacm:secure extension |
|
obj_is_very_secure |
Return TRUE if object contains the nacm:very-secure extension |
|
obj_is_system_ordered |
Return TRUE if the list or leaf-list object is system ordered; FALSE if it is user ordered |
|
obj_is_np_container |
Return TRUE if the object is a YANG non presence container |
|
obj_is_enabled |
Return TRUE if the object is enabled; FALSE if any if-feature, when-stmt, or deviation-stmt has removed the object from the system. |
|
obj_sort_children |
Rearrange any child nodes in YANG schema order |
A Yuma data tree is a representation of some subset of all possible object instances that a server is maintaining within a configuration database or other structure.
Each data tree starts with a 'root' container, and any child nodes represent top-level YANG module data nodes that exist within the server.
Each configuration database maintains its own copy (and version) of the data tree. There is only one object tree, however, and all data trees use the same object tree for reference.
Not all object types have a corresponding node within a data tree. Only 'real' data nodes are present. Object nodes that are used as meta-data to organize the object tree (e.g., choice, augment) are not present. The following table lists the object types and whether each one is found in a data tree.
Object Types in the Data Tree
|
Object Type |
Found In Data Tree? |
|
OBJ_TYP_ANYXML |
Yes |
|
OBJ_TYP_CONTAINER |
Yes |
|
OBJ_TYP_CONTAINER (ncx:root) |
Yes |
|
OBJ_TYP_LEAF |
Yes |
|
OBJ_TYP_LEAF_LIST |
Yes |
|
OBJ_TYP_LIST |
Yes |
|
OBJ_TYP_CHOICE |
No |
|
OBJ_TYP_CASE |
No |
|
OBJ_TYP_USES |
No |
|
OBJ_TYP_REFINE |
No |
|
OBJ_TYP_AUGMENT |
No |
|
OBJ_TYP_RPC |
No |
|
OBJ_TYP_RPCIO |
No |
|
OBJ_TYP_NOTIF |
No |
The ncx_btype_t enumeration in ncx/ncxtypes.h is used within each val_value_t to quickly identify which variant of the data node structure is being used.
The following table describes the different enumeration values:
Yuma Data Types (ncx_btype_t)
|
Data Type |
Description |
|
NCX_BT_NONE |
No type has been set yet. The val_new_value() function has been called but no specific init function has been called to set the base type. |
|
NCX_BT_ANY |
The node is a YANG 'anyxml' node. When the client or server parses an 'anyxml' object, it will be converted to containers and strings. This type should not be used directly. |
|
NCX_BT_BITS |
YANG 'bits' data type |
|
NCX_BT_ENUM |
YANG 'enumeration' data type |
|
NCX_BT_EMPTY |
YANG 'empty' data type |
|
NCX_BT_BOOLEAN |
YANG 'boolean' data type |
|
NCX_BT_INT8 |
YANG 'int8' data type |
|
NCX_BT_INT16 |
YANG 'int16' data type |
|
NCX_BT_INT32 |
YANG 'int32' data type |
|
NCX_BT_INT64 |
YANG 'int64' data type |
|
NCX_BT_UINT8 |
YANG 'uint8' data type |
|
NCX_BT_UINT16 |
YANG 'uint16' data type |
|
NCX_BT_UINT32 |
YANG 'uint32' data type |
|
NCX_BT_UINT64 |
YANG 'uint64' data type |
|
NCX_BT_DECIMAL64 |
YANG 'decimal64' data type |
|
NCX_BT_FLOAT64 |
Hidden double type, used just for XPath. If the HAS_FLOAT #define is false, then this type will be implemented as a string, not a double. |
|
NCX_BT_STRING |
YANG 'string' type. There are also some Yuma extensions that are used with this data type for special strings. The server needs to know if a string contains XML prefixes or not, and there are several flavors to automatate processing of each one correctly. |
|
NCX_BT_BINARY |
YANG 'binary' data type |
|
NCX_BT_INSTANCE_ID |
YANG 'instance-identifier' data type |
|
NCX_BT_UNION |
YANG 'union' data type. This is a meta-type. When the client or server parses a value, it will resolve the union to one of the data types defined within the union. |
|
NCX_BT_LEAFREF |
YANG 'leafref' data type. This is a meta-type. The client or server will resolve this data type to the type of the actual 'pointed-at' leaf that is being referenced. |
|
NCX_BT_IDREF |
YANG 'identityref' data type |
|
NCX_BT_SLIST |
XSD list data type (ncx:xsdlist extension) |
|
NCX_BT_CONTAINER |
YANG container |
|
NCX_BT_CHOICE |
YANG choice. This is a meta-type and placeholder. It does not appear in the data tree. |
|
NCX_BT_CASE |
YANG case. This is a meta-type and placeholder. It does not appear in the data tree. |
|
NCX_BT_LIST |
YANG list |
|
NCX_BT_EXTERN |
Internal 'external' data type, used in yangcli. It indicates that the content is actually in an external file. |
|
NCX_BT_INTERN |
Internal 'buffer' data type, used in yangcli. The content is actually stored verbatim in an internal buffer. |
There is a temporary data structure which is attached to a data node while editing operations are in progress, called val_editvars_t. This structure is used by the functions in agt/agt_val.c to manipulate the value tree nodes during an <edit-config>, <copy-config>, <load-config>, or <commit> operation.
The SIL callback functions may wish to refer to the fields in this data structure. There is also a SIL cookie field to allow data to be transferred from one callback stage to the later stages. For example, if an edit operation caused the device instrumentation to reserve some memory, then this cookie could store that pointer.
The following typedef is used to define the val_editvars_t structure:
/* one set of edit-in-progress variables for one value node */
typedef struct val_editvars_t_ {
/* these fields are only used in modified values before they are
* actually added to the config database (TBD: move into struct)
* curparent == parent of curnode for merge
*/
struct val_value_t_ *curparent;
op_editop_t editop; /* effective edit operation */
op_insertop_t insertop; /* YANG insert operation */
xmlChar *insertstr; /* saved value or key attr */
struct xpath_pcb_t_ *insertxpcb; /* key attr for insert */
struct val_value_t_ *insertval; /* back-ptr */
boolean iskey; /* T: key, F: value */
boolean operset; /* nc:operation here */
void *pcookie; /* user pointer cookie */
int icookie; /* user integer cookie */
} val_editvars_t;
The following fields within the val_editvars_t are highlighted:
val_editvars_t Fields
|
Field |
Description |
|
curparent |
A 'new' node will use this field to remember the parent of the 'current' value. This is needed to support the YANG insert operation. |
|
editop |
The effective edit operation for this node. |
|
insertop |
The YANG insert operation, if any. |
|
insertstr |
The YANG 'value' or 'key' attribute value string, used to support the YANG insert operation. |
|
insertxpcb |
XPath parser control block for the insert 'key' expression, if needed. Used to support the YANG insert operation. |
|
insertval |
Back pointer to the value node to insert ahead of, or behind, if needed. Used to support the 'before' and 'after' modes of the YANG insert operation. |
|
iskey |
TRUE if this is a key leaf. FALSE otherwise. |
|
operset |
TRUE if there was an nc:operation attribute found in this node; FALSE if the 'editop' is derived from its parent. |
|
pcookie |
SIL user pointer cookie. Not used by the server. Reserved for SIL callback code. |
|
icookie |
SIL user integer cookie. Not used by the server. Reserved for SIL callback code. |
The val_value_t data structure is used to maintain the internal representation of all NETCONF databases, non-configuration data available with the <get> operation, all RPC operation input and output parameters, and all notification contents.
The following typedef is used to define a value node:
/* one value to match one type */
typedef struct val_value_t_ {
dlq_hdr_t qhdr;
/* common fields */
struct obj_template_t_ *obj; /* bptr to object def */
typ_def_t *typdef; /* bptr to typdef if leaf */
const xmlChar *name; /* back pointer to elname */
xmlChar *dname; /* AND malloced name if needed */
struct val_value_t_ *parent; /* back-ptr to parent if any */
xmlns_id_t nsid; /* namespace ID for this node */
ncx_btype_t btyp; /* base type of this value */
uint32 flags; /* internal status flags */
ncx_data_class_t dataclass; /* config or state data */
/* YANG does not support user-defined meta-data but NCX does.
* The <edit-config>, <get> and <get-config> operations
* use attributes in the RPC parameters, the metaQ is still used
*
* The ncx:metadata extension allows optional attributes
* to be added to object nodes for anyxml, leaf, leaf-list,
* list, and container nodes. The config property will
* be inherited from the object that contains the metadata
*
* This is used mostly for RPC input parameters
* and is strongly discouraged. Full edit-config
* support is not provided for metdata
*/
dlq_hdr_t metaQ; /* Q of val_value_t */
/* value editing variables */
val_editvars_t *editvars; /* edit-in-progress vars */
status_t res; /* validationt result */
/* Used by Agent only:
* if this field is non-NULL, then the entire value node
* is actually a placeholder for a dynamic read-only object
* and all read access is done via this callback function;
* the real data type is getcb_fn_t *
*/
void *getcb;
/* if this field is non-NULL, then a malloced value struct
* representing the real value retrieved by
* val_get_virtual_value, is cached here for XPath filtering
* TBD: add timestamp to reuse cached entries for some time
* period
*/
struct val_value_t_ *virtualval;
/* these fields are used for NCX_BT_LIST */
struct val_index_t_ *index; /* back-ptr/flag in use as index */
dlq_hdr_t indexQ; /* Q of val_index_t or ncx_filptr_t */
/* this field is used for NCX_BT_CHOICE
* If set, the object path for this node is really:
* $this --> casobj --> casobj.parent --> $this.parent
* the OBJ_TYP_CASE and OBJ_TYP_CHOICE nodes are skipped
* inside an XML instance document
*/
struct obj_template_t_ *casobj;
/* these fields are for NCX_BT_LEAFREF
* NCX_BT_INSTANCE_ID, or tagged ncx:xpath
* value stored in v union as a string
*/
struct xpath_pcb_t_ *xpathpcb;
/* union of all the NCX-specific sub-types
* note that the following invisible constructs should
* never show up in this struct:
* NCX_BT_CHOICE
* NCX_BT_CASE
* NCX_BT_UNION
*/
union v_ {
/* complex types have a Q of val_value_t representing
* the child nodes with values
* NCX_BT_CONTAINER
* NCX_BT_LIST
*/
dlq_hdr_t childQ;
/* Numeric data types:
* NCX_BT_INT8, NCX_BT_INT16,
* NCX_BT_INT32, NCX_BT_INT64
* NCX_BT_UINT8, NCX_BT_UINT16
* NCX_BT_UINT32, NCX_BT_UINT64
* NCX_BT_DECIMAL64, NCX_BT_FLOAT64
*/
ncx_num_t num;
/* String data types:
* NCX_BT_STRING
* NCX_BT_INSTANCE_ID
*/
ncx_str_t str;
val_idref_t idref;
ncx_binary_t binary; /* NCX_BT_BINARY */
ncx_list_t list; /* NCX_BT_BITS, NCX_BT_SLIST */
boolean boo; /* NCX_BT_EMPTY, NCX_BT_BOOLEAN */
ncx_enum_t enu; /* NCX_BT_UNION, NCX_BT_ENUM */
xmlChar *fname; /* NCX_BT_EXTERN */
xmlChar *intbuff; /* NCX_BT_INTERN */
} v;
} val_value_t;
The following table highlights the fields in this data structure:
val_value_t Fields
|
Field |
Description |
|
qhdr |
Internal queue header to allow a value node to be stored in a queue. A complex node maintains a child queue of val_value_t nodes. |
|
obj |
Back pointer to the object template for this data node |
|
typdef |
Back pointer to the typedef structure if this is a leaf or leaf-list node. |
|
name |
Back pointer to the name string for this node |
|
dname |
Malloced name string if the client or server changed the name of this node, so the object node name is not being used. This is used for anyxml processing (and other things) to allow generic objects (container, string, empty, etc.) to be used to represent the contents of an 'anyxml' node. |
|
parent |
Back pointer to the parent of this node, if any |
|
nsid |
Namespace ID for this node. This may not be the same as the object node namespace ID, e.g., anyxml child node contents will override the generic object namespace. |
|
btyp |
The ncx_btype_t base type enumeration for this node. This is the final resolved value, in the event the object type is not a final resolved base type. |
|
flags |
Internal flags field. Do not access directly. |
|
dataclass |
Internal config or non-config enumeration |
|
metaQ |
Queue of val_value_t structures that represent any meta-variables (XML attributes) found for this data node. For example, the NETCONF filter 'type' and 'select' attributes are defined for the <filter> element in yuma-netconf.yang. |
|
editvars |
Pointer to the malloced edit variables structure for this data node. This node will be freed (and NULL value) when the edit variables are not in use. |
|
res |
Internal validation result status for this node during editing or parsing. |
|
getcb |
Internal server callback function pointer. Used only if this is a 'virtual' node, and the actual value node contents are generated by a SIL callback function instead of being stored in the node itself. |
|
virtualval |
The temporary cached virtual node value, if the getcb pointer is non-NULL. |
|
indexQ |
Queue of internal data structures used during parsing and filtering streamed output. |
|
casobj |
Back pointer to the OBJ_TYP_CASE object node for this data node, if this node is a top-level child of a YANG case statement. |
|
xpathpcb |
XPath parser control block, used if this value contains some sort of XPath string or instance-identifier. For example, the XML namespace ID mappings are stored, so the XML prefix map generated for the <rpc-reply> will contain and reuse the proper namespace attributes, as needed. |
|
v |
Union of different internal fields, depending on the 'btyp' field value. |
|
v.childQ |
Queue of val_value_t child nodes, if this is a complex node. |
|
v.num |
ncx_num_t for all numeric data types |
|
v.str |
Malloced string value for the string data type |
|
v.idref |
Internal data structure for the YANG identityref data type |
|
v.binary |
Internal data structure for the YANG binary data type |
|
v.list |
Internal data structure for YANG bits and NCX xsdlist data types |
|
v.boo |
YANG boolean data type |
|
v.enu |
Internal data structure for YANG enumeration data type |
|
v.fname |
File name for NCX 'external' data type |
|
v.intbuff |
Malloced buffer for 'internal' data type |
There are a set of macros defined to access the fields within a val_value_t structure.
These should be used instead of accessing the fields directly. There are also functions defined as well. These macros are provided in addition the the access functions for quick access to the actual node value. These macros must only be used when the base type ('btyp') field has been properly set and known by the SIL code. Some auto-generated SIL code uses these macros.
The following table summarized the val_value_t macros that are defined in ncx/val.h:
|
Macro |
Description |
|
VAL_BOOL(V) |
Access value for NCX_BT_BOOLEAN |
|
VAL_EMPTY(V) |
Access value for NCX_BT_EMPTY |
|
VAL_DOUBLE(V) |
Access value for NCX_BT_FLOAT64 |
|
VAL_STRING(V) |
Access value for NCX_BT_STRING |
|
VAL_BINARY(V) |
Access value for NCX_BT_BINARY |
|
VAL_ENU(V) |
Access entire ncx_enum_t structure for NCX_BT_ENUM |
|
VAL_ENUM(V) |
Access enumeration integer value for NCX_BT_ENUM |
|
VAL_ENUM_NAME(V) |
Access enumeration name string for NCX_BT_ENUM |
|
VAL_FLAG(V) |
Deprecated: use VAL_BOOL instead |
|
VAL_LONG(V) |
Access NCX_BT_INT64 value |
|
VAL_INT(V) |
Access NCX_BT_INT32 value |
|
VAL_INT8(V) |
Access NCX_BT_INT8 value |
|
VAL_INT16(V) |
Access NCX_BT_INT16 value |
|
VAL_STR(V) |
Deprecated: use VAL_STRING instead |
|
VAL_INSTANCE_ID(V) |
Access NCX_BT_INSTANCE_ID value |
|
VAL_IDREF(V) |
Access entire val_idref_t structure for NCX_BT_IDREF |
|
VAL_IDREF_NSID(V) |
Access the identityref namespace ID for NCX_BT_IDREF |
|
VAL_IDREF_NAME(V) |
Access the identityref name string for NCX_BT_IDREF |
|
VAL_UINT(V) |
Access the NCX_BT_UINT32 value |
|
VAL_UINT8(V) |
Access the NCX_BT_UINT8 value |
|
VAL_UINT16(V) |
Access the NCX_BT_UINT16 value |
|
VAL_ULONG(V) |
Access the NCX_BT_UINT64 value |
|
VAL_DEC64(V) |
Access the ncx_dec64structure for NCX_BT_DEC64 |
|
VAL_LIST(V) |
Access the ncx_list_t structure for NCX_BT_LIST |
|
VAL_BITS |
Access the ncx_list_t structure for NCX_BT_BITS. (Same as VAL_LIST) |
The file ncx/val.h contains many API functions so that object properties do not have to be accessed directly. In addition, the file ncx/val_util.h contains more (high-level) utility functions. The following table highlights the most commonly used functions. Refer to the H files for a complete definition of each API function.
val_value_t Access Functions
|
Function |
Description |
|
val_new_value |
Malloc a new value node with type NCX_BT_NONE. |
|
val_init_complex |
Initialize a malloced value node as one of the complex data types. |
|
val_init_virtual |
Initialize a malloced value node as a virtual node (provide a 'get' callback function). |
|
val_init_from_template |
Initialize a malloced value node using an object template. This is the most common form of the init function used by SIL callback functions. |
|
vaL-free_value |
Clean and free a malloced value node. |
|
val_set_name |
Set or replace the value node name. |
|
val_set_qname |
Set or replace the value node namespace ID and name. |
|
val_string_ok |
Check if the string value is valid for the value node object type. |
|
val_string_ok_errinfo |
Check if the string value is valid for the value node object type, and provide the error information to use if it is not OK. |
|
val_list_ok |
Check if the list value is valid for the value node object type. |
|
val_list_ok_errinfo |
Check if the list value is valid for the value node object type, and provide the error information to use if it is not OK. |
|
val_enum_ok |
Check if the enumeration value is valid for the value node object type. |
|
val_enum_ok_errinfo |
Check if the enumeration value is valid for the value node object type, and provide the error information to use if it is not OK. |
|
val_bit_ok |
Check if the bits value is valid for the value node object type. |
|
val_idref_ok |
Check if the identityref value is valid for the value node object type. |
|
val_parse_idref |
Convert a string to an internal QName string into its various parts and find the identity struct that is being referenced (if available). |
|
val_simval_ok |
Check if the smple value is valid for the value node object type. |
|
val_simval_ok_errinfo |
Check if the simple value is valid for the value node object type, and provide the error information to use if it is not OK. |
|
val_get_first_meta |
Get the first meta-variable (XML attribute value) for a value node. |
|
val_get_next_meta |
Get the next meta-variable (XML attribute value) for a value node. |
|
val_find_meta |
Find the specified meta-variable in a value node. |
|
val_dump_value |
Debug function to print the contents of any value node. |
|
val_dump_value_ex |
Debug function to print the contents of any value node, with extended parameters to control the output. |
|
val_dump_value_max |
Debug function to print the contents of any value node, with full control of the output parameters. |
|
val_set_string |
Set a malloced value node as a generic string value. Used instead of val_init_from_template. |
|
val_set_string2 |
Set a malloced value node as a specified string type. Used instead of val_init_from_template. |
|
val_set_simval |
Set a malloced value node as a specified simple type. Used instead of val_init_from_template. |
|
val_set_simval_str |
Set a malloced value node as a specified simple type. Used instead of val_init_from_template. Use a counted string value instead of a zero-terminated string value. |
|
val_make_string |
Create a complete malloced generic string value node. |
|
val_clone |
Clone a value node |
|
val_clone_test |
Clone a value node with a 'test' callback function to prune certain descendant nodes during the clone procedure. |
|
val_clone_config_data |
Clone a value node but skip all the non-configuration descendant nodes. |
|
val_add_child |
Add a child value node to a parent value node. |
|
val_insert_child |
Insert a child value node into a specific spot into a parent value node. |
|
val_remove_child |
Remove a child value node from its parent. |
|
val_swap_child |
Replace a child node within its parent with a different value node. |
|
val_first_child_match |
Match a child node name; Used for partial command completion in yangcli. |
|
val_next_child_match |
Match the next child node name; Used for partial command completion in yangcli. |
|
val_get_first_child |
Get the first child value node. |
|
val_get_next_child |
Get the next child value node. |
|
val_find_child |
Find a specific child value node. |
|
val_find_next_child |
Find the next occurrence of a specified child node. |
|
val_match_child |
Match a potential partial node name against the child node names, and return the first match found, if any. |
|
val_child_cnt |
Get the number of child nodes within a parent node. |
|
val_liststr_count |
Get the number of strings within an NCX_BT_LIST value node. |
|
val_index_match |
Check if 2 value list nodes have the same set of key leaf values. |
|
val_compare |
Compare 2 value nodes |
|
val_compare_ex |
Compare 2 value nodes with extra parameters. |
|
val_compare_to_string |
Compare a value node to a string value instead of another value node. |
|
val_sprintf_simval_nc |
Output the value node as a string into the specified buffer. |
|
val_make_sprintf_string |
Malloc a buffer and fill it with a zero-terminated string representation of the value node. |
|
val_resolve_scoped_name |
Find a descendant node within a value node, from a relative path expression. |
|
val_has_content |
Return TRUE if the value node has any content; FALSE if an empty XML element could represent its value. |
|
val_has_index |
Return TRUE if the value node is a list with a key statement. |
|
val_get_first_index |
Get the first index node for the specified list value node. |
|
val_get_next_index |
Get the next index node for the specified list value node. |
|
val_set_extern |
Set a malloced value node as an NCX_BT_EXTERN internal data type. |
|
val_set_intern |
Set a malloced value node as an NCX_BT_INTERN internal data type. |
|
val_fit_oneline |
Return TRUE if the value node should fit on 1 display line; Sometimes a guess is made instead of determining the exact value. XML namespace declarations generated during XML output can cause this function value to sometimes be wrong. |
|
val_create_allowed |
Return TRUE if the NETCONF create operation is allowed for the specified value node. |
|
val_delete_allowed |
Return TRUE if the NETCONF delete operation is allowed for the specified value node. |
|
val_is_config_data |
Return TRUE if the value node represents configuration data. |
|
val_get_virtual_value |
Get the value for a virtual node from its 'get' callback function. |
|
val_is_default |
Return TRUE if the value node is set to its YANG default value. |
|
val_is_real |
Check if a value node is a real node or one of the abstract node types.
|
|
val_get_parent_nsid |
Get the namespace ID for the parent value node of a specified child node. |
|
val_instance_count |
Get the number of occurrences of the specified child value node within a parent value node. |
|
val_need_quotes |
Return TRUE if the printed string representation of a value node needs quotes (because it contains some whitespace or special characters). |
|
val_get_dirty_flag |
Check if a value node has been altered by an RPC operation, but this edit has not been finalized yet. |
|
val_get_nest_level |
Get the current numeric nest level of the specified value node. |
|
val_get_mod_name |
Get the module name for the specified value node. |
|
val_get_mod_prefix |
Get the module prefix string for the specified value node. |
|
val_get_nsid |
Get the namespace ID for the specified value node. |
|
val_change_nsid |
Change the namespace ID for the specified value node and all of its descendents. |
|
val_set_pcookie |
Set the SIL pointer cookie in the value node editvars structure. |
|
val_set_icookie |
Set the SIL integer cookie in the value node editvars structure. |
|
val_get_pcookie |
Get the SIL pointer cookie in the value node editvars structure. |
|
val_get_icookie |
Get the SIL integer cookie in the value node editvars structure. |
|
val_get_typdef |
Get the typedef structure for a leaf or leaf-list value node. |
|
val_move_children |
Move all the child nodes of one complex value node to another complex value node. |
|
val_set_canonical_order |
Re-order the descendant nodes of a value node so they are in YANG order. Does not change the relative order of system-ordered lists and leaf-lists. |
|
val_gen_index_chain |
Generate the internal key leaf lookup chain for a list value node.. |
|
val_add_defaults |
Generate the leafs that have default values. |
|
val_instance_check |
Check a value node against its template to see if the correct number of descendant nodes are present. |
|
val_get_choice_first_set |
Get the first real node that is present for a conceptual choice statement. |
|
val_get_choice_next_set |
Get the next real node that is present for a conceptual choice statement. |
|
val_choice_is_set |
Return TRUE if some real data node is present for a conceptual choice statement. |
|
val_new_child_val |
Create a child node during an edit operation. Used by the server. SIL code does not need to maintain the value tree. |
|
val_gen_instance_id |
Malloc and generate the YANG instance-identifier string for the value node. |
|
val_check_obj_when |
Check if an object node has any 'when' statements, and if so, evaluate the XPath condition(s) against the value tree to determine if the object should be considered present or not. |
|
val_check_child_conditional |
Check if a child object node has any FALSE 'if-feature' or 'when' statements. |
|
val_is_mandatory |
Check if the child object node is currently mandatory or optional. |
|
val_get_xpathpcb |
Access the XPath parser control block for this value node, if any. |
|
val_make_simval_obj |
Malloc and fill in a value node from an object template and a value string. |
|
val_set_simval_obj |
Fill in a value node from an object template and a value string. |
There are some high-level SIL callback utilities in agt/agt_util.h. These functions access the lower-level functions in libncx to provide simpler functions for common SIL tasks.
The following table highlights the functions available in this module:
agt/agt_util Functions
|
Function |
Description |
|
agt_get_cfg_from_parm |
For value nodes that represent a NETCONF configuration database name (e.g., empty element named 'running'). The configuration control block for the referenced database is retrieved. |
|
agt_get_inline_cfg_from_parm |
For value nodes that represent inline NETCONF configuration data. The value node for the inline config node is retrieved. |
|
agt_get_parmval |
Get the specified parameter name within the RPC input section, from an RPC message control block. |
|
agt_record_error |
Generate a complete RPC error record to be used when the <rpc-reply> is sent. |
|
agt_record_error_errinfo |
Generate a complete RPC error record to be used when the <rpc-reply> is sent, using the YANG specified error information, not the default error information. |
|
agt_record_attr_error |
Generate a complete RPC error record to be used when the <rpc-reply> is sent for an XML attribute error. |
|
agt_record_insert_error |
Generate a complete RPC error record to be used when the <rpc-reply> is sent for a YANG insert operation error. |
|
agt_record_unique_error |
Generate a complete RPC error record to be used when the <rpc-reply> is sent for a YANG unique statement contraint error. |
|
agt_check_default |
val_nodetest_fn_t Node Test Callback function to filter out default data from streamed replies, according to the server's definition of a default node. |
|
agt_check_save |
val_nodetest_fn_t Node Test Callback function to filter out data nodes that should not be saved to NV-storage. |
|
agt_enable_feature |
Enable the specified YANG feature |
|
agt_disable_feature |
Disable the specified YANG feature |
|
agt_make_leaf |
Create a child value node. |
|
agt_make_virtual_leaf |
Create a virtual value child node. Most device monitoring leafs use this function because the value is retrieved with a device-specific API, not stored in the value tree. |
|
agt_init_cache |
Initialize a cached pointer to a node in a data tree. |
|
agt_check_cache |
Check if a cached pointer to a node in a data tree needs to be updated or set to NULL. |
Each SIL has 2 initialization functions and 1 cleanup function that must be present.
The first initialization callback function is used to set up the configuration related objects.
The second initialization callback is used to setup up non-configuration objects, after the running configuration has been loaded from the startup file.
The cleanup callback is used to remove all SIL data structures and unregister all callback functions.
These are the only SIL functions that the server will invoke directly. They are generated by yangdump with the --format=c parameter, and usually do not require any editing by the developer.
Most of the work done by SIL code is through callback functions for specific RPC operations and database objects. These callback functions are registered during the initialization functions.
The stage 1 initialization function is the first function called in the library by the server.
If the netconfd configuration parameters include a 'load' command for the module, then this function will be called during server initialization. It can also be called if the <load> operation is invoked during server operation.
This function MUST NOT attempt to access any database. There will not be any configuration databases if this function is called during server initialization. Use the 'init2' function to adjust the running configuration.
This callback function is expected to perform the following functions:
initialize any module static data
make sure the requested module name and optional revision date parameters are correct
load the requested module name and revision with ncxmod_load_module
setup top-level object cache pointers (if needed)
register any RPC method callbacks with agt_rpc_register_method
register any database object callbacks with agt_cb_register_callback
perform any device-specific and/or module-specific initialization
Name Format:
y_<modname>_init
Input:
modname == string containing module name to load
revision == string containing revision date to use
== NULL if the operator did not specify a revision.
Returns:
operation status (0 if success)
Example function generated by yangdump:
/********************************************************************
* FUNCTION y_toaster_init
*
* initialize the toaster server instrumentation library
*
* INPUTS:
* modname == requested module name
* revision == requested version (NULL for any)
*
* RETURNS:
* error status
********************************************************************/
status_t
y_toaster_init (
const xmlChar *modname,
const xmlChar *revision)
{
agt_profile_t *agt_profile;
status_t res;
y_toaster_init_static_vars();
/* change if custom handling done */
if (xml_strcmp(modname, y_toaster_M_toaster)) {
return ERR_NCX_UNKNOWN_MODULE;
}
if (revision && xml_strcmp(revision, y_toaster_R_toaster)) {
return ERR_NCX_WRONG_VERSION;
}
agt_profile = agt_get_profile();
res = ncxmod_load_module(
y_toaster_M_toaster,
y_toaster_R_toaster,
&agt_profile->agt_savedevQ,
&toaster_mod);
if (res != NO_ERR) {
return res;
}
toaster_obj = ncx_find_object(
toaster_mod,
y_toaster_N_toaster);
if (toaster_mod == NULL) {
return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);
}
make_toast_obj = ncx_find_object(
toaster_mod,
y_toaster_N_make_toast);
if (toaster_mod == NULL) {
return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);
}
cancel_toast_obj = ncx_find_object(
toaster_mod,
y_toaster_N_cancel_toast);
if (toaster_mod == NULL) {
return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);
}
toastDone_obj = ncx_find_object(
toaster_mod,
y_toaster_N_toastDone);
if (toaster_mod == NULL) {
return SET_ERROR(ERR_NCX_DEF_NOT_FOUND);
}
res = agt_rpc_register_method(
y_toaster_M_toaster,
y_toaster_N_make_toast,
AGT_RPC_PH_VALIDATE,
y_toaster_make_toast_validate);
if (res != NO_ERR) {
return res;
}
res = agt_rpc_register_method(
y_toaster_M_toaster,
y_toaster_N_make_toast,
AGT_RPC_PH_INVOKE,
y_toaster_make_toast_invoke);
if (res != NO_ERR) {
return res;
}
res = agt_rpc_register_method(
y_toaster_M_toaster,
y_toaster_N_cancel_toast,
AGT_RPC_PH_VALIDATE,
y_toaster_cancel_toast_validate);
if (res != NO_ERR) {
return res;
}
res = agt_rpc_register_method(
y_toaster_M_toaster,
y_toaster_N_cancel_toast,
AGT_RPC_PH_INVOKE,
y_toaster_cancel_toast_invoke);
if (res != NO_ERR) {
return res;
}
res = agt_cb_register_callback(
y_toaster_M_toaster,
(const xmlChar *)"/toaster",
(const xmlChar *)"2009-11-20",
y_toaster_toaster_edit);
if (res != NO_ERR) {
return res;
}
/* put your module initialization code here */
return res;
} /* y_toaster_init */
The stage 2 initialization function is the second function called in the library by the server:
It will only be called if the stage 1 initialization is called first, and it returns 0 (NO_ERR status).
This function is used to initialize any needed data structures in the running configuration, such as factory default configuration, read-only counters and status objects.
It is called after the startup configuration has been loaded into the server.
If the <load> operation is used during server operation, then this function will be called immediately after the state 1 initialization function.
Note that configuration data structures that are loaded during server initialization (load_running_config) will be handled by the database callback functions registered during phase 1 initialization.
Any server-created configuration nodes should be created during phase 2 initialization (this function), after examining the explicitly-provided configuration data. For example, the top-level /nacm container will be created (by agt_acm.c) if it is not provided in the startup configuration.
This callback function is expected to perform the following functions:
load non-configuration data structures into the server (if needed)
initialize top-level data node cache pointers (if needed)
load factory-default configuration data structures into the server (if needed)
optionally save a cached pointer to a data tree node (such as the root node for the module). The agt_create_cache function in agt/agt_util.h is used to initialize such a module-static variable.
Name Format:
y_<modname>_init2
Returns:
operation status (0 if success)
Example function generated by yangdump:
/********************************************************************
* FUNCTION y_toaster_init2
*
* SIL init phase 2: non-config data structures
* Called after running config is loaded
*
* RETURNS:
* error status
********************************************************************/
status_t
y_toaster_init2 (void)
{
status_t res;
res = NO_ERR;
toaster_val = agt_init_cache(
y_toaster_M_toaster,
y_toaster_N_toaster,
&res);
if (res != NO_ERR) {
return res;
}
/* put your init2 code here */
return res;
} /* y_toaster_init2 */
The cleanup function is called during server shutdown. It is only called if the stage 1 initialization function is called. It will be called right away if either the stage 1 or stage 2 initialization functions return a non-zero error status.
This callback function is expected to perform the following functions:
cleanup any module static data
free any top-level object cache pointers (if needed)
unregister any RPC method callbacks with agt_rpc_unregister_method
unregister any database object callbacks with agt_cb_unregister_callbacks
perform any device-specific and/or module-specific cleanup
Name Format:
y_<modname>_cleanup
Example function generated by yangdump:
/********************************************************************
* FUNCTION y_toaster_cleanup
* cleanup the server instrumentation library
*
********************************************************************/
void
y_toaster_cleanup (void)
{
agt_rpc_unregister_method(
y_toaster_M_toaster,
y_toaster_N_make_toast);
agt_rpc_unregister_method(
y_toaster_M_toaster,
y_toaster_N_cancel_toast);
agt_cb_unregister_callbacks(
y_toaster_M_toaster,
(const xmlChar *)"/toaster");
/* put your cleanup code here */
} /* y_toaster_cleanup */
This section briefly describes the SIL code that a developer will need to create to handle the data-model specific details. SIL functions access internal server data structures, either directly or through utility functions. Database mechanics and XML processing are done by the server engine, not the SIL code. A more complete reference can be found in section 5.
When a <rpc> request is received, the NETCONF server engine will perform the following tasks before calling any SIL:
parse the RPC operation element, and find its associated YANG rpc template
if found, check if the session is allowed to invoke this RPC operation
if the RPC is allowed, parse the rest of the XML message, using the rpc_template_t for the RPC operation to determine if the basic structure is valid.
if the basic structure is valid, construct an rpc_msg_t data structure for the incoming message.
check all YANG machine-readable constraints, such as must, when, if-feature, min-elements, etc.
if the incoming message is completely 'YANG valid', then the server will check for an RPC validate function, and call it if found. This SIL code is only needed if there are additional system constraints to check. For example:
need to check if a configuration name such as <candidate/> is supported
need to check if a configuration database is locked by another session
need to check description statement constraints not covered by machine-readable constraints
need to check if a specific capability or feature is enabled
If the validate function returns a NO_ERR status value, then the server will call the SIL invoke callback, if it is present. This SIL code should always be present, otherwise the RPC operation will have no real affect on the system.
At this point, an <rpc-reply> is generated, based on the data in the rpc_msg_t.
Errors are recorded in a queue when they are detected.
The server will handle the error reply generation for all errors it detects.
For SIL detected errors, the agt_record_error function in agt/agt_util.h is usually used to save the error details.
Reply data can be generated by the SIL invoke callback function and stored in the rpc_msg_t structure.
Replay data can be streamed by the SIL code via reply callback functions. For example, the <get> and <get-config> operations use callback functions to deal with filters, and stream the reply by walking the target data tree.
After the <rpc-reply> is sent, the server will check for an RPC post reply callback function. This is only needed if the SIL code allocated some per-message data structures. For example, the rpc_msg_t contains 2 SIL controlled pointers (rpc_user1 and rpc_user2). The post reply callback is used by the SIL code to free these pointers, if needed.
The database edit SIL callbacks are only used for database operations that alter the database. The validate and invoke callback functions for these operations will in turn invoke the data-model specific SIL callback functions, depending on the success or failure of the edit request.
All RPC operations are data-driven within the server, using the YANG rpc statement for the operation and SIL callback functions.
Any new protocol operation can be added by defining a new YANG rpc statement in a module, and providing the proper SIL code.
The agt_rpc_register_method function in agt/agt_rpc.h is used to provide a callback function for a specific callback phase. The same function can be used for multiple phases if desired.
/* Template for RPC server callbacks
* The same template is used for all RPC callback phases
*/
typedef status_t
(*agt_rpc_method_t) (ses_cb_t *scb,
rpc_msg_t *msg,
xml_node_t *methnode);
extern status_t
agt_rpc_register_method (const xmlChar *module,
const xmlChar *method_name,
agt_rpc_phase_t phase,
agt_rpc_method_t method);
agt_rpc_register_method
|
Parameter |
Description |
|
module |
The name of the module that contains the rpc statement |
|
method_name |
The identifier for the rpc statement |
|
phase |
AGT_PH_VALIDATE(0): validate phase |
|
method |
The address of the callback function to register |
The NETCONF server will parse the incoming XML message and construct an RPC message header, which is used to maintain state and any other message-specific data during the processing of an incoming <rpc> request.
The rpc_msg_t data structure in ncx/rpc.h is used for this purpose. The following table summarizes the fields:
rpc_msg_t
|
Field |
Type |
User Mode |
Description |
|
qhdr |
dlq_hdr_t |
none |
Queue header to store RPC messages in a queue (within the session header) |
|
mhdr |
xml_msg_hdr_t |
none |
XML message prefix map and other data used to parse the request and generate the reply. |
|
rpc_in_attrs |
xml_attrs_t * |
read |
Queue of xml_attr_t representing any XML attributes that were present in the <rpc> element. A callback function may add xml_attr_t structs to this queue to send in the reply. |
|
rpc_method |
obj_template_t * |
read |
Back-pointer to the object template for this RPC operation. |
|
rpc_agt_state |
int |
read |
Enum value (0, 1, 2) for the current RPC callback phase. |
|
rpc_err_option |
op_errop_t |