Management Information Base (MIB) Interface.
Management Information Base (MIB) Interface.
The database controlled by the SNMP Agent is referred to as the Management Information Base (MIB). It is a standard set of statistical and control values. SNMP allows the extension of these standard values with values specific to a particular agent through the use of private MIBs.
The definitions of MIB variables supported by a particular agent are incorporated in descriptor files, written in Abstract Syntax Notation (ASN.1) format, made available to network management client programs so that they can become aware of these MIB variables and their usage.
The MIB variables are referred to as MIB Object Identifiers (OIDs). OID names are hierarchy structured and unique. SNMP uses the OID to identify objects on each network element (device running SNMP agent) that can be managed using SNMP.
The SNMP Agent manages MIB variables that are located in the SNMP_Agent_MIB.c template file. To add the file to your project, simply right-click on the Source group, select Add New Item to Group, then click on User Code Template and scroll in the template files list until you find the SNMP Agent template. The SNMP_Agent_MIB.c file has implemented a scaled-down MIB-II Management Information Base. Only the System MIB is defined by default. The user might expand this table by adding his own MIB variables.
The user can register a callback function with a MIB variable. This function gets called, when the SNMP Manager accesses the MIB variable. This concept allows the SNMP Manager to control the SNMP Agent system. For example to change LED outputs, to write text on embedded LCD module, to read push buttons or analog inputs, etc.
The SNMP MIB entry information structure NET_SNMP_MIB_INFO describes the MIB variable. The SNMP Agent uses this description to process local MIB variables. This structure is defined as follows:
The components of NET_SNMP_MIB_INFO structure are:
MIB Type | Description | Size |
---|---|---|
NET_SNMP_MIB_INTEGER | Signed Integer | 1, 2 or 4 bytes |
NET_SNMP_MIB_OCTET_STR | Octet String entry | max. 110 characters |
NET_SNMP_MIB_BYTE_STR | Byte String entry | max. 110 bytes |
NET_SNMP_MIB_OBJECT_ID | Object Identifier entry | max. 17 bytes |
NET_SNMP_MIB_IP_ADDR | IP Address entry | 4 bytes |
NET_SNMP_MIB_COUNTER | Counter entry | 1, 2 or 4 bytes |
NET_SNMP_MIB_GAUGE | Gauge entry | 1, 2 or 4 bytes |
NET_SNMP_MIB_TIME_TICKS | Time Ticks entry | 4 bytes |
Mode | Type of Access |
---|---|
NET_SNMP_MIB_READ | Reads a MIB variable. |
NET_SNMP_MIB_WRITE | Writes to a MIB variable. |
The MIB Table table is defined as an array. The components of this array are of type NET_SNMP_MIB_INFO.
In the following example, we will construct a MIB variable entry LedOut. It will allow the SNMP Manager to control LEDs on an evaluation board.
The MIB variable type is Integer. An uint8_t variable is sufficient, because the LED port is 8-bit:
The OID reference is 1.3.6.1.3.1.0. It is defined in the Experimental MIB branch of the MIB tree:
The variable size and location is described with the help of NET_SNMP_MIB_INT macro:
The following macros are defined:
Macro | Variable Definition |
---|---|
NET_SNMP_MIB_STR | Octet or Byte String size and location. |
NET_SNMP_MIB_INT | Signed or Unsigned Integer size and location. |
NET_SNMP_MIB_IP | IP Address size and location. |
The write_leds is specified as callback function. It gets called when the LedOut is written:
Finally we need the actual variable definition:
For the LedOut control we actually need the following parts of code to be defined in SNMP_Agent_MIB.c module:
Two types of read/write strings are supported:
Type | Description |
---|---|
OCTET_STRING | An 0-terminating ascii string. |
BYTE_STRING | Length-encoded binary string. |
The OCTET_STRING is treated as an 0-terminating ascii string, the last character in the string is a zero character. When the ascii string is written in the SET request, a 0-termination is added. The position of the zero character specifies the length of the data encoded in the GET response.
The BYTE_STRING is treated as a length-encoded binary string. The first byte in the string is the length of the string. The contents of the string are stored from the second byte onwards. When the byte string is written in the SET request, the len is updated. The len specifies the length of the data encoded in the GET response.
The value of OID address byte must be less than 128. If it is not, an OID address must be encoded in extended format. This is because the high bit of an address byte is an address extension bit.
For example, the OID address 1.3.6.1.4.1.311.0 is encoded as:
The address value for the highlighted numbers is calculated as:
The OID address 1.3.6.1.4.1.31036.50.1.1.0 is encoded as:
where the value 31036 is calculated as: