Re: Regarding Table data Create and Fill

"kumar undurthi" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Hi Dave,
     As u said to generate the code with  " mib2c -S cache=1 -c
mib2c.table_data.conf ocStbHostAVInterfaceTable "
I generated , u can check the code below.
     1) while compiling it i faced few errors ,which i modified :: now i
able to compile .
     2) But now while runing.. i able to get the values if i fill the table
in "initialize_table_ocStbHostAVInterfaceTable"( which is similar to as
normal table_data.conf model (with out catch) )
3) But if I keep same code in the "ocStbHostAVInterfaceTable_load() " module
( to fill the table ) it is not getting the values and more over I kept some
prints in the "ocStbHostAVInterfaceTable_load() module" ,  What i noticed is
that module itself  not called by the rest of the code .

So "ocStbHostAVInterfaceTable_load()" is not called rest of the modules, may
be because of that i am unable to get values. " Please can u tell when the
Table_load is called ".

** more over if u have any examples please sent it or if any site have
examples please fwd to me***

/*
 * Note: this file originally auto-generated by mib2c using
 *  : mib2c.table_data.conf 15999 2007-03-25 22:32:02Z dts12 $
 */

#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "ocStbHostAVInterfaceTable.h"

#include "vl_ocStbHost_GetData.h"
#include "vlochd_OC_STB_HOST_MIB_Data.h"

#define CHRMAX2 256
#define MAX_IOD_LENGTH2 128
/** Initializes the ocStbHostAVInterfaceTable module */
void
init_ocStbHostAVInterfaceTable(void)
{
    /*
     * here we initialize all the tables we're planning on supporting
     */
     printf("init_ocStbHostAVInterfaceTable \n.");
    initialize_table_ocStbHostAVInterfaceTable();
}

//# Determine the first/last column names

/** Initialize the ocStbHostAVInterfaceTable table by defining its contents
and how it's structured */
  netsnmp_tdata  *table_data;
