For each SNMP table defined in the MIB, the mibgen compiler generates:
A class containing the view of the table
A metadata file corresponding to the SNMP table itself
A skeletal MBean representing a table entry, with its interface
A metadata file corresponding to the skeletal MBean
The metadata class containing the SNMP view of a table contains all the management of the table index. The class is also prefixed with Table, followed by the name of the table.
The class containing the MBean view of a table enables you to dynamically add or remove entries from the table. It contains callbacks and factory methods that enable you to instantiate or delete entries upon receiving requests from a remote SNMP manager (see RowStatus example). This class also is prefixed with Table, followed by the name of the table.
For each table in a MIB, the mibgen compiler generates an MBean representing a table entry. These skeletal MBeans must be completed by adding implementation specific code (access methods). The generated code is initialized with default values for table–entry fields. Therefore, if you compile the generated code directly, you obtain a running agent. In this case, values returned by the agent when querying the MIBs are not meaningful. The mibgen compiler uses the entry names specified in the MIB definition to name MBeans generated from table entries.
Remote creation of table entries is disabled by default, for security reasons. You can dynamically enable and disable remote creation of table entries by calling the setCreationEnabled operation on the generated MBean-like object.
The RowStatus convention, defined in RFC 2579, is fully supported by the code generator. When a table is defined using v2, and if it contains a control variable with row status syntax, the mibgen compiler generates a set of methods allowing this table to be remotely controlled by this variable. However, the remote creation and deletion of rows remains disabled by default.
Table objects are divided into two categories:
A metadata class
An MBean-like object
When remote table-entry creation is enabled, and the creation of a new table is requested, a factory method is called on the MBean-like object to instantiate the new table entry. By default, an instance of the skeleton class for that table entry is instantiated.
Subclass the MBean-like object to redefine the factory method for remote entry creation.
Redefine this factory method so that it returns an instance of your implementation class, instead of the default skeleton.
Subclass the group MBean, to which this table belongs, to instantiate your new MBean-like object, instead of the generated default object.
This is demonstrated in the RowStatus example.
In addition to generating skeletal MBeans to represent each table entry, the mibgen compiler generates a Java file containing the SNMP view of the MBean. Metadata files do not need to be modified. For metadata files, the Meta suffix is added.
The mibgen compiler generates a specific class for each enumerated type defined in the MIB. This class contains all the possible values defined in the enumerated type. The generated class extends the generic class Enumerated, defined in the com.sun.jdmk package. The HTML adaptor can use the Enumerated class to display all the labels contained in an enumeration. The mibgen compiler can handle enumerated types defined as part of a type definition or in-line definition.
Generated code representing SNMP enumerated types is prefixed with Enum followed by the type name or the variable name for inline definition.
The mibgen compiler has an option -p prefix that you can use to prefix the names of all generated files with a specific string.
For example, in MIB II, TCP connection states are represented by an enumeration containing all the possible states for a TCP connection. The mibgen compiler generates a Java class named EnumTcpConnState to represent the enumeration.