![]() |
|||
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
![]() ![]() |
![]() |
| ||||||||
As you can see, once the SNMPv3 session has been instantiated and the SNMPv3 USM peer has been created and configured, the inform request is sent in exactly the same way as under SNMPv2. The only difference is the additional SNMPv3 security. 17.3.3 Receiving Inform RequestsManagers receive inform requests as they do traps: they are unsolicited events that must be received by a dispatcher object. Unlike traps, an inform request requires a response PDU that, according to the SNMP specification, must contain the same variable bindings. Therefore, immediately after an inform request is successfully received and decoded, the SnmpEventReportDispatcher class automatically constructs and sends the inform response back to the originating host. The manager application then retrieves the data in the inform request through a listener on the dispatcher. Inform request listeners are registered with the dispatcher object in the same way as trap listeners. The receiving manager in our example is very simple, because its only function is to create the dispatcher and the listener for inform requests. The receiving manager SimpleManager2 is the same for both the SimpleManager1 and SimpleManager1V3 examples. Example 17-11 Receiving Inform Requests in SimpleManager2
The remaining step is to program the behavior we want upon receiving an inform request. To do this, we must write the InformListenerImpl class that we registered as an inform request listener in the previous code sample. This class implements the SnmpInformListener interface and its processSnmpInform and processSnmpInformV3 methods handle the incoming inform requests. Because the dispatcher automatically sends the inform response back to the originating host, the SnmpInformListener implementation does not need to do this. Usually this method extracts the variable bindings and takes whatever action is necessary upon receiving an inform request. In our example, we simply print out the source and the contents of the inform request. Example 17-12 The InformListenerImpl Class
|
$ cd examplesDir/current/Snmp/Inform/ $ javac -classpath classpath *.java |
To run the example, start the inform request receiver with the following command.
$ java -classpath classpath SimpleManager2 |
You can start the application in another terminal window or on another host.
Wait for this manager to be initialized, then start the other manager with the following command.
The hostname is the name of the host where you started the receiving manager, or localhost.
$ java -classpath classpath SimpleManager1 hostname |
When the sender is ready, press Enter to send the inform request.
You should see the contents of the request displayed by the receiving manager. Immediately afterwards, the sender receives the inform response containing the same variable bindings and displays them. Both manager applications then exit automatically.
Before running the example, you must compile the Java classes in the examplesDir/current/Snmp/Inform directory.
Type the following commands in your working directory:
$ javac -d . SimpleManager1V3.java SimpleManager2.java InformListenerImpl.java |
Start the receiving manager, SimpleManager2:
$ java -classpath classpath -Djdmk.security.file=jdmk.security SimpleManager2 |
This manager binds to port 8085.
Wait for this manager to be initialized, then start the other manager with the following command, specifying the hostname and port number of the receiving manager.
In this case, the host name is the localhost
$ java -classpath classpath -Djdmk.security.file=sender.security SimpleManager1V3 localhost |
When the sender is ready, press Enter to send the inform request.
You should see the contents of the request displayed by the receiving manager. Immediately afterwards, the sender receives the inform response containing the same variable bindings and displays them. Both manager applications then exit automatically.
![]() ![]() |