void
initialize_table_ocStbHostAVInterfaceTable(void)
{


    static oid      ocStbHostAVInterfaceTable_oid[] =
        { 1, 3, 6, 1, 4, 1, 4491, 2, 3, 1, 1, 1, 2, 2 };
    size_t          ocStbHostAVInterfaceTable_oid_len =
        OID_LENGTH(ocStbHostAVInterfaceTable_oid);
    netsnmp_handler_registration *reg;
//     netsnmp_tdata  *table_data;
    netsnmp_table_registration_info *table_info;
    netsnmp_cache  *cache;
    printf("initialize_table_ocStbHostAVInterfaceTable table_data
...1......\n");
    reg =
        netsnmp_create_handler_registration("ocStbHostAVInterfaceTable",

ocStbHostAVInterfaceTable_handler,
                                            ocStbHostAVInterfaceTable_oid,

ocStbHostAVInterfaceTable_oid_len,
                                            HANDLER_CAN_RONLY);

   printf("initialize_table_ocStbHostAVInterfaceTable table_data
...2.....\n");
    table_data =
        netsnmp_tdata_create_table("ocStbHostAVInterfaceTable", 0);
    table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
    netsnmp_table_helper_add_indexes(table_info, ASN_UNSIGNED,  /* index:
ocStbHostAVInterfaceIndex */
                                     0);

    table_info->min_column = COLUMN_OCSTBHOSTAVINTERFACETYPE;
    table_info->max_column = COLUMN_OCSTBHOSTAVINTERFACESTATUS;


    printf("initialize_table_ocStbHostAVInterfaceTable Catch ...3......\n");
    netsnmp_tdata_register(reg, table_data, table_info);
    printf("Before Catch .....2....");
    cache = netsnmp_cache_create(OCSTBHOSTAVINTERFACETABLE_TIMEOUT,
                                 ocStbHostAVInterfaceTable_load,
                                 ocStbHostAVInterfaceTable_free,
                                 ocStbHostAVInterfaceTable_oid,
                                 ocStbHostAVInterfaceTable_oid_len);
   printf("Before Catch ....4.....\n");
        cache->magic = (void *) table_data;
    netsnmp_inject_handler_before(reg, netsnmp_cache_handler_get(cache),
                                  TABLE_DATA_NAME);


        /*
         * Initialise the contents of the table here
         */

 #if  0
//Check 1:: (Normal with out cathc) method i will fill here
****************** if i uncommet this code i am able to get the values which
are filled bye the this vl_ocStbHostAVInterfaceTable_getdata(table_data))
**********************

    if(0 == vl_ocStbHostAVInterfaceTable_getdata(table_data))
    {
            //vl_ocStbHostAVInterfaceTable_getdata"
      printf(" ERROR:: Not yet table initialise here \n");
    }
 #endif//if 0
}

    /*
     * Typical data structure for a row entry
     */
struct ocStbHostAVInterfaceTable_entry {
    /*
     * Index values
     */
    u_long          ocStbHostAVInterfaceIndex;

    /*
     * Column values
     */
    oid             ocStbHostAVInterfaceType[MAX_IOD_LENGTH2];
    size_t          ocStbHostAVInterfaceType_len;
    char            ocStbHostAVInterfaceDesc[CHRMAX2];
    size_t          ocStbHostAVInterfaceDesc_len;
    long            ocStbHostAVInterfaceStatus;

    int             valid;
};

/*
 * create a new row in the table
 */
netsnmp_tdata_row *ocStbHostAVInterfaceTable_createEntry(netsnmp_tdata *
                                                         table_data,
                                                         u_long

ocStbHostAVInterfaceIndex)
{
    struct ocStbHostAVInterfaceTable_entry *entry;
    netsnmp_tdata_row *row;

    entry = SNMP_MALLOC_TYPEDEF(struct ocStbHostAVInterfaceTable_entry);
    if (!entry)
        return NULL;

    row = netsnmp_tdata_create_row();
    if (!row) {
        SNMP_FREE(entry);
        return NULL;
    }
    row->data = entry;
    entry->ocStbHostAVInterfaceIndex = ocStbHostAVInterfaceIndex;
    netsnmp_tdata_row_add_index(row, ASN_UNSIGNED,
                                &(entry->ocStbHostAVInterfaceIndex),
                                sizeof(entry->ocStbHostAVInterfaceIndex));
    netsnmp_tdata_add_row(table_data, row);
    return row;
}

/*
 * remove a row from the table
 */
void
ocStbHostAVInterfaceTable_removeEntry(netsnmp_tdata * table_data,
                                          netsnmp_tdata_row * row) {
    struct ocStbHostAVInterfaceTable_entry *entry;

    if (!row)
        return;                 /* Nothing to remove */
    entry = (struct ocStbHostAVInterfaceTable_entry *)
        netsnmp_tdata_remove_and_delete_row(table_data, row);
    if (entry)
        SNMP_FREE(entry);       /* XXX - release any other internal
resources */
}

/*
 * Example cache handling - set up table_data list from a suitable file
 */
int
ocStbHostAVInterfaceTable_load(netsnmp_cache * cache, void *vmagic) {
    netsnmp_tdata *table = (netsnmp_tdata *) vmagic;
    netsnmp_tdata_row *row;
    //struct ocStbHostAVInterfaceTable_entry *this
     //cache->magic
    /**
     *vl_ocStbHostAVInterfaceTable_getdata module will  Initialise the
contents of the table here
     */
       printf(".................table initialise here ............\n");
      if(0 == vl_ocStbHostAVInterfaceTable_getdata(table))
    {
            //vl_ocStbHostAVInterfaceTable_getdata"
      printf(" ERROR:: Not yet table initialise here \n");
    }
#if 0


    FILE *          fp;
    char            buf[STRMAX];
                   ;

                    fp = fopen("/data/for/ocStbHostAVInterfaceTable", "r");
    while           (fgets(buf, STRMAX, fp)) {
        /*
         * Unpick 'buf' to extract the index values...
         */

        this =
            ocStbHostAVInterfaceTable_createEntry(table,

ocStbHostAVInterfaceIndex);
        /*
         * ... and then populate 'this' with the column values
         */
    } fclose        (fp);
#endif
}

void
ocStbHostAVInterfaceTable_free(netsnmp_cache * cache, void *vmagic) {
    netsnmp_tdata * table = (netsnmp_tdata *) vmagic;
    netsnmp_tdata_row *this;

    netsnmp_tdata_delete_table(table);

//     while           ((this = netsnmp_tdata_get_first_row(table))) {
//         netsnmp_tdata_remove_and_delete_row(table, this);
//               }

}

/** handles requests for the ocStbHostAVInterfaceTable table */
int
ocStbHostAVInterfaceTable_handler(netsnmp_mib_handler *handler,
                                      netsnmp_handler_registration
                                      *reginfo,
                                      netsnmp_agent_request_info *reqinfo,
                                      netsnmp_request_info *requests) {

    netsnmp_request_info *request;
    netsnmp_table_request_info *table_info;
    netsnmp_tdata * table_data;
    netsnmp_tdata_row *table_row;
    struct ocStbHostAVInterfaceTable_entry *table_entry;
    int             ret;



    switch (reqinfo->mode) {
        /*
         * Read-support (also covers GetNext requests)
         */
    case MODE_GET:
        for (request = requests; request; request = request->next) {
            table_entry = (struct ocStbHostAVInterfaceTable_entry *)
                netsnmp_tdata_extract_entry(request);
            table_info = netsnmp_extract_table_info(request);
            printf("....ocStbHostAVInterfaceTable_handler:: ..MODE_GET:
............\n");
            switch (table_info->colnum) {
            case COLUMN_OCSTBHOSTAVINTERFACETYPE:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_OBJECT_ID,
                                         (u_char *) table_entry->
                                         ocStbHostAVInterfaceType,
                                         table_entry->
                                         ocStbHostAVInterfaceType_len);
                 printf("....COLUMN_OCSTBHOSTAVINTERFACETYPE:: ..MODE_GET:
............\n");
                break;
            case COLUMN_OCSTBHOSTAVINTERFACEDESC:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_value(request->requestvb, ASN_OCTET_STR,
                                         (u_char *) table_entry->
                                         ocStbHostAVInterfaceDesc,
                                         table_entry->
                                         ocStbHostAVInterfaceDesc_len);
        printf("....COLUMN_OCSTBHOSTAVINTERFACEDESC:: ..MODE_GET:
............\n");
                break;
            case COLUMN_OCSTBHOSTAVINTERFACESTATUS:
                if (!table_entry) {
                    netsnmp_set_request_error(reqinfo, request,
                                              SNMP_NOSUCHINSTANCE);
                    continue;
                }
                snmp_set_var_typed_integer(request->requestvb, ASN_INTEGER,
                                           table_entry->
                                           ocStbHostAVInterfaceStatus);
                break;
            default:
                netsnmp_set_request_error(reqinfo, request,
                                          SNMP_NOSUCHOBJECT);
                break;
            }
        }
        break;

    }
    return SNMP_ERR_NOERROR;
}

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.