How to add the support of the get_next_object() callback to the 5-c_stats example?

Hi,

In case a nested list exists in the arpe list, how it will be filled with get_next_object?
For the functions get_next and get_elem, I have implemented new functions(for example get_next_nested, get_elem_nested) using a new callpoint for the nested list data. Should I also implement a new get_next_object_nested function (I’ve tried this but it is not triggered) or there is a special way to fill obj object?

Thank you,
Olia

Hello,

please see description in the man confd_types manpage,
namely section “XML STRUCTURES”, subsection “Value Array
(or Tagged Value Array, depending on which callback/data you need to return):
specifically:

2. List nodes use a single array element, with type C_NOEXISTS (value ignored), regardless of the actual number of entries or their contents

(plus other specific rules for list entry child nodes, e.g. empty leaves etc.)

Returning the “C_NOEXISTS” as a value of the inner list will then cause ConfD to invoke another get_object() (or other) callbacks to iterate the children list entries of inner list with appropriate input keypath…

Assuming e.g. pseudo-model:

list outer {
    key "a";
    leaf a { type int32; }
    list inner {
        key "x";
        leaf x { type int32; }
        // other child-leaves
    }
    leaf b { type string; }
}

For a get_next_object() request with input keypath “/outer”, you can yield response like 11 C_NOEXISTS london.
(array of three confd_value_t the one representing inner list == C_NOEXISTS)

In case ConfD is interested internally in inner list values too, it will invoke further requests with input keypath “/outer{11}/inner”…

Thank you very much for your help it worked!

For future reference I used:
CONFD_SET_NOEXISTS(&(obj[i].v[5]));
(in case my list was the 5th element).

and the get_next_object_nested function was called, but another problem occurred.

My application fails because the find_next callback is not implemented:
DEBUG No find_next() callback installed --> CONFD_ERR DEBUG No find_next() callback installed Error on worker socket request: Bad protocol usage or unexpected retval (21): No find_next() callback installed

From the user guide I found that it is not mandatory to implement it and it can be replaced with get_next.

find_next()
This callback primarily optimizes cases where ConfD wants to start a list traversal at some other point than at the first entry of the list. It is mainly useful for lists with a large number of entries. If it is not registered, ConfD will use a sequence of get_next() calls to find the desired list entry.

So is find_next callback mandatory in this case or not, and if not why get_next is not called?

Thank you for your time

Yes, if you return next with value -1 in one of obj,

struct confd_tag_next_object {
    confd_tag_value_t *tv;
    int n;
    long next;
};

then find_next or find_next_object is mandatory

Thus a data provider can choose to give next values that uniquely identify list entries if that is convenient, or otherwise use -1 for all next elements - or a combination, e.g. -1 for all but the last entry. If any next value is given as -1, at least one of the find_next() and find_next_object() callbacks must be registered.

Ok it’s clear now!
Thank you very much for you feedback!

To clarify, a get_next_object() that doesn’t necessarily need find_next_object() and optimize the memory and CPU resources needed by chunking the confd_data_reply_next_object_arrays() could be implemented like this:

/* Keypath example */
/* /arpentries/arpe */
/*    2         1   */

static int max_nobjs = 100; // Chunk size hardcoded here to simplify

static int get_next_object(struct confd_trans_ctx *tctx,
			     confd_hkeypath_t *keypath, long next)
{
  int pos, i;
  confd_value_t *v;
  struct confd_next_object *obj;
  struct arpdata *dp = tctx->t_opaque;
  int n_list_entries;
  struct aentry *ae;

  if (need_arp(dp)) {
    if (run_arp(dp) == CONFD_ERR)
      return CONFD_ERR;
  }

  n_list_entries = dp->n_ae;
  ae = dp->arp_entries;
  
  if (next == -1) {
    pos = 0; /* ConfD wants to get the whole table / list from the beginning */
  } else if (next < n_list_entries) {
    pos = next; /* ConfD wants the table / list from a specific index */
  } else { /* next == n_list_entries, return nothing */
    confd_data_reply_next_object_array(tctx, NULL, -1, -1);
    return CONFD_OK;
  }

  /* If we have more than say 100 objects for smaller objects to return, we chunk the reply to ConfD in 100 objects at a time for best possible performance.       
  */
  if (n_list_entries - pos > max_nobjs) {
    nobj = max_nobjs + pos;
  } else {
    nobj = n_list_entries;
  }

  for(i = 0; i < pos; i++)
    ae = ae->next;
  
  obj = malloc(sizeof(struct confd_next_object) * (nobj + 2));
  v = (confd_value_t *) malloc(sizeof(confd_value_t) * nobj * N_LEAFS);

  for (i = 0; pos + i < nobj; i++) { /* Collect all the rows in the table / list entries */
    obj[i].v = &v[i * N_LEAFS];

    CONFD_SET_IPV4(&(obj[i].v[0]), ae->ip4);
    CONFD_SET_STR(&(obj[i].v[1]), ae->iface);
    if (ae->hwaddr == NULL) {
      CONFD_SET_NOEXISTS(&(obj[i].v[2]));
    } else {
      CONFD_SET_STR(&(obj[i].v[2]), ae->hwaddr);
    }
    CONFD_SET_BOOL(&(obj[i].v[3]), ae->perm);
    CONFD_SET_BOOL(&(obj[i].v[4]), ae->pub);
    obj[i].n = N_LEAFS;
    /* If we pass -1 here we will invoke find_next_object. If we instead pass next object ConfD will invoke get_next_object if there are more objects to be fetched
    */
    obj[i].next = pos+i+1; //-1;
    ae=ae->next;
  }
  if (pos + i == n_list_entries)
    obj[i++].v = NULL;
  confd_data_reply_next_object_arrays(tctx, obj, i, 0); /* Reply with an array of object arrays. I.e. the whole table / list */
  free(v);
  free(obj);
  return CONFD_OK;
}

