Network Component
Version 6.3
MDK-Professional Middleware for IP Networking
|
Simple Network Management Protocol (SNMP) is mainly used in network management systems to monitor network-attached devices for conditions that warrant administrative attention. It is the most popular network management protocol in the TCP/IP protocol suite.
SNMP is a simple request/response protocol that communicates management information between two types of SNMP software entities: SNMP managers and SNMP agents. The following picture shows an exemplary setup:
In summary, SNMP performs the following operations:
The SNMP Agent validates each request from a SNMP manager before responding to the request, by verifying that the manager belongs to a SNMP community with access privileges to the agent. A SNMP community is a logical relationship between a SNMP agent and one or more SNMP managers. The community has a name, and all members of a community have the same access privileges: either read-only or read-write.
The SNMP Agent in the Network Component is an optimized and compact implementation for embedded systems. Check: Currently it implements SNMP version 1.
The following functions are included in the Network Component library rl_net.h:
The data base controlled by the SNMP Agent is referred to as the SNMP 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 Net Item to Group, then click on User Code Template and scroll in the template files list until you find the SNMP Agent template (you will find a listing here). 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 snmp_mib describes the MIB variable. The SNMP Agent uses this description to process local MIB variables. This structure is defined as follows:
The components of MIB_ENTRY structure are:
MIB Type | Description | Size |
---|---|---|
MIB_INTEGER | Signed Integer | 1, 2 or 4 bytes |
MIB_OCTET_STR | Octet String entry | max. 110 characters |
MIB_OBJECT_ID | Object Identifier entry | max. 17 bytes |
MIB_IP_ADDR | IP Address entry | 4 bytes |
MIB_COUNTER | Counter entry | 1, 2 or 4 bytes |
MIB_GAUGE | Gauge entry | 1, 2 or 4 bytes |
MIB_TIME_TICKS | Time Ticks entry | 4 bytes |
Mode | Type of Access |
---|---|
MIB_READ | Reads a MIB variable. |
MIB_WRITE | Writes to a MIB variable. |
The snmp_table table is defined as an array. The components of this array are of type snmp_mib.
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 MIB_INT macro:
The following macros are defined:
Macro | Variable Definition |
---|---|
MIB_STR | Octet String size and location. |
MIB_INT | Signed or Unsigned Integer size and location. |
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_MIB.c module:
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:
The SNMP agent configuration file Net_Config_SNMP_Agent.h contains the following settings: