30.11 Example encoded SNMP Message
The encoded form of ASN.1 uses Variable-length fields to represent items. In general, each field is begins with a header which specifies the type of object and its length in bytes. For example, each SEQUENCE begins with an octet containing (hexadecimal); The next octet specifies the number of following octets that comprise the sequence.
Figure 30.11 contains a example SNMP message that illustrates how values is encoded into octets. The message is a get-request that specifies data item SYSDESCR (Numeric object identifier 1.3.6.1.2.1.1. 1.0). Because The example shows an actual message, it includes many details. In particular, the message contains a msgsecurityparameters sections which have not been discussed above. This particular message uses the usmsecurityparameters form of security parameters. It should is possible, however, to correlate and other sections of the message with the definitions above.
As Figure 30.11 shows, the message starts with a code for SEQUENCE which have a length of 103 octets8. The first item in the sequence was a 1-octet integer that specifies the protocol version; The value 3 indicates that's a SNMPV3 message. Successive fields define a message ID and the maximum message size the sender can accept in a reply. Security information, including the name of the user (Comerbook) follows the message header.
TheGETREQUEST-PDUOccupies the tail of the message. The sequence labeledSCOPEDPDUSpecifies a context in which to interpret the remainder of the message. The octet A0 Specifies the operation as aget-request. Because the High-order bit is turned on, the interpretation of the octet isContext Specific. That is, the hexadecimal valueA0only specifies aGETREQUEST-PDUWhen used in context; It is a universally reserved value. Following the request octet, the length octet specifies the request is a octets long. The request ID is 2 octets, but each of the error-status and Error-index is one octet. Finally, the sequence of pairs contains one binding, a single object identifier bound to aNULLValue. The identifier is encoded as expected except, the fist, and numeric are labels to a single combined.
8Sequence items occur frequently in an snmpmessage because SNMP uses SEQUENCE instead of conventional
Programming language constructs like arrayor struct
Abstract from internetworking with TCP/IP Vol i:principles, protocols, and Architecture fourth Edition,
DOUGLAS E. Comer,
Department of computer Sciences Purdue University, West Lafayette, in 47907,
PRENTICE HALL,
Upper Saddle River, New Jersey 07458
example:encoded SNMP Message-snmp Tutorial