Re: [tkined] automate SNMP testing

Juergen Schoenwaelder (schoenw@ibr.cs.tu-bs.de)
Thu, 8 Apr 1999 10:41:53 +0200

>>>>> Qiu Jin writes:

Qiu> This question is about synchronization of received traps by bind
Qiu> command.

Qiu> I try to use tnm to automate SNMP testing. The test has following
Qiu> steps:

Qiu> 1) Set mib variable pluginAdminState.3.3 down
Qiu> 2) The traps should be received within 10 sec.
Qiu> 3) If four traps are received then the test result will be PASS;
Qiu> otherwise, the test result will be FAIL.

Qiu> I use snmp# bind "" trap "traphandler %A %V" command in my
Qiu> script. Where should I put the code to determine the test
Qiu> result? Any sample program I can refer to?

Qiu> Seems like that the scotty script will first execute all the
Qiu> commands after snmp# bind "" trap "traphandler %A %V"; and then,
Qiu> if there are traps in the queue, it will call traphandler.
Qiu> Correct me if I misunderstood.

Always remember that Tcl is event-driven and single-threaded. This
means that callback procedures (e.g. your traphandler) will only be
called if Tcl falls in its event loop and processes events. Therefore,
what you want to do is something similar to the following:

proc traphandler {addr varbind} {
global trapcount
# analyze the trap, e.g. extract the trapOid
incr trapcount($trapOid)
}

$t bind {} trap "traphandler %A %V"

proc test {s} {
global trapcount
set cnt $trapcount(myPluginTrap)
$s set {{pluginAdminState.3.3 down}}
after 10000 set timeoutvar foo
vwait timeoutvar
if {$trapcount(myPluginTrap) < $cnt+4} {
error "test failed"
}
}

(Note, this is pseudo code which is not expected to run. But it might
help to get the idea how you do these things within Tcl.)

Juergen

--
!! This message is brought to you via the `tkined & scotty' mailing list.
!! Please do not reply to this message to unsubscribe. To subscribe or
!! unsubscribe, send a mail message to <tkined-request@ibr.cs.tu-bs.de>.
!! See http://wwwsnmp.cs.utwente.nl/~schoenw/scotty/ for more information.