JFLib

netpkt/mib.rs#

Source: lib/netpkt/mib.rs

mib -- a small built-in MIB: the objects of SNMPv2-MIB (system, snmp, the notifications of
RFC 3418), IF-MIB (interfaces, ifTable, ifXTable, linkDown and linkUp of RFC 2863), IP-MIB
(ipForwarding, ipDefaultTTL, ipAddrTable) and IP-FORWARD-MIB (ipCidrRouteTable of RFC 2096)
with the nodes of SNMPv2-SMI above them: names, OIDs, syntax, access, the names of enumerated
values; for the tools of a shell and for dissectors

  OBJECTS                    every object in OID order (Obj: module, name, oid, kind, syntax,
                             access, enums)
  find(oid) / by_name(name)  an object exactly
  object_of(oid)             the object an OID names or is an instance of, with the arcs of the
                             instance (sysName.0: sysName and [0])
  name_of(oid, numeric)      "SNMPv2-MIB::sysName.0", "IF-MIB::ifDescr.2",
                             "SNMPv2-SMI::enterprises.32473.1.4"; numeric: ".1.3.6.1.2.1.1.5.0"
  lookup(text)               an OID from what a user types: "SNMPv2-MIB::sysName.0",
                             "sysName.0", "ifTable", "iso.3.6.1", "1.3.6.1.2.1.1.5.0" or with a
                             leading dot
  show(oid, value, numeric)  the value as the tools of net-snmp print it after "=": "STRING:
                             R1", "INTEGER: up(1)", "Timeticks: (500) 0:00:05.00", "OID:
                             IF-MIB::linkDown" (the exceptions in our own words)
  bare(oid, value)           the same without the type (snmpget -Oq): "R1", "up"
  ticks_text(t)              "(500) 0:00:05.00", "(8640000) 1 day, 0:00:00.00"
  children(oid)              the objects one level below a node (a tree of the MIB)

Names and syntax follow the MIB modules; the table has only what JFNetworker's agent serves
and what names it, no descriptions (the RFCs have them).  The access is the agent's: objects
a module allows to write but the agent does not (ipForwarding, ipDefaultTTL,
ifLinkUpDownTrapEnable, ifPromiscuousMode) are read-only here.  A name the table does not know
is written with the arcs below the nearest one it knows, as net-snmp does ("iso.2.999").
  • enum ObjKind what an object is

    • Node -- a node of the tree (system, ifMIB, enterprises)
    • Scalar -- a scalar: its instance is .0
    • Table
    • Entry -- the row of a table
    • Column -- a column: its instances are the indexes of the rows
    • Notification -- a notification (a value of snmpTrapOID.0)
  • enum Syntax the syntax of a scalar or a column

    • None
    • Integer
    • DisplayString -- text up to 255 octets (RFC 2579)
    • PhysAddress -- octets shown as hex digits with colons (RFC 2579)
    • Octets
    • Oid
    • IpAddress
    • Counter32
    • Gauge32
    • TimeTicks
    • Counter64

impl Syntax

  • fn tag(self) -> u8 the BER tag of its values

  • fn name(self) -> &'static str the name the MIB module gives it

  • enum Access who may do what with an object

    • NotAccessible
    • ReadOnly
    • ReadWrite
    • Notify -- only in notifications (snmpTrapOID)

impl Access

  • fn name(self) -> &'static str

  • struct Obj an object of the MIB

    • module: &'static str
    • name: &'static str
    • oid: &'static [u32]
    • kind: ObjKind
    • syntax: Syntax
    • access: Access
    • enums: &'static [(i64, &'static str)] -- the names of an INTEGER's values ("up" for 1)
/// the objects in OID order
OBJECTS: &[Obj] = &[ node(SMI, "zeroDotZero", &[0, 0]), node(SMI, "iso", &[ ...
  • fn find(oid: &[u32]) -> Option<&'static Obj> an object by its OID exactly

  • fn by_name(name: &str) -> Option<&'static Obj> an object by its name (case matters, as in the MIB modules)

  • fn object_of(oid: &[u32]) -> Option<(&'static Obj, &[u32])> the longest object the OID starts with, and the arcs after it

  • fn column_of(oid: &[u32]) -> Option<&'static Obj> the scalar or column an OID is an instance of (sysName.0, ifDescr.2)

  • fn name_of(oid: &[u32], numeric: bool) -> String a name as net-snmp's tools write it: MODULE::name and the arcs after it; numeric: the arcs with a leading dot

  • fn short_name(oid: &[u32]) -> String the name without the module ("sysName.0"; snmpget -Os)

  • fn lookup(text: &str) -> Option<Oid> an OID from what a user types: MODULE::name.arcs, name.arcs, dotted arcs (a leading dot allowed); None for a name the table does not know or arcs that are no numbers

  • fn children(oid: &[u32]) -> Vec<&'static Obj> the objects one level below oid (the children of a node, the columns of an entry), in OID order; an object whose parent the table lacks hangs below its nearest ancestor

  • fn ticks_text(t: u32) -> String "(500) 0:00:05.00", "(8640000) 1 day, 0:00:00.00" as net-snmp writes TimeTicks

  • fn show(oid: &[u32], v: &Value, numeric: bool) -> String the value after "=" as net-snmp's tools print it; the object named by oid gives the form of strings and the names of integers; numeric writes OIDs as numbers

  • fn bare(oid: &[u32], v: &Value, numeric: bool) -> String the value alone (snmpget -Oqv): the name of an enumerated value, a text without quotes

Source: docs/API.md in the JFLib repository.