Hello,

  Using net-snmp 5.2.1-12 ( redhat release 12 for fc3 ), I've found
that a create-dataset table ( created and updated through the dataset
methods ) returns the wrong index to a row if there is more than one
row in the table. This was checked by adding several rows to a table,
and then from the programmer's defined request handler, each row was
examined ( where each row was extracted from each request ). Each row
had the index of another row. The incorrect index was actually the
index of the row added before it.

  My example application runs as a subagent using the example subagent
code found on the net-snmp site. The table is defined with each row
having 3 columns: string index, U64 value, U64 value.  My example
application creates rows with corresponding indexes "1","2","3","4'
and reports the address of the row created for each index:
 
      AddRow():: created row with index "1" at 0x8b40088 
      AddRow():: created row with index "2" at 0x8b400c8
      AddRow():: created row with index "3" at 0x8b40188
      AddRow():: created row with index "4" at 0x8b40248

 The programmer defined handler extracts the row from each request and
reports the address of the row and the row's corresponding index:

        Examining row with index "1" at 0x8b400c8
        Examining row with index "2" at 0x8b40188
        Examining row with index "3" at 0x8b40248
        Examining row with index "4" at 0x8b40088

 You can see that the rows have shifted by one row when reported with
the indexes in ascending order ( and order of addition ).

  Can someone take a look at 'netsnmp_table_data_set' and help me fix
this problem? I have included the important parts of code from my test
subagent below.

Thanks,
Raul

Globals:
    Netsnmp_Node_Handler RmReportingTable_handler;
    static netsnmp_table_data_set *table_set;

Initialize Table:
     table_set = netsnmp_create_table_data_set("RmReportingTable");
     netsnmp_table_set_add_indexes(table_set, ASN_OCTET_STR, 0);
     netsnmp_table_set_multi_add_default_row(table_set, ... );
     netsnmp_register_table_data_set(
netsnmp_create_handler_registration( .. ), ... );

Add Rows to Table after Initialization:  ( Note: addRows defined
farther down in mail )
     addRow("1", 111, 111);
     addRow("2", 222, 222);
     addRow("3", 333, 333);
     addRow("4", 444, 444);

Define DataSet Handler to Examine Address of Each Row and Index Value:
      int
      RmReportingTable_handler( netsnmp_mib_handler *handler,
                                              
netsnmp_handler_registration *reginfo,
                                              
netsnmp_agent_request_info *reqinfo,
                                               netsnmp_request_info *requests)
      {
             netsnmp_table_request_info * ti;
             u_char * idxName;
             netsnmp_request_info *request;
             netsnmp_table_row * row; 

             for(request = requests; request; request=request->next)
             {
                   ti = netsnmp_extract_table_info( request );

                   if( ti )
                   {
                      if( ti->indexes )
                      {
                          if( &ti->indexes->val ) 
                          {
                              row = netsnmp_extract_table_row( request );
                              idxName = ti->indexes->val.string;

                              if( idxName ) 
                              {
                                     printf("Examining row with index
\"%s\" at 0x%x\n", idxName, row);
                              }
                           }
                         }
                       }
                 }
          }



void addRow(const char * index, const int value, const int timeStamp){
  
  U64 * cp1;
  U64 * cp2;
  netsnmp_table_row *row;

  cp1 = malloc (sizeof(U64)); 
  cp2 = malloc (sizeof(U64)); 
  zeroU64(cp1);
  zeroU64(cp2);
  incrByU32(cp1, value);
  incrByU32(cp2, timeStamp);

  /*
   * create the a row for the table, and add the data 
   */
  row = netsnmp_create_table_data_row();
  
  /*
   * set the index to "testIndex1" 
   */
  netsnmp_table_row_add_index(row, ASN_OCTET_STR, index, strlen(index));
  
  /*
   * set column 2 to 
   */
  netsnmp_set_row_column(row, 2, ASN_COUNTER64, (u_char *)cp1,
sizeof(U64));//REMOVE
  netsnmp_mark_row_column_writable(row, 2, 1);
  
  /*
   * set column 3 to 
   */
  netsnmp_set_row_column(row, 3, ASN_COUNTER64,  (u_char *)cp2,
sizeof(U64));//REMOVE
  netsnmp_mark_row_column_writable(row, 3, 1);

  /*
   * add the row to the table 
   */
  netsnmp_table_dataset_add_row(table_set,row);
  printf("AddRow():: created row with index \"%s\" at 0x%x\n", index, row);

}


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&op=click
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to