unable to decode message

Padala <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
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.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.