[AGENT++] unable to decode message

Frank Fock fock at agentpp.com
Fri Mar 28 21:13:40 CET 2008


Hi,

Please use the SNMP4J mailing list for questions about SNMP4J.
Why are you using SNMP4J to build a command responder application
instead of SNMP4J-Agent?

Please read the SNMPv3 RFCs carefully - especially about engine
IDs. Then check your code again and also read the SNMP4J JavaDoc
(i.e., about timeout handling).

Best regards,
Frank

Padala wrote:
> Hi All
>    
>   My Application using SNMP4J API  is 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 loop
> 
>   while(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 timeout
> 
>   userTarget.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 Attributes
> 
>   responsePDU.setRequestID(new Integer32(pdu.getRequestID().getValue())); 
> 
>   responsePDU.setType(PDU.RESPONSE);
> 
>   responsePDU.setErrorStatus(PDU.noError);
> 
>   responsePDU.setErrorIndex(0); // NO ERROR
>    
>   Vector 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();
> 
>   }
>    
>   }//ProcessPDU
> 
>   public void main(String s[])
> 
>   {
> 
>   MySNMPResponse resObj = new MySNMPResponse();
> 
>   }//main
> 
>   }//MySnmpResponse
> 
>    
> 
>   I would appreciate if you provide any inputs to solve porblem.
> 
>    
> 
>   Thanks in advance,
>   
>  Sai
> 
>        
> ---------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile.  Try it now.
> _______________________________________________
> AGENTPP mailing list
> AGENTPP at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/agentpp

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com



More information about the AGENTPP mailing list