I am trying to test SNMP4J Manager to basic SNMP4J agent.
Been successful at returning variable bindings in PDU response for SET command issued to agent.
However, when using TableUtils.getTable()
I don’t see any variable bindings (columns) in retured TableEvent
.
Instead I see the response variable bindings in TableEvent.source.rowCache.
I do have another SNMP agent (Proprietary code) to point to that is sending back the variable bindings in the the TableEvent.
Is there special handling required to return the variable bindings for the GETBULK PDU in my SimpleSnmpAgent class.
SimpleSnmpAgent.java snip:
public SimpleSnmpAgent() {
snmp = new Snmp();
snmp.getMessageDispatcher().addCommandResponder(new CommandResponder() {
@Override
public void processPdu(CommandResponderEvent event) {
System.out.println("Incoming Event = " + event);
ScopedPDU responsePDU = (ScopedPDU) event.getPDU();
responsePDU.setType(PDU.RESPONSE);
responsePDU.setErrorStatus(PDU.noError);
responsePDU.setErrorIndex(0);
// FIXME On client side, the binding are showing up in event.source.rowCache,
// but not in TableEvent.getColumns()
for (VariableBinding binding : responsePDU.getVariableBindings()) {
System.out.println("Incoming VariableBinding = " + binding);
Variable variable = new OctetString("HELLO");
binding.setVariable(variable);
System.out.println("Outgoing VariableBinding = " + binding);
}
StatusInformation statusInformation =new StatusInformation();
event.setProcessed(true);
try {
event.getMessageDispatcher().returnResponsePdu(event.getMessageProcessingModel(),
event.getSecurityModel(),
event.getSecurityName(),
event.getSecurityLevel(),
responsePDU,
event.getMaxSizeResponsePDU(),
event.getStateReference(),
statusInformation);
} catch (MessageException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
try {
transportMapping = new DefaultUdpTransportMapping(new UdpAddress(161));
snmp.addTransportMapping(transportMapping);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());
SecurityProtocols.getInstance().addDefaultProtocols();
OctetString localEngineID = new OctetString(MPv3.createLocalEngineID());
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
usm.setEngineDiscoveryEnabled(true);
SecurityModels.getInstance().addSecurityModel(usm);
UsmUser user = new UsmUser(new OctetString(SMNP_USER), AuthSHA.ID,
new OctetString(SMNP_AUTH_PASSWORD), PrivAES128.ID, new OctetString(SMNP_PRIV_PASSWORD));
usm.addUser(new OctetString(SMNP_USER), user);
snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3(usm.getLocalEngineID().getValue()));
}