How to implement get_object for a container inside of a list

What does the implementation of get_object( ) look like when the object contains a list with a container inside of the list? How do you fill out the data_reply_value_array with the confd_data_reply_value_arrary( ) call?

As a variation to http://discuss.tail-f.com/t/how-to-add-the-support-of-the-get-object-callback-to-the-5-c-stats-example/142, following is the modified YANG model:

container arpentries {
  config false;
  tailf:callpoint arpe;
  list arpe {
    key "ip ifname";
    max-elements 1024;
    leaf ip {
      type inet:ip-address;
    }
    leaf ifname {
      type string;
    }
    container stat {
      leaf hwaddr {
        type string;
        mandatory true;
      }
      leaf permanent {
        type boolean;
        mandatory true;
      }
      leaf published {
        type boolean;
        mandatory true;
      }
    }
  }
}

The get_object( ) implementation will look like the following:

static int get_object(struct confd_trans_ctx *tctx,
                      confd_hkeypath_t *keypath)
{
    confd_value_t v[6];

    struct aentry *ae = find_ae(keypath, tctx->t_opaque, 0);
    if (ae == NULL) {
        confd_data_reply_not_found(tctx);
        return CONFD_OK;
    }

    CONFD_SET_IPV4(&v[0], ae->ip4);
    CONFD_SET_STR(&v[1], ae->iface);

    CONFD_SET_XMLTAG(&v[2], arpe_stat, arpe__ns);

    if (ae->hwaddr == NULL) {
        CONFD_SET_NOEXISTS(&v[3]);
    } else {
        CONFD_SET_STR(&v[3], ae->hwaddr);
    }
    CONFD_SET_BOOL(&v[4], ae->perm);
    CONFD_SET_BOOL(&v[5], ae->pub);

    confd_data_reply_value_array(tctx, v, 6);

    return CONFD_OK;
}

From the above code, you will notice that the XMLTAG element of the data_reply_value_array should be set to the name of the internal container. Refer to the description for confd_data_reply_value_array( ) in the confd_lib_dp section in Volume 3 of the ConfD man-pages for more information on how to work with containers within an object.

1 Like

When you have a more complex yang model where you use for example “augment” and provide values from multiple namespaces in your reply you want to use confd_data_reply_tag_value_array() to provide the data to ConfD.

The get_object() implementation of the yang model in the previos post can then be something like this:

static int get_object(struct confd_trans_ctx *tctx,
                      confd_hkeypath_t *keypath)
{
    confd_tag_value_t tv[7];

    struct aentry *ae = find_ae(keypath, tctx->t_opaque, 0);
    if (ae == NULL) {
        confd_data_reply_not_found(tctx);
        return CONFD_OK;
    }

    CONFD_SET_TAG_IPV4(&tv[0], arpe_ip, ae->ip4);
    CONFD_SET_TAG_STR(&tv[1], arpe_ifname, ae->iface);
    CONFD_SET_TAG_XMLBEGIN(&tv[2], arpe_stat, arpe__ns);
    CONFD_SET_TAG_STR(&tv[3], arpe_hwaddr, ae->hwaddr);
    CONFD_SET_TAG_BOOL(&tv[4], arpe_permanent, ae->perm);
    CONFD_SET_TAG_BOOL(&tv[5], arpe_published, ae->pub);
    CONFD_SET_TAG_XMLEND(&tv[6], arpe_stat, arpe__ns);

    confd_data_reply_tag_value_array(tctx, tv, 7);

    return CONFD_OK;
}

If you do not want to reply with any value for the hwaddr, you just leave it out from the tag value reply.

@cohult @waitai
With reference to “How to add the support of the get_object() callback to the 5-c_stats example?”,
Would like to know the confd trace pattern in terms of get_object & get_next callback registration for below yang hierarchy. How many get_object & get_next involved & for which hierarchy get_object will be invoked. It will be helpful, if you explain with the example & traces.

Container A
  |- List A-A
  |- List A-B
  |- List A-C
        |- Sub-Container C-B (sub container of List A-C)
              |- Leaf B-A
              |- List B-B
              |- Sub-Container C  (sub container of sub container's C-B)
                    |- Leaf C-A
                    |- Leaf C-B