A general table differs from a simple table in at least one of the following ways:
The table is not indexed with a single integer.
For example, if the index is an IP address, the table is a general table.
The maximum index cannot be determined easily.
For example, the network interfaces table is a general table because it does not have a maximum index that you can determine.
At any given point, some indexes might be invalid.
For example, a table of currently running software might contain a row for a program that has just ended, but the table has yet to be updated. The table must be processed as a general table.
The table data is not directly accessible.
For example, the network interfaces table is maintained in the kernel and cannot be accessed directly.
The command that you use to generate code templates for general tables is the same command used for simple tables:
mib2c -c mib2c.iterate.conf mibnode1 mibnode2 ... |
The demo_module_3 code example shows how modify the templates appropriately to retrieve data from general tables.
The demo_module_3 code example is provided to help you understand how to modify the code generated by the mib2c command to perform a data retrieval in a general table. The table example provides information for monitoring a list of files. The demo_module_3 code example is located by default in the directory /usr/demo/sma_snmp/demo_module_3.
The README_demo_module_3 file contains instructions that describe how to perform the following tasks:
Generate code templates from a MIB that contains general table
Compile source files to generate a shared library object that implements a module
Set up the agent to dynamically load the module
Test the module with snmp commands to show that the module is functioning as expected
The demo_module_3 is set up to allow you to generate code templates me1ContactInfoTable.c and me1ContactInfoTable.h. You can then compare the generated files to the files demo_module_3.c and demo_module_3.h.
The me1ContactInfoTable.c and me1ContactInfoTable.h have been modified appropriately to retrieve data from general tables. You can use these files as a model for learning how to work with general tables in your own module. The instructions then explain how to compile the modified source files to create a functioning module.
The demo_module_3 code was generated by using mib2c with the -c mib2c.iterate.conf option. Some functions have been added to implement a link list to provide the test data.
The example uses some dummy data to perform data retrieval for a two-index table. The code is similar to the demo_module_2.c with one extra index. The following code sets up the table with two indexes:
netsnmp_table_helper_add_indexes(table_info, ASN_INTEGER, /* index: me1FloorNumber */ ASN_INTEGER, /* index: me1RoomNumber */ 0);
Use care in returning the “NEXT” data when function me1ContactInfoTable_get_next_data_point() is called. For instance, the data in this table is presorted so the next data is conveniently pointed by the pNext pointer in this example code:
me1ContactEntry* nextNode = (me1ContactEntry*) *my_loop_context; nextNode = nextNode->pNext;
If your implementation is more complicated, make sure the OIDs are increased incrementally, (xxx.1.1, xxx.1.2, ).
The input MIB file contains the specification of tables and scalars. When you run mib2c -c mib2c.iterate.conf on a general table node, template code is generated only for the general table in the MIB.