MFD:ifTable:mib2c

From Net-SNMP Wiki
Revision as of 17:10, 13 July 2011 by Wes (Talk | contribs) (Running mib2c)

Jump to: navigation, search

Running mib2c

The first step is to generate the code. Create a new directory somewhere and run:

 $ mib2c -c mfd-top.m2c ifXTable
 writing to ifXTable.h
 | +-> Processing table ifXTable
 writing to -
 There are no defaults for ifXTable. Would you like to

   1) Accept hard-coded defaults [DEFAULT]
   2) Set defaults now

 Select your choice : 2

Notes:
Select '2', to change some of the defaults.

 This table has writable columns. Do you want to generate
 code for writeable columns, or restrict the table to read-only?

   1) generate code with writeable columns [DEFAULT]
   2) generate code with read-only columns

 Select your choice : [RETURN]

Notes:
We will be implementing set support.

 Writable tables sometimes have dependencies beteen columns
 or with other tables. If there are no dependencies in this table, you
 might want the extra code.
   1) do not generate dependency code [DEFAULT]
   2) generate dependency code
 Select your choice : [RETURN]

Notes:
While the ifXTable is related to the ifTable, the two tables do not have any dependencies.

Do you want to use an existing data structure for the USER context?

  1) No, use netsnmp_data_list * [DEFAULT]
  2) Yes, use my own structure

Select your choice : [RETURN]

Notes:
We don't need to track anything at the table level, so we'll just accept the default.

Do you want to use an existing data structure for the DATA context?

  1) No, use generated [DEFAULT]
  2) Yes, use my own structure

Select your choice : 2
Enter your DATA context : netsnmp_interface_entry

Notes:
We'll be using the net-snmp access routines to get interface data, so we'll just use the netsnmp_interface_entry structure to keep that data.

Do you want to allocate your 'netsnmp_interface_entry', or
embed it directly?

  1) directly embed structure [DEFAULT]
  2) dynamically allocate structure

Select your choice : 2

Notes:
The net-snmp access routines will provide us with allocated structures, so we'll just use those instead of copying them to an embeded structure.

Do you need to initialize elements in your 'netsnmp_interface_entry'
when a new instance is created?

  1) no, no initialization needed [DEFAULT]
  2) yes, initilization is needed

Select your choice : [RETURN]

Notes:
We'll be using the net-snmp data access routines to create the netsnmp_interface_entry structures, and those routines will take care of initialization for us.

Which method would you like to use to gather data about available rows?

  1) container-cached : [DEFAULT]  This access method uses a
     netsnmp_container to keep track of the indexes (and data, usually)
     for each row. Thi method is best for:
         - Internal data (maintained by the agent)
         - External data (maintained by another process) which can be
           cached (minumum cache time is 1 second)
      
  2) unsorted-external : This access method iterates over all of your data
     to find the row with the appropriate index. This method is best for
         - External data that cannot be cached.

Select your choice : [RETURN]

Notes:
We are going to keep a cache and refresh it periodically.

When accessing your data, is your data TRANSIENT?

  1) Yes. My data is TRANSIENT (e.g. a pointer to a static buffer that
     my be overwritten during a request) and needs to be copied during
     processing.

  2) Yes. My data is SEMI-TRANSIENT (e.g. an allocated pointer to a
     copy of the data).

  3) No, my data is PERSISTENT (e.g. an allocated pointer to the actual
     data, which is under the agent's control)

Select your choice [DEFAULT=1] : 2

Notes:
We get a copy of the interface data via the netsnmp data access functions.

Do you want example code to be generated?

  1) generate example code [DEFAULT]
  2) do not generate example code

Select your choice : 2

Notes:
We saw the example code in the last tutorial, so we'll skip it this time.

As before, when finished, you should have several files:

  • ifXTable.c
  • ifXTable_data_access.c
  • ifXTable_data_access.h
  • ifXTable_data_get.c
  • ifXTable_data_get.h
  • ifXTable_data_set.c
  • ifXTable_data_set.h
  • ifXTable_enums.h
  • ifXTable.h
  • ifXTable_interface.c
  • ifXTable_interface.h
  • ifXTable_Makefile
  • ifXTable_oids.h
  • ifXTable-README-FIRST.txt
  • ifXTable-README-ifXTable.txt
  • ifXTable_subagent.c

You should read ifXTable-README-FIRST.txt for a basic overview of MFD. The basic steps outlined in ifXTable-README-ifXTable.txt were used to write this tutorial.


Next: Data Structures Up: MFD IF-MIB Tutorials