[Erlang Systems]

4 The MIB Compiler

This section describes the MIB compiler and contains the following topics:

4.1 Operation

The MIB must be written as a text file in ASN.1 before being compiled. This text file must have the same name as the MIB, but with the suffix .mib. This is necessary for handling the IMPORT statement.

The association file which contains the names of instrumentation functions for the MIB should have the suffix .funcs. If the compiler does not find the association file, it gives a warning message and uses default instrumentation functions. (See see Default Instrumentation for more details).

The MIB compiler is started with a call to snmp:c(<mibname>). For example:

snmp:c("RFC1213-MIB").
    

The output is a new file which is called <mibname>.bin.

The MIB compiler understands both SNMPv1 and SNMPv2 MIBs. It uses the MODULE-IDENTITY statement to determinte if the MIB is version 1 or 2.

4.2 Importing MIBs

The compiler handles the IMPORT statement. It is the compiled file which is imported, not the ASN.1 file. Therefore, an MIB must be recompiled to make changes visible to other MIBs which import it.

The compiled files of the imported MIBs must be present in the current directory, or a directory in the current path. The path is supplied with the {i, Path} option, for example:

snmp:c("MY-MIB", 
       [{i, ["friend_mibs/", "../standard_mibs/"]}]).
    

It is also possible to import MIBs from OTP applications in an "include_lib" like fashion with the il option. Example:

snmp:c("MY-MIB", 
       [{il, ["snmp/priv/mibs/", "myapp/priv/mibs/"]}]).
    

finds the lastest version of the snmp and myapp applications in the OTP system and uses the expanded paths as include paths.

Note that a SNMPv2 MIB can import an SNMPv1 MIB and vice versa.

4.3 MIB Consistency Checking

When an MIB is compiled, the compiler detects if several managed objects use the same OBJECT IDENTIFIER. If this is the case, it issues an error message. However, the compiler cannot detect Oid conflicts between different MIBs. These kind of conflicts generate an error at load time. To avoid this, the following function can be used to do consistency checking between MIBs:

erl>snmp:is_consistent(ListOfMibNames).
    

ListOfMibNames is a list of compiled MIBs, for example ["RFC1213-MIB", "MY-MIB"]. This function also performs consistency checking on trap definitions.

4.4 .hrl File Generation

It is possible to generate an .hrl file which contains definitions of Erlang constants from a compiled MIB file. This file can then be included in Erlang source code. The file will contain constants for:

Use the following command to generate a .hrl file from an MIB:

erl>snmp:mib_to_hrl(MibName).
    

4.5 Emacs Integration

With the Emacs editor, the next-error (C-X `) function can be used indicate where a compilation error occurred, provided the error message is described by a line number.

Use M-x compile to compile an MIB from inside Emacs, and enter:

 erl -s snmp c <MibName> -noshell
    

An example of <MibName> is RFC1213-MIB.

4.6 Compiling from a shell or a Makefile

The erlc commands can be used to compile SNMP MIBs. Example:

 erlc MY-MIB.mib
    

4.7 Deviations from the standard

In some aspects the Erlang MIB compiler doesn't follow or implement SNMP fully. Here are the differences:


Copyright © 1991-97 Ericsson Telecom AB