Previous Table of Contents Next


2.4.5 Tagged Types

Tags distinguish between defined objects unequivocally. While a human reader might be able to distinguish defined objects through their names in ASN.1 notation, a machine can’t without additional information. Therefore, the tagged types use a previously defined type as a base, and then add unique information. ASN.1 defines four classes of tags: universal, application, context specific, and private. ASN.1 (ISO 8824-1) defines universal tags. Other standards, such as the Internet standards, assign application class tags. The SNMP definition (RFC 1157) interprets context-specific class tags according to their context. Enterprise-specific applications use private class tags.

A number within square brackets ([ ]) identifies tagged types. For example, the concise SMI definition (Section 2.7) shows that

       TimeTicks ::=
        [APPLICATION 3]
           IMPLICIT INTEGER (0..4294967295)

Therefore, the TimeTicks type is a tagged type, designated APPLICATION 3. It is of the application class, and the tag number is 3. It may take on the range of values between 0 and 4294967295. The IMPLICIT keyword indicates that the tag associated with the INTEGER type is not transmitted, but the tag associated with TimeTicks is. This reduces the amount of data that must be encoded and transmitted.

2.5 Encoding Rules

Section 2.4 discusses the abstract syntax that represents management information. This section discusses the encoding rules that allow that information to be transmitted on a network. The Basic Encoding Rules (BER) define this transfer syntax, and ISO 8825-1 specifies it [2-6].

2.5.1 Encoding Management Information

Recall that each machine in the management system can have its own internal representation of the management information. The ASN.1 syntax describes that information in a standard form. The transfer syntax performs the bit-level communication (the external representation) between machines. For example, assume that the host needs management information from another device. The management application would generate an SNMP request, which the BER would encode and transmit on the network media. The destination machine would receive the information from the network, decode it using the BER rules, and interpret it as an SNMP command. The SNMP response would return in a similar, but reverse, manner. The encoding structure used for the external representation is called Type-Length-Value encoding (see Figure 2-1).


Figure 2-1.  Internal and external data representations

2.5.2 Type-Length-Value Encoding

To define the external data representation, the BER first specify the position of each bit within the octets being transmitted. Each octet transmits the most significant bit (MSB) first and defines it as bit 8 on the left-hand side of the octet. The octet defines the least significant bit (LSB) as bit 1 on the right-hand side (see Figure 2-2).


Figure 2-2.  BER bit ordering, as defined in ISO 8825-1

The data encoding structure itself has three components: the Type, Length, and Value (TLV). Note that in the literature you will run across other names for Type-Length-Value, including Tag-Length-Value and Identifier-Length-Contents (from ISO 8825-1). The structure of a TLV encoding used with SNMP is shown in Figure 2-3.


Figure 2-3.  Type-Length-Value (TLV) encoding

By defining the order and structure of the bits, the BER guarantee that both ends of the communication channel interpret the bit stream consistently. The following sections examine the structure of each TLV field individually.

2.5.2.1 Type Field

The Type field comes first and alerts the destination to the structure that follows. Thus, the Type field contains an identification for the encoding structure; it encodes the ASN.1 tag (both the class and number) for the type of data contained in the Value field. A subfield within the Type field contains a bit designated as P/C that indicates whether the coding is Primitive (P/C = 0) or Constructed (P/C = 1), as shown in Figure 2-4.


Figure 2-4.  Type field encoding (Source: ISO 8825-1)

There are two types of Type fields; and their use depends on the magnitude of the tag number. When the tag number is between 0 and 30, the Tag field contains a single octet (see Figure 2-4). When the tag number is 31 or greater, the Type field contains multiple octets. In either case, the first octet contains three subfields: the Class, P/C bit, and tag number. The Class subfield encodes the class of tag in use:

Class Bit 8 Bit 7

Universal   0   0
Application   0   1
Context-specific   1   0
Private   1   1

SNMP applications use the first three classes: universal, application, and context specific. The universal class encodes the INTEGER type, OCTET STRING type, and so on. The application class encodes the defined types (IpAddress, Counter, and so on). The context-specific class encodes the five SNMP protocol data units (PDUs), GetRequest, GetResponse, and so on.

The P/C subfield (bit 6) indicates the form of the data element. Primitive encoding (P/C = 0) means that the contents octets represent the value directly. A Constructor encoding (P/C = 1) means that the contents octets encode one or more additional data values, such as a SEQUENCE.

SNMP uses tag numbers between 0 and 30. The tag number appears in the third subfield and is represented in binary. Bit 5 is the tag’s MSB; bit 1 is its LSB.

ISO 8824-1 contains tag numbers for the universal class (for example, UNIVERSAL 2 represents the INTEGER type). The SMI specification, RFC 1155, contains tag numbers for the application class (for example, IpAddress is a primitive type with tag [0]). The SNMP specification, RFC 1157, contains tag numbers for the context-specific class (for example, GetRequest PDU is a constructed type with tag [0]).


Previous Table of Contents Next