http://qs321.pair.com?node_id=653590

I have what I hope is an interesting proposition for whomever's reading this node!

I am trying to design a distribution for working with SNMP, that I will eventually upload to CPAN. I've been disappointed in one way or another by the API of every SNMP module I've tried, but I haven't given up hope that there can be something better.

Smarter hackers than I have put their hands to this task before, but I still believe there's a better way and I need your help to find it!

Everything in this RFC is up for debate and constructive criticism, and if anyone wishes to collaborate further on this project, I welcome you!

To begin, I have laid out the following terminology:
SNMP MIB Terminology: MIB - A Management Information Base. It's a database, essentially, j +ust not a familiar RDBMS. Every device that supports SNMP has one, whi +ch you can query and update, if you know it's schema. The schema of a MIB + is defined in a set of MIB files where each file contains modular + portions of the schema. Since each device may implement a different ove +rall schema, a module-based approach allows for that sort of flexib +ility MIB File - An ASCII text file written according to the SMI format, w +hich is based on and defined using ASN.1. The MIB file is used to + define and describe the schema of an SNMP MIB, or a portion of o +ne. MIB Object - A queriable entity from an SNMP MIB. In a MIB browser, +this is often described as a leaf or column. Each MIB Object is + defined in a MIB file using the OBJECT-TYPE syntax. A MIB Objec +t would define the following properties: object_type: The name of this object in the SMI OBJECT-TYPE def +inition in the MIB File. type_oid: The OID of the object_type, as defined in the MIB. index_name[n]: The name of the n-th index of this object-type, as + defined in the MIB. (only valid for tables, table entries, an +d columns) Object Instance - To borrow terminology from Object Oriented Program +ming, if a MIB Object is a class definition, an Object Instan +ce is an instance of an object of a class. In addition to t +he properties of a MIB Object, it has the following w +hich establish it's identity and value: value: The actual value, as returned from a query to a dev +ice. instance_id: The specific identity of this object instance in a +device in relation to it's object_type. It is a portion of an + OID string that is composed by the concatenation of one + or more indices. index_val[n]: The value of the n-th index of this object's instan +ce full_oid: The full identifier for this particular object inst +ance in a device's MIB. It's the same as concatenating the ty +pe_oid and instance_id
Some additional notes:

An OID is a way of identifying objects in a MIB. an OID is composed of an array of Octets, represented by integers with a \. between each element. Each object in a MIB has a unique OID, and instances of objects have additional octets on the end that define their identity in relation to their object-type.

There are several types of objects, but only a few can be queried. The queriable object types are scalars and columns, but for the purposes of this we only will consider columns, because scalars are *much* simpler.

Column objects are assembled into groupings called Tables, and tables contain a Table Entry object which defines what indexes are used to construct the instance_id of available Object Instances of the column objects within the table.

These concepts are what SNMP is built on. SNMP is essentially object-oriented, but uses mechanisms and concepts that are (academically) supposed to be straight-forward to implement in C. (they usually aren't) It's both elegantly simple and frustratingly complex, depending on the implementation, much like some programming languages. ;)

With this terminology in mind, I have the following scenarios as 'use cases'for which I am trying to develop a clean, clear, flexible general API.

Objects that I am presenting in these use cases will be specified not using their Numeric OIDs (.1.3.6.1.4.1...) but rather their Symbolic OIDs (textual names defined in the MIB Files)

First, a simple one:
ifTable.ifEntry.ifType - value is an integer representing the type of interface - index_val[0] is an integer value known as an ifIndex ifTable.ifEntry.ifAdminStatus - value is an integer that represents an interface's administrative +state (1=up,2=down,3=testing) - index_val[0] is an integer value known as an ifIndex ifTable.ifEntry.ifInOctets - value is the number of bytes that have passed through the interfac +e since being turned up. - index_val[0] is an integer value known as an ifIndex
We want to retrieve the full_oid of any ifInOctets objects whose instance_id matches (the instance_ids of all ifType objects whose value is 18) and (the instance_ids of all ifAdminStatus objects whose value is 1)


Second, a more complex one:
adMX2820M13PrvSlotTable.adMX2820M13PrvSlotEntry.adMX2820M13PrvCardPair +ID - value is the name of the protection pair - index_val[0] is the slot number of this card in the pair adGenPortSlotMapTable.adGenPortSlotMapEntry.adGenSlotAddress - value is the slot number an interface is provisioned on (many interfaces per slot) - index_val[0] is the ifIndex value that corresponds to an interface + adMX2820M13StatDS3Table.adMX2820M13StatDS3Entry.adMX2820M13NetFuncServ +State - value is a bitmask with the status of a DS3 circuit - index_val[0] is the ifIndex value that corresponds to this interfa +ce
We want to retrieve the values of the adMX2820M13NetFuncServState objects that are only provisioned in slots whose adMX2820M13PrvCardPairID value is not blank and does not match '/not in use/i'


If you could write code to implement any of these use cases any way you wished, what would it look like? Pseudo-code is just as welcome as Perl.