The following article illustrates how to utilize the GET2 callback in examples. Let us go through simple examples that will illustrate how to utilize the GET2 callbacks for container YANG node types.

Consider this simplified example, that represents GET2 callback for the “interface-state” container.


  container interfaces-state {
     config false;

     leaf in-errors { type uint32; }


The following C API code exemplifies a simple GET2 callback function for the above data model, which returns the “interfaces-state” container node with an additional leaf node when it is requested.

* FUNCTION  get2_container_interfaces
* Path: /interfaces-state
*   scb == session control block making the request 
*   msg == incoming XML message header 
*   get2cb == get2 control block for this callback request
*   return_valQ is filled with malloced val_value_t nodes
*    status: 
*      NO_ERR if executed OK and found OK 
*      ERR_NCX_NO_INSTANCE warning if no instance found
static status_t 
    get2_container_interfaces (ses_cb_t *scb, 
                               xml_msg_hdr_t *msg, 
                               getcb_get2_t *get2cb) 

    /* check the callback mode type */ 
    getcb_mode_t cbmode = GETCB_GET2_CBMODE(get2cb); 
    switch (cbmode) { 
    case GETCB_GET_VALUE: 
        return ERR_NCX_NO_INSTANCE; 
        return SET_ERROR(ERR_INTERNAL_VAL); 

    status_t res = NO_ERR;

    /* return all the child leaf and leaf-list nodes in the
     * interfaces-state container
    obj_template_t *obj = GETCB_GET2_OBJ(get2cb);

    /* get the interfaces-state child, 'in-errors' */
    obj_template_t *chobj =
                       (const xmlChar *)"in-errors");
    if (chobj) {

        /* use the chobj to make a return value */
        val_value_t *retval =
                                (const xmlChar *)"11",
        if (retval) {
            /* add the return value to the GET2 control block */
            getcb_add_return_val(get2cb, retval);
    } else {
        res = ERR_NCX_NOT_FOUND;

    /* choice and other complex nodes will be checked in a separate call */ 

    return res; 

}  /* get2_container_interfaces */ 

The val_make_simval_obj API returns malloced value structure or NULL if some error and create and set a val_value_t as a simple type from an object template instead of individual fields.

In the scenario above, make sure that the leaf object template was found. If it was not found, you may report an error immediately or ignore that node and skip the node generation process. However, do not generate the leaf node, if the object template was not found. 

To ensure that the GET2 callbacks are working as expected an application may retrieve running configuration and device state information as follows:

 <?xml version="1.0" encoding="UTF-8"?> 
  <rpc message-id="3" 
      <filter type="subtree"> 
        <interfaces-state xmlns="" /> 


The server may reply with:

     <rpc-reply message-id="101"
        <interfaces-state xmlns="">