SNMP DPI Protocol
This section describes the actual protocol used between the SNMP agent and sub-agents. This information has not previously been published.
Connection Establishment
In a TCP/IP environment, the SNMP agent listens on an arbitrary TCP port for a connection request from a sub-agent. It is important to realize that a well-known port is not used: every invocation of the SNMP agent will potentially result in a different TCP port being used.
A sub-agent needs to determine this port number to establish a connection. The sub-agent learns the port number from the agent by sending it one conventional SNMP get-request PDU. The port number is maintained by the SNMP agent as the object whose identifier is 1.3.6.1.4.1.2.2.1.1.0; this variable is registered under the IBM enterprise-specific tree. The SNMP agent replies with a conventional SNMP response PDU that contains the port number to be used. This response is examined by the sub-agent and the port number is extracted. The sub-agent then establishes the connection to the specified port.
On the surface, this procedure appears to mean that the sub-agent must be able to create and parse SNMP packets, but this is not the case. The DPI Application Program Interface (API) has a library routine, query_DPI_port(), which can be used to generate and parse the required SNMP packets. This routine is very small (under 100 lines of C), so it does not greatly increase the size of any sub-agent).
For completeness, byte-by-byte descriptions of the packets generated by the SNMP DPI API routine query_DPI_port() are provided below. This is probably of little interest to most readers and reading the source to query_DPI_port() provides much of the same information.
SNMP PDU to Get the Agent's DPI Port
As noted, before a TCP connection to the SNMP agent can be made, the sub-agent must learn which TCP port that the agent is listening on. To do so, it can issue an SNMP GET for an IBM enterprise-specific variable 1.3.6.1.4.1.2.2.1.1.0.
NOTE: the object instance of ".0" is included for clarity in this document.
The SNMP PDU can be constructed as shown below. This PDU must be sent to UDP port 161 on the host where the agent runs (probably the same host where the sub-agent runs).
+----------------------------------------------------------------------+
| Table 1. SNMP PDU for GET DPI_port. This is the layout of an SNMP |
| PDU for GET DPI_port |
+-----------------+-----------------+----------------------------------+
| OFFSET | VALUE | FIELD |
+-----------------+-----------------+----------------------------------+
| 0 | 0x30 | ASN.1 header |
+-----------------+-----------------+----------------------------------+
| 1 | 34 + len | pdu_length, see formula below |
+-----------------+-----------------+----------------------------------+
| 2 | 0x02 0x01 0x00 | version (integer, length=1, |
| | 0x04 | value=0), community name |
| | | (string) |
+-----------------+-----------------+----------------------------------+
| 6 | len | length of community name |
+-----------------+-----------------+----------------------------------+
| 7 | community name | |
+-----------------+-----------------+----------------------------------+
| 7 + len | 0xa0 0x1b | SNMP GET request: |
| | | request_type=0xa0, length=0x1b |
+-----------------+-----------------+----------------------------------+
| 7 + len + 2 | 0x02 0x01 0x01 | SNMP request ID: integer, |
| | | length=1, ID=1 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 5 | 0x02 0x01 0x00 | SNMP error status: integer, |
| | | length=1, error=0 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 8 | 0x02 0x01 0x00 | SNMP index: integer, length=1, |
| | | index=0 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 11 | 0x30 0x10 | Varbind list, length=0x10 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 13 | 0x30 0x0e | Varbind, length=0x0e |
+-----------------+-----------------+----------------------------------+
| 7 + len + 15 | 0x06 0x0a | Object ID, length=0x0a |
+-----------------+-----------------+----------------------------------+
| 7 + len + 17 | 0x2b 0x06 0x01 | Object instance: |
| | 0x04 0x01 0x02 | 1.3.6.1.4.1.2.2.1.1.0 |
| | 0x02 0x01 0x01 | |
| | 0x00 | |
+-----------------+-----------------+----------------------------------+
| 7 + len + 27 | 0x05 0x00 | null value, length=0 |
+-----------------+-----------------+----------------------------------+
+----------------------------------------------------------------------+
The formula to calculate the length field "pdu_length" is as follows:
pdu_length = length of version field and string tag (4 bytes)
+ length of community length field (1 byte)
+ length of community name (depends...)
+ length of SNMP GET request (29 bytes)
= 34 + length of community name
SNMP PDU Containing the Response to the GET
Assuming that no errors occured, then the port is returned in the last 2 octets of the received packet. The format of the packet is shown below:
+----------------------------------------------------------------------+
| Table 2. SNMP RESPONSE PDU for GET of Agent's DPI port. This is the |
| layout of an SNMP RESPONSE PDU for GET DPI_port |
+-----------------+-----------------+----------------------------------+
| OFFSET | VALUE | FIELD |
+-----------------+-----------------+----------------------------------+
| 0 | 0x30 | ASN.1 header |
+-----------------+-----------------+----------------------------------+
| 1 | 36 + len | length, see formula below |
+-----------------+-----------------+----------------------------------+
| 2 | 0x02 0x01 0x00 | version (integer, length=1, |
| | 0x04 | value=0), community name |
| | | (string) |
+-----------------+-----------------+----------------------------------+
| 6 | len | length of community name |
+-----------------+-----------------+----------------------------------+
| 7 | community name | |
+-----------------+-----------------+----------------------------------+
| 7 + len | 0xa2 0x1d | SNMP RESPONSE: |
| | | request_type=0xa2, length=0x1d |
+-----------------+-----------------+----------------------------------+
| 7 + len + 2 | 0x02 0x01 0x01 | SNMP request ID: integer, |
| | | length=1, ID=1 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 5 | 0x02 0x01 0x00 | SNMP error status: integer, |
| | | length=1, error=0 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 8 | 0x02 0x01 0x00 | SNMP index: integer, length=1, |
| | | index=0 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 11 | 0x30 0x12 | Varbind list, length=0x12 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 13 | 0x30 0x10 | Varbind, length=0x10 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 15 | 0x06 0x0a | Object ID, length=0x0a |
+-----------------+-----------------+----------------------------------+
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Table 2. SNMP RESPONSE PDU for GET of Agent's DPI port. This is the |
| layout of an SNMP RESPONSE PDU for GET DPI_port |
+-----------------+-----------------+----------------------------------+
| OFFSET | VALUE | FIELD |
+-----------------+-----------------+----------------------------------+
| 7 + len + 17 | 0x2b 0x06 0x01 | Object instance: |
| | 0x04 0x01 0x02 | 1.3.6.1.4.1.2.2.1.1.0 |
| | 0x02 0x01 0x01 | |
| | 0x00 | |
+-----------------+-----------------+----------------------------------+
| 7 + len + 27 | 0x02 0x02 | integer, length=2 |
+-----------------+-----------------+----------------------------------+
| 7 + len + 29 | msb lsb | port number (msb, lsb) |
+-----------------+-----------------+----------------------------------+
+----------------------------------------------------------------------+
The formula to calculate the length field "pdu_length" is as follows:
pdu_length = length of version field and string tag (4 bytes)
+ length of community length field (1 byte)
+ length of community name (depends...)
+ length of SNMP RESPONSE (31 bytes)
= 36 + length of community name
SNMP DPI Packet Formats
Each request to or response from the agent is constructed as a "packet" and is written to the stream.
Each packet is prefaced with the length of the data remaining in the packet. The length is stored in network byte order (most significant byte first, least significant last). The receiving side will read the packet by doing something similar to:
unsigned char len_bfr[2];
char *bfr;
int len;
read(fd,len_bfr,2);
len = len_bfr[0] * 256 + len_bfr[1];
bfr = malloc(len);
read(fd,bfr,len);
NOTE: the above example makes no provisions for error handling or a read returning less than the requested amount of data. This is not a suggested coding style.
The first part of every packet identifies the application protocol being used, as well as some version information. The protocol major version is intended to indicate in broad terms what version of the protocol is used. The protocol minor version is intended to identify major incompatible versions of the protocol. The protocol release is intended to indicate incremental modifications to the protocol. The constants that are valid for these fields are defined in Table 10 on page 18.
The next (common) field in all packets is the packet type. This field indicates what kind of packet we're dealing with (SNMP DPI GET, GET-NEXT, SET, TRAP, RESPONSE or REGISTER). The permitted values for this field are defined in Table 11 on page 18.
+----------------------------------------------------------------------+
| Table 3. SNMP DPI packet header. This header is present in all |
| packets. |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type |
+-------------+--------------------------------------------------------+
+----------------------------------------------------------------------+
From this point onwards, the contents of the packet are defined by the protocol being used. The remainder of this section describes:
-
the structure of packets for the SNMP DPI protocol, version 1.0.
-
The constants as defined with this version of the protocol.
REGISTER
In order to register a branch in the MIB tree, an SNMP sub-agent sends an SNMP DPI REGISTER packet to the agent.
Such a packet contains the standard SNMP DPI header plus REGISTER-specific data, which basically is a null terminated string representing the object ID in dotted ASN.1 notation (with a trailing dot!).
+----------------------------------------------------------------------+
| Table 4. SNMP DPI REGISTER packet. This is the layout of an SNMP |
| DPI REGISTER packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type = SNMP_DPI_REGISTER |
+-------------+--------------------------------------------------------+
| 6 | null terminated object ID |
+-------------+--------------------------------------------------------+
+----------------------------------------------------------------------+
GET
When the SNMP agent receives a PDU containing an SNMP GET request for a variable that a sub-agent registered with the agent, it passes an SNMP DPI GET packet to the sub-agent.
Such a packet contains the standard SNMP DPI header plus GET-specific data, which is basically a null terminated string representing the object ID in dotted ASN.1 notation.
+----------------------------------------------------------------------+
| Table 5. SNMP DPI GET packet. This is the layout of an SNMP DPI GET |
| packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type = SNMP_DPI_GET |
+-------------+--------------------------------------------------------+
| 6 | null terminated object ID |
+-------------+--------------------------------------------------------+
+----------------------------------------------------------------------+
GET-NEXT
When the SNMP agent receives a PDU containing an SNMP GET-NEXT request for a variable for which a sub-agent may be authoritative, it passes an SNMP DPI GET-NEXT packet to the sub-agent.
Such a packet contains the standard SNMP DPI header plus GET-NEXT-specific data. These data take the form of two null terminated strings. The first string represents the object ID in dotted ASN.1 notation; the second string represents the group ID in dotted ASN.1 notation.
+----------------------------------------------------------------------+
| Table 6. SNMP DPI GET NEXT packet. This is the layout of an SNMP |
| DPI GET NEXT packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type = SNMP_DPI_GET_NEXT |
+-------------+--------------------------------------------------------+
| 6 | null terminated object ID |
+-------------+--------------------------------------------------------+
| 6 + len | null terminated group ID |
+-------------+--------------------------------------------------------+
| NOTE: len=strlen(object ID)+1 |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
SET
When the SNMP agent receives a PDU containing an SNMP SET request for a variable that a sub-agent registered with the agent, it passes an SNMP DPI SET packet to the sub-agent.
Such a packet contains the standard SNMP DPI header plus SET specific data, which is basically a null terminated string representing the object ID in ASN.1 notation, with the type, value length and value to be set. The permitted types for the type field are defined in Table 12 on page 19. Integer values are sent as 4-byte elements in network byte order (most significant byte first, least significant byte last).
+----------------------------------------------------------------------+
| Table 7. SNMP DPI SET packet. This is the layout of an SNMP DPI SET |
| packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type = SNMP_DPI_SET |
+-------------+--------------------------------------------------------+
| 6 | null terminated object ID |
+-------------+--------------------------------------------------------+
| 6 + len | SNMP Variable Type Value |
+-------------+--------------------------------------------------------+
| 6 + len + 1 | Length of value (MSB) |
+-------------+--------------------------------------------------------+
| 6 + len + 2 | Length of value (LSB) |
+-------------+--------------------------------------------------------+
| 6 + len + 3 | Value |
+-------------+--------------------------------------------------------+
| NOTE: len=strlen(object ID)+1 |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
RESPONSE
An SNMP sub-agent must respond to a GET, GET_NEXT or SET request that it has received from the agent (unless it fails or has a bug). To do so, it sends an SNMP DPI RESPONSE packet to the agent.
Such a packet contains the standard SNMP DPI header plus RESPONSE specific data, which basically is an error_code plus (if there was no error), the name/type/value tuple representing the returned object. This is described as by a string representing the object ID in ASN.1 notation, plus the type, value length and value of the object that was manipulated. The permitted types for the type field are defined in Table 12 on page 19. Integer values are sent as 4-byte elements in network byte order (most significant byte first, least significant byte last).
+----------------------------------------------------------------------+
| Table 8. SNMP DPI RESPONSE packet. This is the layout of an SNMP |
| DPI RESPONSE packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type = SNMP_DPI_RESPONSE |
+-------------+--------------------------------------------------------+
| 6 | SNMP error code |
+-------------+--------------------------------------------------------+
| 7 | null terminated object ID |
+-------------+--------------------------------------------------------+
| 7 + len | SNMP Variable Type Value |
+-------------+--------------------------------------------------------+
| 7 + len + 1 | Length of value (MSB) |
+-------------+--------------------------------------------------------+
| 7 + len + 2 | Length of value (LSB) |
+-------------+--------------------------------------------------------+
| 7 + len + 3 | Value |
+-------------+--------------------------------------------------------+
| NOTE: len=strlen(object ID)+1 |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
TRAP
An SNMP sub-agent can request the agent to generate a TRAP by sending an SNMP DPI TRAP packet to the agent.
Such a packet contains the standard SNMP DPI header plus TRAP specific data, which is basically the generic and specific trap code, plus a name/type/value tuple. The tuple is described by a string representing the object ID in ASN.1 notation, plus the type, value length and value of the object that is being sent in the trap. The permitted types for the type field are defined in Table 12 on page 19. Integer values are sent as 4-byte elements in network byte order (most significant byte first, least significant byte last).
+----------------------------------------------------------------------+
| Table 9. SNMP DPI TRAP packet. This is the layout of an SNMP DPI |
| TRAP packet |
+-------------+--------------------------------------------------------+
| OFFSET | FIELD |
+-------------+--------------------------------------------------------+
| 0 | packet length to follow (MSB) |
+-------------+--------------------------------------------------------+
| 1 | packet length to follow (LSB) |
+-------------+--------------------------------------------------------+
| 2 | protocol major version |
+-------------+--------------------------------------------------------+
| 3 | protocol minor version |
+-------------+--------------------------------------------------------+
| 4 | protocol release |
+-------------+--------------------------------------------------------+
| 5 | packet type - SNMP_DPI_TRAP |
+-------------+--------------------------------------------------------+
| 6 | SNMP generic trap code |
+-------------+--------------------------------------------------------+
| 7 | SNMP specific trap code |
+-------------+--------------------------------------------------------+
| 8 | null terminated object ID |
+-------------+--------------------------------------------------------+
| 8 + len | SNMP Variable Type Value |
+-------------+--------------------------------------------------------+
| 8 + len + 1 | Length of value (MSB) |
+-------------+--------------------------------------------------------+
| 8 + len + 2 | Length of value (LSB) |
+-------------+--------------------------------------------------------+
| 8 + len + 3 | Value |
+-------------+--------------------------------------------------------+
| NOTE: len=strlen(object ID)+1 |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
Constants and Values
This section describes the constants that have been defined for this version of the SNMP DPI Protocol.
Protocol Version and Release Values
+----------------------------------------------------------------------+
| Table 10. Protocol version and release values |
+-----------------------------------+----------------------------------+
| FIELD | VALUE |
+-----------------------------------+----------------------------------+
| protocol major version | 2 (SNMP DPI protocol) |
+-----------------------------------+----------------------------------+
| protocol minor version | 1 (version 1) |
+-----------------------------------+----------------------------------+
| protocol release | 0 (release 0) |
+-----------------------------------+----------------------------------+
+----------------------------------------------------------------------+
Any other values are currently undefined.
Packet Type Values
The packet type field can have the following values:
+----------------------------------------------------------------------+
| Table 11. Valid values for the packet type field |
+-------+--------------------------------------------------------------+
| VALUE | PACKET TYPE |
+-------+--------------------------------------------------------------+
| 1 | SNMP_DPI_GET |
+-------+--------------------------------------------------------------+
| 2 | SNMP_DPI_GET_NEXT |
+-------+--------------------------------------------------------------+
| 3 | SNMP_DPI_SET |
+-------+--------------------------------------------------------------+
| 4 | SNMP_DPI_TRAP |
+-------+--------------------------------------------------------------+
| 5 | SNMP_DPI_RESPONSE |
+-------+--------------------------------------------------------------+
| 6 | SNMP_DPI_REGISTER |
+-------+--------------------------------------------------------------+
+----------------------------------------------------------------------+
Variable Type Values
The variable type field can have the following values:
+----------------------------------------------------------------------+
| Table 12. Valid values for the Value Type field |
+-------+--------------------------------------------------------------+
| VALUE | VALUE TYPE |
+-------+--------------------------------------------------------------+
| 0 | text representation |
+-------+--------------------------------------------------------------+
| 129 | number (integer) |
+-------+--------------------------------------------------------------+
| 2 | octet string |
+-------+--------------------------------------------------------------+
| 3 | object identifier |
+-------+--------------------------------------------------------------+
| 4 | empty (no value) |
+-------+--------------------------------------------------------------+
| 133 | internet address |
+-------+--------------------------------------------------------------+
| 134 | counter (unsigned) |
+-------+--------------------------------------------------------------+
| 135 | gauge (unsigned) |
+-------+--------------------------------------------------------------+
| 136 | time ticks (1/100ths seconds) |
+-------+--------------------------------------------------------------+
| 9 | display string |
+-------+--------------------------------------------------------------+
+----------------------------------------------------------------------+
NOTE: Fields which represent values that are stored as a 4-byte integer are indicated by ORing their base type value with 128.
Error Code Values for SNMP Agent Detected Errors
The error code can have one of the following values:
+----------------------------------------------------------------------+
| Table 13. Valid values for the SNMP Agent Minor Error Code field |
+-------+--------------------------------------------------------------+
| VALUE | SNMP AGENT ERROR CODE |
+-------+--------------------------------------------------------------+
| 0 | no error |
+-------+--------------------------------------------------------------+
| 1 | too big |
+-------+--------------------------------------------------------------+
| 2 | no such name |
+-------+--------------------------------------------------------------+
| 3 | bad value |
+-------+--------------------------------------------------------------+
| 4 | read only |
+-------+--------------------------------------------------------------+
| 5 | general error |
+-------+--------------------------------------------------------------+
+----------------------------------------------------------------------+