Why we need to apply nobj+2 , i think it should be nobj+1, the tv of last instance is filled with null as end indication.

Why i get error: non-unique key values: {01:02:03:04:05:02} ?

Correct, it should say “1” there. Thanks!

Don’t know with that little info on the error you get. Check the run_arp() function of the example and verify that it parses the ARP table in your system correctly after calling “arp -an”

I have been wanting to provide a tag value array variant to this post for a while now as I belive it is more easy to follow than a plain value array. It does the same thing but use the tag too. The memory and performance overhead of using tag_value instead of value is negligible here, while the advantage is slightly improved readability:

// NOTE: See the original post for the other changes needed to the original (here ConfD-6.7.1) arpstat.c file 
...
static int navals;
static int max_nobjs = 100; // Chunk size hardcoded here to simplify

static int get_next_object_tag(struct confd_trans_ctx *tctx,
			     confd_hkeypath_t *keypath, long next)
{
  int i;
  confd_tag_value_t *tv;
  struct confd_tag_next_object *tobj;
  struct arpdata *dp = tctx->t_opaque;
  struct aentry *curr;

  if (next == -1) {  /* first call */
    if (need_arp(dp)) {
      if (run_arp(dp) == CONFD_ERR)
	return CONFD_ERR;
    }
    curr = dp->arp_entries;
  } else {
    curr = (struct aentry *)next;
  }
  if (curr == NULL) {
    confd_data_reply_next_key(tctx, NULL, -1, -1);
    return CONFD_OK;
  }

  tobj = malloc(sizeof(struct confd_tag_next_object) * (max_nobjs + 1));
  tv = (confd_tag_value_t *) malloc(sizeof(confd_tag_value_t) * max_nobjs * navals);
  
  for (i = 0; curr != NULL && i < max_nobjs; curr = curr->next, i++) { /* Collect max_nobjs or as many as there is rows in the table / list entries */
    tobj[i].tv = &tv[i * navals];

    CONFD_SET_TAG_IPV4(&(tobj[i].tv[0]), arpe_ip, curr->ip4);
    CONFD_SET_TAG_STR(&(tobj[i].tv[1]), arpe_ifname, curr->iface);
    if (curr->hwaddr == NULL) {
      CONFD_SET_TAG_NOEXISTS(&(tobj[i].tv[2]), arpe_hwaddr);
    } else {
      CONFD_SET_TAG_STR(&(tobj[i].tv[2]), arpe_hwaddr, curr->hwaddr);
    }
    CONFD_SET_TAG_BOOL(&(tobj[i].tv[3]), arpe_permanent, curr->perm);
    CONFD_SET_TAG_BOOL(&(tobj[i].tv[4]), arpe_published, curr->pub);
    tobj[i].n = navals;
    tobj[i].next = (long)curr->next;
  }
  
  if (curr == NULL) {
    tobj[i++].tv = NULL;
  }
  
  confd_data_reply_next_object_tag_value_arrays(tctx, tobj, i, 0); /* Reply with an array of object arrays. I.e. the whole table / list */
  free(tv);
  free(tobj);
  return CONFD_OK;
}

int main(int argc, char *argv[])
{
...
    data.get_next_object = get_next_object_tag;
...
    if (confd_load_schemas((struct sockaddr*)&addr,
                           sizeof (struct sockaddr_in)) != CONFD_OK)
        confd_fatal("Failed to load schemas from confd\n");

    object = confd_cs_node_cd(NULL, "/arpe:arpentries/arpe");
    navals = confd_max_object_size(object);
...
}

Thanks . i addressed the issue, i use the same memory for different key, i found before calling confd_reply_XX, it just point to the memory.

I’m wondering that what will happen if the size of list in response is larger than the request one.i mean CONFD reply more lists(for example: 3 instances) , however we just ask 2 instances. it seems that CONFD does not know how many lists now is requesting

i want to CONFD return data of confd_tag_value_t type, which API should i should in client? as i know , maapi_get_objects just get confd_value_t

We are getting the size of one list entry / object / row here, not the number of list entries / instances / objects / rows

Try maapi_get_values() / cdb_get_values().

@cohult, Do you know how confd only trigger get_next_object for Netconf request and confd still trigger get_next/get_elem for CLI. We use the external data provider and need to support 8k onts. Since get_next_object back-end code will stuck some while, we don’t want cli stuck. So we want to know how to trigger get_next_object only for Netconf request.
Much appreciated.

I think it is recommended not to return huge amount of objects (8k) in get_next_object. You should limit it to cca 100 elements (make it perhaps configurable and try to find best value). Then CLI will be responsive as well. In several cases (e.g. TAB completion) ConfD can choose itself to call get_next instead of get_next_object

Thanks @mnovak. Yes, we don’t return all the instances in one swoop and are trying out to find the best cca value. But actually, there are no customers complaining cli performance issue, so we don’t want to impact on CLI. We only want to support get_next_object for netconf request. I see there are “bulk hint” mentioned in confd_user_guide_6.7.4.pdf, but there are no further detail description. So I want to confirm whether confd can only trigger get_next_object for netconf somehow.
Much appreciated.

HI @mnovak, I also have another block issue. Take a simple example: list ont
and list ont has nested-list vlan.
Since nested-list vlan can’t be returned to confd in the get_next_object for list ont, confd will trigger get_next_object for nested-list vlan. So there are large numbers of get_next_object for nested-list vlan, which is not efficient and consumes lots of time, right? So how to improve the loop of nested-list? By the way, “container children nodes” can be returned in get_next_object for list onts, and I use confd_data_reply_next_object_tag_value_arrays() and external data provider.
Much appreciated.