SNMP Subagent Programmer's Guide

Encoding MIBs
3-14 119728SNMP Subagent Programmer’s Guide
Writing and Compiling MIBs
scalar-object-syntax
is the SNMP data type for the entry object. It must match the value you encode in
the SYNTAX clause of the scalar-object-definition for the entry object.
scalar-object-definition
describes each object in an entry. Encode this definition as described earlier in this
section, under “Scalar Object Definitions.” Remember to specify a locator function
in the C_LOCATOR_FUNC clause for entry objects associated with the index if you
used the C_NEXT_FUNC construct in your index definition.
Examples
The Indexed Trap Generator sample subagent uses a MIB that defines two scalar objects,
a table, and a trap. The name of the MIB is tblTrap:
tblTrap ( peer-demos 9 )
tblTrapCards ( tblTrap 1 )
tblTrapPorts ( tblTrap 2 )
tblTrapTable ( tblTrap 3 )
tblTrapTableEntry ( tblTrapTable 1 )
cardNumber ( tblTrapEntry 1 )
portNumber ( tblTrapEntry 2 )
ratio ( tblTrapEntry 3 )
tableTrap ( 0 )
Values for the two scalar objects are maintained in fields within a structure named
“master.” The objects are both read-only objects having the SNMP data type Gauge:
tblTrapCards OBJECT-TYPE
SYNTAX Gauge
ACCESS read-only
C_STRUCT master, FIELD card_count
STATUS mandatory
DESCRIPTION
"The tblTrapCards variable reports the number of cards
in the tblTrapTable."
::= { tblTrap 1 }
tblTrapPorts OBJECT-TYPE
SYNTAX Gauge
ACCESS read-only
C_STRUCT master, FIELD port_count
STATUS mandatory
DESCRIPTION
"The tblTrapPorts variable reports the maximum number
of ports held by any card in the tblTrapTable."
::= { tblTrap 2 }
The table, tblTrapTable, is a collection of entries consisting of three scalar objects:
cardNumber, portNumber, and ratio. The index for each entry consists of the values for
two of these objects: cardNumber and portNumber. Indexed Trap Generator provides a
next and a locator function to help the run-time library find individual table entries; the
C_NEXT_FUNC clause in the index definition identifies the next function (next_entry),