How to encode and decode large OID values?
Asked Answered
R

1

6

I have OID of 1.3.6.1.2.1.2.2.1.8.4096 (ifOperStatus)

In my code I have:

MIB[0]=0x2b
MIB[1]=0x06
MIB[2]=0x01
MIB[3]=0x02
MIB[4]=0x01
MIB[5]=0x02    
MIB[6]=0x02
MIB[7]=0x01
MIB[8]=0x08
MIB[9]=0xA0
MIB[10]=0x00

where A0 00 represents 4096.

4096 in HEX is 1000. Breaking this in 2 bytes will give me 10 00. SNMP data should be sent in single byte format. Therefore, a special rule is required for large numbers because one byte (eight bits) can only represent a number from 0-255. The rule is the highest order bit is used as a flag to let the recipient know that this number spans more than one byte.

I have shifted the bits to the left and added 1 to the 8th bit.

Shift left: 20 00
Bit 8 becomes 1: A0 00

Reference: [OID Encoding] (http://www.rane.com/note161.html)

Have I encoded the 4096 correctly?

What about decoding string of data to the original OID ?

Examples would be good for me to understand the concept.

Reginaldreginauld answered 11/8, 2013 at 21:10 Comment(0)
P
5

Yes, you have encoded the OID correctly (as far as the contents go). The full encoding (with tag for OID and length, which were omitted) would be 06 0b 2b 06 01 02 01 02 02 01 08 a0 00.

With regards to encoding/decoding strings in OIDs (presumably an INDEX), the rules depend on whether or not the value in question is for an object defined as a fixed-length or variable-length string, and whether or not the IMPLIED keyword was used in defining the INDEX.

If it's a fixed-length string, or variable-length string with IMPLIED keyword (which would have to be the last INDEX object) then it is encoded simply as one subidentifier per byte of string. Otherwise, a variable-length string is encoded with one subidentifier to indicate the length of the string, followed by each byte encoded in a single subidentifier as with fixed-length.

RFC 2578 section 7.7 details the rules for encoding values for INDEX objects in an OID.

Psephology answered 12/8, 2013 at 3:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.