Receiving Traps and Informs
We've split up the SNMPv2c and SNMPv3 trap receivers into two separate classes, V2TrapReceiver
and V3TrapReceiver
. These classes implement CommandResponder
. This means that we must implement a method that has the following signature:
public synchronized void processPdu(CommandResponderEvent e) { ... }
The processPdu
method is responsible for handling incoming requests. Since SnmpWalk
supports SNMPv3, we have to be able to respond to discovery requests from an authoritative SNMP engine.
Tip
With the other SNMP applications, we created transport objects that were a combination of the IP address and port on a remote machine. With a trap or inform receiver, we create a target object, but the IP address is the IP of the local Ethernet interface we wish to bind to, along with the port (default for traps is 162).
Consider the following code sequence:
_threadPool = ThreadPool.create("DispatcherPool", _numThreads); MessageDispatcher mtDispatcher = new MultiThreadedMessageDispatcher(_threadPool, new MessageDispatcherImpl()); // add message processing models mtDispatcher.addMessageProcessingModel(new MPv2c()); // add all security protocols SecurityProtocols.getInstance().addDefaultProtocols(); CommunityTarget target = new CommunityTarget(); if(target != null) { target.setCommunity(_comm); _target = target; } else { System.out.println("Unable to create Target object"); System.exit(-1); } _snmp = new Snmp(mtDispatcher, _transport); if(_snmp != null){ _snmp.addCommandResponder(this); ...
Get Essential SNMP, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.