shradha upadhyay

HCP SNMP V3 support with SNMP4J

Discussion created by shradha upadhyay on Apr 20, 2016

I am using SNMP4J to connect to snmp agent on HCP simulator I have , I can do  get,walk etc fine with SNMPv2.

When I change the version on snmp agent running on simulator to V3  via https://<ipaddress>:8000/cluster/snmp_input.action  , I get Unsupported securityModel error. Below is code snippet using snmp4j. Please advice.

 

USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);

SecurityModels.getInstance().addSecurityModel(usm);

OctetString octetUserId = new OctetString(userId);

OctetString octetPassword = new OctetString(password);

 

//create different security level user

UsmUser authPrivUsernew UsmUser(octetUserId,AuthMD5.ID,octetPassword, PrivDES.ID,octetPassword);

UsmUser authNoPrivUsernew UsmUser(octetUserId,AuthMD5.ID,octetPassword,  null,null);

UsmUser noAuthNoPrivUser = new UsmUser(octetUserId, null, null,null, null);

 

usm.addUser(noAuthNoPrivUser.getSecurityName(), noAuthNoPrivUser);

this.snmp = new Snmp(new DefaultUdpTransportMapping());

  communityString = "public";

UdpAddress address = new UdpAddress(serverAddress + "/" + port);

address.setPort(port);

target = new CommunityTarget();

target.setCommunity(new OctetString(communityString));

target.setVersion(SnmpConstants.version3);

target.setAddress(address);

target.setTimeout(1000);

target.setRetries(5);

snmp.listen();

snmp.getUSM().addUser(noAuthNoPrivUser);

target.setSecurityLevel(SecurityLevel.NOAUTH_NOPRIV);

target.setVersion(3);

target.setSecurityName(usmUser.getSecurityName());

PDU pdu = new ScopedPDU();

pdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0")));

pdu.setType(PDU.GET);

// send the PDU
ResponseEvent response = snmp.send(pdu, target);

Outcomes