Previous Table of Contents Next


The following list summarizes the three classes of Type fields used with SNMP and the encodings for those fields: class, P/C, and tag number. These encodings appear in both binary and hexadecimal notation, where the Hrepresents hexadecimal notation:

Universal Class Type Field Value

INTEGER 00000010 = 02H
OCTET STRING 00000100 = 04H
NULL 00000101 = 05H
OBJECT IDENTIFIER 00000110 = 06H
SEQUENCE 00110000 = 30H
SEQUENCE-OF 00110000 = 30H

Application Class Type Field Value

IpAddress 01000000 = 40H
Counter 01000001 = 41H
Gauge 01000010 = 42H
TimeTicks 01000011 = 43H
Opaque 01000100 = 44H

Context-Specific Class Type Field Value

GetRequest 10100000 = A0H
GetNextRequest 10100001 = A1H
GetResponse 10100010 = A2H
SetRequest 10100011 = A3H
Trap 10100100 = A4H

Although the BER also provide tag numbers of 31 or greater, SNMP does not use these (see the lower portion of Figure 2-4). For tag numbers larger than 31, the Type field uses a different format. The tag number in the first octet is set to binary 11111, and subsequent octets are added to carry the tag number. Bit 8 = 1 of an octet indicates that more octets will follow; Bit 8 = 0 of an octet specifies the last octet. Bits 7 through 1 of each subsequent octet carry the unsigned binary integer of the tag number. Bit 7 of the first subsequent octet indicates the MSB of the tag number.

2.5.2.2 Length Field

The Length field follows the Type field and determines the number of octets the Value field will contain. The Length field may take either the short definite or the long definite form, as shown in Figure 2-5. (Another form, called “indefinite,” is not used with SNMP.) The Definite indicates that the length of the encoding is known prior to transmission; the indefinite indicates otherwise.


Figure 2-5.  Length field encoding

The short definite form indicates a length of between 0 and 127 octets in the Contents field; the long definite form indicates 128 or more octets in the Contents field, although it can indicate shorter lengths.

The long form uses multiple octets to represent the total length. In the long form, the first octet of the Length field has Bit 8 = 1, followed by a binary number indicating the number of octets to follow. This number must be between 1 and 126; 127 is reserved for future extensions. Bit 8 of the second octet is considered the MSB of the Length field, and the following octets make up the rest of the length. Thus, the long definite form may represent a length up to 21008-1 octets. (The 1008 is derived from the product of 126 and 8 — 126 subsequent octets times 8 bits per octet.)

2.5.2.3 Value Field

The Value field contains zero or more contents octets, which convey the data values. Examples include an integer, ASCII character, or OBJECT IDENTIFIER, such as { 1.3.6.1.2. }.

2.5.3 Encoding Examples

Section 2.4.2 mentioned that the Internet SMI defines a subset of the ASN.1 types. This subset includes the following universal Primitive types: INTEGER, OCTET STRING, OBJECT IDENTIFIER, and NULL. The universal Constructor types are SEQUENCE And SEQUENCE OF. The application Primitive types are IpAddress, Counter, Gauge, and TimeTicks. SNMP-related applications use only these ten types. I will use this information in the case studies presented in the following chapters. For illustrations of the other types, consult ISO 8825-1.

2.5.3.1 INTEGER Type Encoding

The INTEGER type is a Simple type that has values of zero, positive, or negative whole numbers. It is a Primitive type encoded with a Value field containing one or more Contents octets. The Contents octets are “two’s-complement” binary number equal to the integer value, and they can use as many octets as necessary. For example, Boomer, my Labrador, weighs 75 pounds. The value of his weight would be encoded as: Type field = 02H, Length field = 01H, and Value field = 4BH (see Figure 2-6). Note that the value appears in quotes (Value = “75”) to indicate that it represents a quantity, which can be numerical, ASCII characters, an IP address, and so on.


Figure 2-6.  Encoding for the INTEGER type, Value = “75”

2.5.3.2 OCTET STRING Type Encoding

The OCTET STRING is a Simple type whose distinguished values are an ordered sequence of zero, one, or more octets, each of which must be a multiple of 8 bits. Encoding for OCTET STRING values is primitive, with the Type field = 04H. The Length field and Value field depend on the encoded information.

Let’s again use Boomer as an example to show the OCTET STRING type encoding. Figure 2-7 shows how I encoded the value for Boomer’s initials (BBM, for Boomerang Buddy Miller). The Type field contains 04H, indicating a Primitive type, OCTET STRING (tag number 4). The Length field indicates 3 octets in the Value field. The Value field encodings come from the ASCII chart.


Figure 2-7.  Encoding for the OCTET STRING type, Value = “BBM”

2.5.3.3 OBJECT IDENTIFIER Type Encoding

The OBJECT IDENTIFIER names (or identifies) items. (In SNMP, these identify managed objects.) Its Value field contains an ordered list of subidentifiers. To save encoding and transmission effort, you can take advantage of the fact that the first subidentifier is a small number, such as 0, 1, or 2, and combine it mathematically with the second subidentifier, which may be larger. The total number of subidentifiers is, therefore, less than the number of object identifier components in the OID value being encoded. This reduced number (one less) results from a mathematical expression that uses the first two OID components to produce another expression:

    Given X is the value of the first OID, and Y is the second:
    First subidentifier = (X * 40) + Y


Previous Table of Contents Next