-----Original Message-----
From: Dave Shield [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 28, 2005 1:35 AM
To: Toth, Gregory S
Cc: [email protected]
Subject: Re: How to implement tables in 5.0.6


On Wed, 2005-04-27 at 22:38, Toth, Gregory S wrote:
> We are in the transition process from 4.2.x to 5.0.6
> Doing scalars in 5.0.6 is fairly straightforward but the table 
> implementation is very different.

Probably because there are now several different possible alternatives,
depending on the characteristics of your table.


> The output file from mib2c has two methods that appear to be roughly 
> the
> same:
>    netsnmp_variable_list * xxxxxx_get_first_data_point(....) 
> And
>    netsnmp_variable_list * xxxxxx_get_next_data_point(....) 

OK - so you're working with the iterator helper.

The main thing to realise is that any table implementation faces two
basic tasks - identifying which row of the table is needed for a given
request, and then returning the appropriate column value from that
particular row.

With the v4 agent, the 'var_xxx' routine typically handled both tasks.
Unless you used the 'header_simple_table' routine, which took care of
(most of) the first task - identifying the row.

With the v5 agent, the most basic "register_table_handler" approach
still leaves both tasks to the user-provided handler routine (just
weeding out some of the more obviously invalid requests).

All of the other helpers (data, dataset, container, iterator,
array_user, MfD, etc) take care of much of this first task - and
typically provide the user helper with the relevant row, leaving it to
return the appropriate column value.
  (The dataset helper takes care of this second task too, and the
array_user and MfD helpers don't use the same handler-based structure of
the rest of the agent toolkit).  But that's the basic idea.


> My guess is that xxxxxx_get_first_data_point should return the 
> objectID (in the netsnmp_variable_list) of the first element table 
> element (1 (column),1 (row)) for a 2 dimensional table and that given 
> a object id in the "netsnmp_variable_list * put_index_data",
> xxxxxx_get_next_data_point(....) should return the object id of the 
> next element (for example passing in the oid (1 (column),1 (row)) 
> should possibly return the oid (1 (column),2 (row)).

Good guess, but not quite right.

These two routines are just concerned with determining the appropriate
*row* to use.  They're not interested in columns at all.
The 'get_first' routine should return some sort of pointer to the first
row of the table (and will only be called once). The 'get_next' routine
should take this pointer, and return the equivalent pointer for the next
row.  This will be called repeatedly until the agent
has walked through the full table.   At which point, the internal
iterator helper will decide which was the correct row, and call the
handler routine.  See my response to Emmanuel for a slightly fuller
description of this.


>The other thing to realise is that these get_{first,next} routines
actually return *three* pointers.  One (the >>>variable_list parameter)
is an indication of the index values for each row (so that the iterator
helper can decide which >row is required).  Another (the loop_context
parameter) is a pointer to allow the get_next routine to move on to the
next >row of the table.  The third (the data_context
>parameter) is a separate pointer that will be passed to the main
handler, to retrieve the column values for that row.

>It's often the case that the loop_context and data_context pointers
will be identical, but that's not necessarily always >>the case. It's up
to you how you pass information between the get_* hooks
>(loop_context) and between these hook routines and the main handler
(data_context).


>> If this is true, how do I set this in the
>> snmp_set_var_value(vptr, (u_char *) /* XXX: oidNumber data */ ,/*
XXX:
>>                        length of oidNumber data */ );
>> Call?

>This is used to set the index of the appropriate row in the array.

>> For example if the object id of the (1,1) element in my array is 
>> "1.2.3.4.5.6.7.1", do I just do this:
>> 
>> oid  my_oid[] ={ 1,2,3,4,5,6,7,1};
>> vptr = put_index_data;
>> snmp_set_var_value(vptr,(u_char *)my_oid,8);

>No.
>Try:
>     long  this_index = 1;    // (1,x) elements
>     vptr = put_index_data;
>     snmp_set_var_value( vptr,  (u_char*)&this_index,
                                   sizeof(this_index));
>     return put_index_data;

This caused the agent to coredump on the snmp_set_var_value call.


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r 
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to