To use your custom PDU factory in your SNMP agent, you need to call the usePduFactory method of your SnmpAdaptorServer instance. First instantiate your PDU factory implementation and then pass it to this method. Your encoding and decoding scheme will then replace the standard one used by the SNMP protocol adaptor.
The SecureAgent.java file contains a simple agent like the one presented in "The SNMP Protocol Adaptor". It only adds the call to force the SNMP adaptor to use the new PDU factory that we specify.
// Use SnmpPduFactoryImpl class for SnmpPduFactory to filter requests. // Enter your list of refused hosts as arguments when launching this agent. // The agent will reject requests coming from the specified hosts. // String[] refusedHosts = new String[args.length]; refusedHosts = args; snmpAdaptor.usePduFactory(new SnmpPduFactoryImpl(refusedHosts)); |
The SNMP adaptor will then use this PDU factory to filter incoming requests based on their originating host. It will also encode all outgoing messages, including any traps that are sent, though it does nothing more than standard BER encoding. The secure agent example does not demonstrate traps, and the LinkTrapGenerator class is not written to function with the SecureAgent class. However, the SnmpPduFactoryImpl could be used as it is shown above in the SNMP Agent example.