NetHead
NetHead

Reputation: 81

SNMP table index using octet string

I am working on an SNMP agent using net-snmp and developing a MIB for data held in tables.

I am considering using a table key based on a string of around 15 decimal digits.

Is it reasonable to implement this as an OCTET STRING index?

Even if I encode 2 digits per octet, it would be around 8 octets long.

With an OCTET STRING index, each octet would be added as a node to the OID.

I know that I can convert this to an integer(s), but the decimal digits could have leading zeros.

Are there any views or suggestions for this?

Thanks in advance.

Upvotes: 1

Views: 8167

Answers (1)

Wes Hardaker
Wes Hardaker

Reputation: 22262

You can put zeros into OCTET STRINGS, so yes you can do it that way. OCTET STRINGS can contain binary data, and are encoded as simply a number into the OID. The Net-SNMP API accepts not just a pointer to the char *, but also the length of the data returned. And this is specifically because it's perfectly legal to have OCTET STRINGS with null values encoded within it.

On the OID side, if you had the string consisting of characters A, B 0, D it would generally be encoded as:

blah.blah.4.65.66.0.67

Where 4 is the length of the string. If the OCTET STRING is marked as IMPLICIT, then the 4 would be left out.

You're encoding decimal digits into the string, so your values would be closer to things like 0x15, 0x04, 0x42, etc. Those are just fine as well (you're building a binary string).

Whether you should do that or whether you should just plop the integers themselves down in the string is subject to debate but depends on what you're doing, and the bandwidth constraints of the environment, etc.

Upvotes: 3

Related Questions