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 GET2 callbacks for “container” elements DO NOT required to fill in any children elements. All additional leafs are optional to fill in. Any other descendant complex elements, such as lists, other containers, and choice elements must have their own callbacks functions.

The following C API code exemplifies a simple GET2 callback function for the data model, which returns the “interfaces-state” container element with an additional leaf element 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); 

    /* get the template for the “interfaces-state” container */ 
    obj_template_t *obj = GETCB_GET2_OBJ(get2cb); 
    status_t res = NO_ERR; 

    /* pretend leaf 'in-errors' is present */ 
    val_value_t *retval =
                            (const xmlChar *)"in-errors", 
                            (const xmlChar *)"8", 
    if (retval) { 
        getcb_add_return_val(get2cb, retval); 
    } else { 
        return res; 

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

    return res; 

}  /* get2_container_interfaces */ 

The agt_make_leaf2 API returns malloced value structure or NULL if some error. Alternatively, if you know the object template that defines the leaf node that you want to generate, the following more generic API can be used:


    obj_template_t *leafobj =
          (const xmlChar *)"in-errors");
    if (!leafobj) {
    /* report an error or do not try to generate the leaf, just skip it */

    /* pretend leaf 'in-errors' is present */ 
    val_value_t *retval = 
                             (const xmlChar *)"8", 

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. 


In the SIL, when you fill the data in get2cb with help of val_make_simval_obj() or analogous APIs, You don’t need to free the buffer because the server does clean up get2cb.

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="">