[SNMP4J] problem with V3

ragavendra annakula a_ragavendra at hotmail.com
Thu Mar 27 09:50:24 CET 2008


My Application using SNMP4J API to give response for snmp v3 requests. I have given the following netsnmp command from my linux box. snmpget -v 3 -a MD5 -A 'hello1234'  -l authPriv  -u 'snmpuser1' -x DES -X hello1234 annra01-xp1 1.3.6.1.2.1.2.2.1.2.1 -t 30 -d   My Agent application is responding to snmp request and it is sending the response but NetSNMP Get command unable to decode the message.
 
I also attaching netsnmp output.
  class MySNMPResponse extends Thread implements CommandResponder {public MySNMPResponse(){try {udpAddress = new UdpAddress('0.0.0.0/161');TransportMapping transport = new DefaultUdpTransportMapping(udpAddress); snmp = new Snmp(transport);localEngineID =((MPv3)snmp.getMessageProcessingModel(MessageProcessingModel.MPv3)).createLocalEngineID();USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(localEngineID), 0);SecurityModels.getInstance().addSecurityModel(usm);snmp.getUSM().addUser(new OctetString('snmpuser1'),new UsmUser(new OctetString('snmpuser1'),AuthMD5.ID, new OctetString('hello1234'),PrivDES.ID, new OctetString('hello1234')));snmp.setLocalEngine(localEngineID, 0, 0);snmp.addCommandResponder(this);transport.listen();start();}catch(Exception e){e.printStackTrace();}}//MySNMPResponse() public void run(){//infinite loopwhile(1);}//Run()  public synchronized void processPdu(CommandResponderEvent e) {System.out.println('in ProcessPDU');//System.out.println(e.getSecurityLevel());/*Creating Target Object*/PDU pdu = e.getPDU();TransportMapping tm = e.getTransportMapping();if(pdu != null ) {int snmpVersion = e.getMessageProcessingModel();PDU responsePDU = null;Target target = null;if(snmpVersion == MessageProcessingModel.MPv1 || snmpVersion == MessageProcessingModel.MPv2c ||snmpVersion == MessageProcessingModel.MPv2u){ //Create an object of CommunityTarget and assing to target//Create an object of PDU and assign to responsePDU}else if(snmpVersion == MessageProcessingModel.MPv3){UserTarget userTarget = new UserTarget();userTarget.setAddress((UdpAddress) e.getPeerAddress());userTarget.setRetries(1);// set timeout to 500 milliseconds -> 2*500ms = 1s total timeoutuserTarget.setTimeout(500);userTarget.setVersion(SnmpConstants.version3);System.out.println(e.getSecurityLevel());System.out.println(new OctetString(e.getSecurityName()));userTarget.setSecurityLevel(e.getSecurityLevel());userTarget.setSecurityName(new OctetString(e.getSecurityName()));ScopedPDU scopedPDU = new ScopedPDU();scopedPDU.setContextName(new OctetString('snmpuser1'));scopedPDU.setContextEngineID(new OctetString('123456789123456789'));responsePDU = scopedPDU;target = userTarget;}}try{ //Setting Response Packet AttributesresponsePDU.setRequestID(new Integer32(pdu.getRequestID().getValue())); responsePDU.setType(PDU.RESPONSE);responsePDU.setErrorStatus(PDU.noError);responsePDU.setErrorIndex(0); // NO ERRORVector variableBindings = pdu.getVariableBindings();for(int index = 0;index < variableBindings.size();index++){Variable value = null;VariableBinding var = (VariableBinding)variableBindings.get(index);OID oid = var.getOid();VariableBinding vbObj = new VariableBinding(oid,new Integer32(4));responsePDU.add(vbObj);}snmp.send(responsePDU, target, tm);}catch(Exception e){e.printStackTrace();}}//ProcessPDUpublic void main(String s[]){MySNMPResponse resObj = new MySNMPResponse();}//main}//MySnmpResponse I would appreciate if you provide any inputs to solve porblem. Thanks in advance,Ragavendra.
_________________________________________________________________
Video: Get a glimpse of the latest in Cricket, Bollywood, News and Fashion. Only on MSN videos.
http://video.msn.com/?mkt=en-in
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: netsnmp.txt
URL: <http://oosnmp.net/pipermail/snmp4j/attachments/20080327/18a03ff4/attachment.txt>


More information about the SNMP4J mailing list