Difference between revisions of "MFD:ifXTable:Data Structures"

From Net-SNMP Wiki
Jump to: navigation, search
(MFD: ifXTable Data Structures)
Line 59: Line 59:
 
     */
 
     */
 
     typedef struct ifXTable_rowreq_ctx_s {
 
     typedef struct ifXTable_rowreq_ctx_s {
 
+
 
     /** this must be first for container compare to work */
 
     /** this must be first for container compare to work */
 
         netsnmp_index  oid_idx;
 
         netsnmp_index  oid_idx;
 
         oid            oid_tmp[MAX_OID_LEN];  /* xxx-rks: shrink this */
 
         oid            oid_tmp[MAX_OID_LEN];  /* xxx-rks: shrink this */
 
+
 
         ifXTable_mib_index tbl_idx;
 
         ifXTable_mib_index tbl_idx;
 
+
 
         ifXTable_data  *data;
 
         ifXTable_data  *data;
 
         ifXTable_undo_data *undo;
 
         ifXTable_undo_data *undo;
 
+
 
     /** implementor's context pointer provided during registration */
 
     /** implementor's context pointer provided during registration */
 
         ifXTable_registration_ptr ifXTable_reg;
 
         ifXTable_registration_ptr ifXTable_reg;
 
+
 
         /*
 
         /*
 
         * TODO:
 
         * TODO:
Line 79: Line 79:
 
         /** ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */
 
         /** ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */
 
         u_long          ifLinkUpDownTrapEnable;
 
         u_long          ifLinkUpDownTrapEnable;
 
+
 
         /** ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */
 
         /** ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */
 
         char            ifAlias[64];
 
         char            ifAlias[64];
Line 88: Line 88:
 
         */
 
         */
 
         netsnmp_data_list *ifXTable_data_list;
 
         netsnmp_data_list *ifXTable_data_list;
 
+
 
     } ifXTable_rowreq_ctx;
 
     } ifXTable_rowreq_ctx;
 
</td>
 
</td>
 
         </tr>
 
         </tr>
 
     </table>
 
     </table>

Revision as of 21:53, 13 July 2011

MFD: ifXTable Data Structures

Let's take a look in ifXTable.h. Since we will be using the netsnmp access routines to get the interface data, we specified netsnmp_interface_entry as our data context. You might expect to run into it a lot in the code. Instead, the code uses a typedef:

   /*
    * data context
    */
   typedef netsnmp_interface_entry ifXTable_data;

Whenever you see ifXTable_data, remember that it is simply a typedef for netsnmp_interface_entry. As we will see in a moment, the the row request context has a pointer to an ifXTable_data structure. The first edit we need to make is to include the interface access header file:

#include <net-snmp/library/asn1.h>
#include <net-snmp/data_access/interface.h>

However, the netsnmp_interface_entry does not contain all the information we need to implement all the ifXTable columns. In particluar, the ifLinkUpDownTrapEnable and ifAlias columns are specific to the ifXTable, and not kept in the netsnmp_interface_entry structure. To keep track of them, we'll add them to the rowrequest_context. Because we specified a type for our data context, mib2c did not generate storage for any columns. So we need to add storage. For consistency's sake, we'll use mib2c to generate a data context. We specify dummy as the output file name, so that it won't get confused with the other ifXTable implementation files.

$ mib2c -f dummy -c mib2c.column_storage.conf ifXTable


Then we copy the definitions we need from dummy_storage.h to the rowrequest_context in ifXTable.h:

   /*
    *********************************************************************
    * Row request context
    * When your functions are called, you will be passed a
    * ifXTable_rowreq_ctx pointer.
    */
   typedef struct ifXTable_rowreq_ctx_s {

   /** this must be first for container compare to work */
       netsnmp_index   oid_idx;
       oid             oid_tmp[MAX_OID_LEN];   /* xxx-rks: shrink this */

       ifXTable_mib_index tbl_idx;

       ifXTable_data  *data;
       ifXTable_undo_data *undo;

   /** implementor's context pointer provided during registration */
       ifXTable_registration_ptr ifXTable_reg;

       /*
        * TODO:
        * add any other useful data
        *       (e.g. flags for when a column has been set)
        */
       /** ifLinkUpDownTrapEnable(14)/INTEGER/ASN_INTEGER/long(u_long)//l/A/W/E/r/d/h */
       u_long          ifLinkUpDownTrapEnable;

       /** ifAlias(18)/DisplayString/ASN_OCTET_STR/char(char)//L/A/W/e/R/d/H */
       char            ifAlias[64];
       size_t          ifAlias_len;        /* # of char elements, not bytes */

       /*
        * storage for future expansion
        */
       netsnmp_data_list *ifXTable_data_list;

   } ifXTable_rowreq_ctx;