[AGENT++] unable to decode message

Padala padala456 at yahoo.com
Wed Apr 2 09:56:42 CEST 2008


Dear Frank and all
   
  First...........using snmp4j API
   
  I am using xml file (which is recorded from a real agent) as my MIB.SoIt is a virtual MIB. I have written a program to read oids and values from XML file and store them into hashmap. When a request is received from the manager then my agent gets corresponding oid value from hashmap and forwards it to the manager. 
   
  My agent can give response to both snmpv1 and snmpv2 commands but not to the snmpv3 commands.
  
Could you please help me in this regard? I do not know where I am making mistake.
  
Next................... using snmp4jagent api
   
  Can I use this  snmp4j-agent api for the above application?  It should be able to read hashmap and get oid values from hashmap and forward it to the manager.
  
I have gone through  ifMib.java file. It seems I can not use xml file and furthermore I need to use MIB compiler.I need to use xml file as my MIB. Please give me suggestion.
   
   
   
  I would appreciate your help in this regard. 
   
  Thanks in advace.
   
  Sai

Frank Fock <fock at agentpp.com> wrote:
  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


       
---------------------------------
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.


More information about the AGENTPP mailing list