[SNMP4J] reg: USM and MPV3

Tomasz Kaczmarek losmotylos at gmail.com
Tue Apr 20 22:40:50 CEST 2010


Frank,
I have the similar problem. I'm using snmp4j 1.11
I'm using one MPV3 and USM. Snmp4j is utilized in tomcat6 container.
Everything is working pretty fine for only one remote device. I have a
problem with talking via snmp to 2 network devices. My configuration
is the same name but different passwords.
I'm getting an exception:
org.snmp4j.Message Exception: "Message processing model 3 returned
error: Unknown security name"
I've debugged that engineId discovery succeed and and user is added to
USM's user's table before send operation.

Thanks,
Tomek

Here is my code (This is a part of bigger one. I've just cut a part
responsible for communication with one snmp device):
------------------------------------------------
OctetString localEngineID = new OctetString(MPv3.createLocalEngineID());
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
SecurityModels.getInstance().addSecurityModel(usm);

TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();

Snmp snmp = new Snmp(transport);
((MPv3) snmp.getMessageProcessingModel(MPv3.ID)).setLocalEngineID(localEngineID.getValue());
snmp.listen();

UserTarget target = fillTarget(new UserTarget(), agent);
target.setVersion(SnmpConstants.version3);
//target.setSecurityLevel(securityLevel);
target.setSecurityLevel(((UserBasedModel)
agent.getSecurityModel()).getSecurityLevel());

UsmUser user = Snmp4JTranslator.to(((UserBasedModel)
agent.getSecurityModel()).getUser());
target.setSecurityName(user.getSecurityName());

byte[] engineIdDisc = null;
if (((MPv3) snmp.getMessageProcessingModel(MPv3.ID)).getEngineID(target.getAddress())
== null) {
 usm.setEngineDiscoveryEnabled(true);
 engineIdDisc =
snmp.discoverAuthoritativeEngineID(target.getAddress(),
target.getTimeout());
} else {
 engineIdDisc = ((MPv3)
snmp.getMessageProcessingModel(MPv3.ID)).getEngineID(target.getAddress()).toByteArray();
}

if(engineIdDisc != null) {
 target.setAuthoritativeEngineID(engineIdDisc);
 usm.addUser(new OctetString(user.getSecurityName()), new
OctetString(engineIdDisc), user);
} else {
 throw new SessionTimeoutException("Timeout exception");
}

try {
   return snmp.send(pdu, target);
} catch (IOException ex) {
 ....
}
------------------------------------------------



More information about the SNMP4J mailing list