snmp getbulk
nr mr vbl [script]
The snmp# getbulk session
command can be used to implement faster MIB tree walks by using get-bulk-requests.
The getbulk session command
performs a getnext on the first nr elements given in the varbind
list vbl. For the remaining elements, the agent is asked to repeat the
getnext operation mostly mr times.
SNMPv1 sessions automatically
map getbulk-requests to getnext-requests. If
the getbulk session command contains a callback
script, then the command sends the getbulk-request and returns immediately.
The result is the request
id for the asynchronous request. The getbulk session command is processed
synchronously if the callback script is absent. In this case, the received
varbind list is returned.
The command fails with a
Tcl error if the agent does not respond or if a protocol error happens.
The following synchronous
example show how to retrieve the value of ifNumber.0 and how to use it
to read columns of the ifTable in a single getbulk operation.
set err [catch {$s
get ifNumber.0} vbl]
if {$err == 1} { exit 1
}
set m [snmp value $vbl 0]
set vbl {SNMPv2-MIB!sysUpTime\
IF-MIB!ifDescr
IF-MIB!ifLastChange} set err [catch \
{$s getbulk
1 $m $vbl} vbl]
if {$err == 1} { exit 2
}
puts $vbl
The example below does the same
thing asynchronously. Note, both examples are simplifications because the
getbulk does not guarantee that all mr repetitions are actually made. You
therefore have to ask ifNumber.0 + 1 repetitions so that you are able to
detect whether you got the whole table or just parts of it.
proc getit {s m}
{
set vbl {SNMPv2-MIB!sysUpTime\
IF-MIB!ifDescr
IF-MIB!ifLastChange}
$s getbulk 1 $m $vbl
{
if {”%E”
== “noError”} {
puts “%V”
}
}
}
$s get ifNumber.0 {
if {”%E” == “noError”}
{
getit %S [snmp value
“%V” 0]
}
}
|