If you are already familiar with how MIBs are written, you can probably skip most of this section. However, you should still read the descriptions of the extended keywords DEFAULT, EXCLUDE, and FORCE-INCLUDE, which are specific to this implementation of a MIB compiler.
This section describes the format of the description file used as input by mibcomp. This form is described more completely and generally in the SMI documents cited in A.3 Theory of Operation of this manual.
mibcomp does not provide a general-purpose ASN.1 parser. Instead, mibcomp implements a subset of the ASN.1 macro language, tailored to MIB specifications as they appear in the Internet community.
A MIB description begins with the MIB's module name, a list of all the objects and textual conventions that the MIB exports to other MIBs, and a list of any objects, textual conventions, or ASN.1 macros that the MIB imports from other MIB modules. The MIB's module name must be unique; this includes MIB modules that are actually mibcomp control files. If there is no list of exports, all objects and textual conventions in the MIB are implicitly exported.
EXAMPLE-MIB DEFINITIONS ::= BEGIN
All MIBs import at least a few ASN.1 macros, for example, the OBJECT-TYPE macro from one of the SMIs. Most MIBs import at least a few more object identifiers and textual conventions. For instance, mgmt is an object identifier that many MIBs import from the appropriate SMI (RFC1155-SMI for SNMPv1). DisplayString is a textual convention that many MIBs import (from the RFC1213-MIB module for SNMPv1 MIBs---note that this implies that an SNMPv1 MIB which uses DisplayString cannot be processed by mibcomp unless you first load RFC1213-MIB from rfc1213.mib).
Most MIBs then define any object identifiers they need. A MIB can define an object identifier anywhere in its body, but by convention they are usually defined at the beginning of the MIB. Many MIBs are broken into groups of variables; the groups are usually defined as object identifiers, and the actual variables then placed in the groups when they are later defined using OBJECT-TYPE.
-- WRS private enterprises MIB extensions wrs OBJECT IDENTIFIER ::= { enterprises 731 } -- examples MIB examples OBJECT IDENTIFIER ::= { wrs 7 }
Most MIBs then define any textual conventions that they use later. A textual convention is a way of defining a new type based on other types. Note that SNMP does not allow aggregate types; you may not define a new type to be an ASN.1 SEQUENCE. Textual conventions are mostly used to provide clarity in a MIB as to how a type is being used.
-- Make a textual convention
After defining textual conventions, MIBs usually define the objects that a network management station can access. These objects are defined using OBJECT-TYPE.
-- define a couple of objects exFirstObject OBJECT-TYPE SYNTAX ExampleType ACCESS read-write STATUS mandatory DESCRIPTION "First example object." REFERENCE "EXAMPLE MIB SPECIFICATION VERSION 0.0" DEFVAL { 1 } ::= { examples 1 }
An OBJECT-TYPE invocation ends with a line equating the object's name to an object identifier OBJECT IDENTIFIER. The object identifier comes after a "::=" and must be unique. Such object identifiers are constructed by combining the name of a group this object is under with this object's number within that group.
You can also specify traps in your MIB. In SNMPv1, traps are defined using the TRAP-TYPE macro. SNMPv1 traps are identified by simple integers.
mibcomp extends the normal MIB syntax with three new keywords: DEFAULT, FORCE-INCLUDE, and EXCLUDE.
All three of these keywords may be used at the beginning of a MIB description file, between the module name and the line:
The DEFAULT keyword can also be embedded in OBJECT-TYPE definitions as the final line before "::=". For instance:
These new keywords are not compatible with other software that processes MIB specifications. For greater compatibility, you can also use them inside comments. If the keyword immediately follows the comment characters, mibcomp recognizes it as the appropriate keyword. Otherwise, mibcomp ignores the word as a comment. For instance:
is a comment (note the space between the second dash and the word EXCLUDE).
We recommend that you organize your MIBs as sets of standard MIB files (extracted from RFCs and draft specifications, or written by you) that do not use the extended keywords at all, with control files which complement them and which specify the extended keywords. The control files can also be specific to projects and products, and allow you to maintain only one set of MIB specifications, varying the control files as you change the implementation of MIBs from product to product.
The FORCE-INCLUDE keyword directs mibcomp to produce #include statements in C-code output files. When you refer to structures or variables declared in header files provided by other software, you can force the files to be included using the FORCE-INCLUDE keyword.
The FORCE-INCLUDE keyword takes one argument: the name of the file to be included, exactly as it should appear in the resulting #include statement.2 For instance:
--FORCE-INCLUDE <asn1.h>
mibcomp remembers and uses all FORCE-INCLUDE statements from all input files, no matter which input file they appear in, and outputs a corresponding #include statement for each one at the top of any C-code output files. mibcomp provides no protection against duplicate #include files. The order of the #include files in the output corresponds to the order in which mibcomp encounters the FORCE-INCLUDE statements.
The DEFAULT keyword associates MIB implementation information with MIB objects. This information is needed by the -mib.c, -skel, and -skel.h output options. If you are using any of these options with mibcomp, you must supply DEFAULT keywords to provide the required information. If you are not using these options, you can ignore the DEFAULT keyword.
The DEFAULT keyword takes two arguments. The first tells mibcomp which function or value is being set. The second provides a string which identifies the function or value.
The general form of a DEFAULT statement is:
where label identifies one of the functions or values that the SNMP agent associates with each object. The string argument is either the name of a C function or a C expression, depending on whether label identifies a function or a value, respectively. As with the argument to the FORCE-INCLUDE keyword, the string argument to the DEFAULT keyword should be exactly as you want it to appear in the output file.3
The DEFAULT labels that specify method routines come in two parallel sets, one of which specifies a synchronous method routine, the other of which specifies asynchronous method routines. See 4.6 Method Routines for more details on these two kinds of method routines. You can use both synchronous and asynchronous method routines within a MIB, but all the method routines for a particular MIB object must be of the same kind. This is true whether the method routine for a particular MIB object is specified explicitly via a DEFAULT statement associated directly with the MIB object, or is inherited from a node higher in the MIB tree.
DEFAULT cookie (char *) 0 or DEFAULT cookie "_ipstats"
For details on the -mib.c, -skel, and -skel.h options to mibcomp, see B. mibcomp Output Formats.
It is not necessary to specify nine DEFAULT statements in every object definition in the MIB. If mibcomp finds no DEFAULT on a particular object, it checks that object's parent, and the parent's parent, and so forth, until it finally finds the DEFAULT it needs or hits the root object in the MIB. Thus, you can easily use the same set of DEFAULTs for all objects in a group or a particular MIB or table quite easily, just by setting the DEFAULT in an object they all share as a parent. You can also override these inherited DEFAULTs by setting DEFAULTs at a lower layer.
The DEFAULT statements at the top of the MIB are associated with the root object in the MIB and are therefore inherited by all MIB objects, unless overridden. Only one input file should specify DEFAULT statements for the root object.
The value supplied to a DEFAULT statement can include several special strings. Each of the special strings begins with a percent sign (%). When mibcomp comes across one of these special strings, it replaces it with a more meaningful string.