[SNMP4J] Code hangs on syncResponse.wait();

Oosten, Harry van harry.van.oosten at logica.com
Mon Aug 11 08:53:29 CEST 2008


I use 1.8.2.
I've callec Snmp.listen() and it only happens when I use a wrong
password or username. The request is then ignored by the agent and the
code is hanging on syncResponse.wait(); When I debug. 


Met vriendelijke groet / Kind Regards,

ing. Harry van Oosten

Software engineer
_________________________________________


Logica Nederland B.V.
Registered office in Amstelveen, The Netherlands
Registration Number Chamber of Commerce: 33136004

-----Original Message-----
From: Frank Fock [mailto:fock at agentpp.com] 
Sent: zondag 10 augustus 2008 13:47
To: Oosten, Harry van
Cc: snmp4j at agentpp.org
Subject: Re: [SNMP4J] Code hangs on syncResponse.wait();

Harry,

That's all you need to do. What SNMP4J version
are you using? Have you called Snmp.listen()
before sending the request?

Best regards,
Frank

Oosten, Harry van wrote:
> Frank, 
> 
> I've set the time out of the target to 5000 ms. 
> But on the scopedPDU I create for the request message I can't set any
> timeout. How do I set the time out off the request message?
> 
> 
> Met vriendelijke groet / Kind Regards,
> 
> ing. Harry van Oosten
> 
> Software engineer
> _________________________________________
> 
> 
> -----Original Message-----
> From: Frank Fock [mailto:fock at agentpp.com] 
> Sent: woensdag 6 augustus 2008 13:58
> To: Oosten, Harry van
> Cc: snmp4j at agentpp.org
> Subject: Re: [SNMP4J] Code hangs on syncResponse.wait();
> 
> I have not read your code, but in general
> this is handled by the timeout value of the
> request. Try to decrease the value. The
> wait() is OK. The timeout is handled
> elsewhere.
> 
> Best regards,
> Frank
> 
> Oosten, Harry van schrieb:
>> Anybody got an idea? I don't understands why the code hangs on the
> wait
>> as the request is being ignored. Could it help to set .the
>> syncResponse.wait(); with an timeout value of 10 seconds or is there
>> more time needed for the agent to response? 
>>
>> Thanks.
>>
>> Met vriendelijke groet / Kind Regards,
>>
>> ing. Harry van Oosten
>>
>> Software engineer
>>
>>
>> -----Original Message-----
>> From: snmp4j-bounces at agentpp.org [mailto:snmp4j-bounces at agentpp.org]
> On
>> Behalf Of Oosten, Harry van
>> Sent: dinsdag 5 augustus 2008 10:08
>> To: snmp4j at agentpp.org
>> Subject: [SNMP4J] Code hangs on syncResponse.wait();
>>
>> Hi,
>>
>>  
>>
>> I managed to create an test class that's send a GETBULK request to an
>> configured switch and router. This goes well as long as I use the
> right
>> username password. 
>>
>>  
>>
>> Only when I change a username or password the request is ignored by
> the
>> device and the code hangs on the syncResponse.wait(); 
>>
>>  
>>
>>  
>>
>> MyCode:
>>
>>  
>>
>> public class SNMPManager {
>>
>>    
>>
>>     private boolean needConfig = false;
>>
>>    
>>
>>     public static void main(String[] args) {
>>
>>         SNMPManager snmpMan = new SNMPManager();
>>
>>         System.out.println("Switch = up?
>> "+snmpMan.isResponding("192.168.16.122", "1AuthUser", "AuthPassword",
>> null)); //wrong username
>>
>>         System.out.println(snmpMan.needConfig);
>>
>>     }
>>
>>     public boolean isResponding(String ipAddress, String userName,
>> String authPassword, String privPassword){
>>
>>     List<String> OIDList = new LinkedList<String>();
>>
>>     //OIDList.add("");
>>
>>       PDU pdu;
>>
>>         try {
>>
>>             pdu = getPDU(ipAddress, userName, authPassword,
> privPassword
>> ,OIDList);
>>
>>             if (pdu != null)  {
>>
>>                     System.out.println(pdu);
>>
>>                     return true;      
>>
>>             } else{
>>
>>                 return false;
>>
>>             }
>>
>>         } catch (IOException e) {
>>
>>             e.printStackTrace();
>>
>>             needConfig = true;
>>
>>             return false;
>>
>>         }
>>
>>     }
>>
>>     
>>
>>     private PDU getPDU(String ipAddress, String userName, String
>> authPassword, String privPassword ,List<String> OIDList) throws
>> IOException {
>>
>>         //Create transport.
>>
>>         Address targetAddress =
>> GenericAddress.parse("udp:"+ipAddress+"/161");
>>
>>         TransportMapping transport = new
DefaultUdpTransportMapping();
>>
>>         Snmp snmp = new Snmp(transport);
>>
>>         
>>
>>         USM usm = new USM(SecurityProtocols.getInstance(), new
>> OctetString(MPv3.createLocalEngineID()),0);
>>
>>         SecurityModels.getInstance().addSecurityModel(usm);
>>
>>         transport.listen();
>>
>>         
>>
>>         // add user to the USM
>>
>>         if (privPassword != null)  {
>>
>>             snmp.getUSM().addUser(new OctetString(userName), 
>>
>>                                   //new
>> OctetString("80:00:13:70:c0:a8:01:0d"), 
>>
>>                                   new UsmUser(new
> OctetString(userName),
>>
>>                                               AuthMD5.ID, 
>>
>>                                               new
>> OctetString(authPassword),
>>
>>                                               PrivDES.ID,
>>
>>                                               new
>> OctetString(privPassword)
>>
>>                                               )); //Fill out!  
>>
>>         } else {
>>
>>             snmp.getUSM().addUser(new OctetString(userName), 
>>
>>                                //new
>> OctetString("80:00:13:70:c0:a8:01:0d"), 
>>
>>                                new UsmUser(new OctetString(userName),

>>
>>                                            AuthMD5.ID, 
>>
>>                                            new
>> OctetString(authPassword),
>>
>>                                            null,
>>
>>                                            null)); 
>>
>>         }
>>
>>         
>>
>>         //Create target.
>>
>>         UserTarget target = createTarget(targetAddress, userName);
>>
>>         
>>
>>         //Create the PDU
>>
>>         PDU pdu = createPDU(OIDList);
>>
>>         
>>
>>         //Send the PDU
>>
>>         ResponseEvent responseEvent = snmp.send(pdu, target);
>>
>>         //Exctract the response PDU (could be null if timed out)
>>
>>         PDU responsePDU = responseEvent.getResponse();
>>
>>         closeTransport(transport);
>>
>>         return responsePDU;
>>
>>     }
>>
>>  
>>
>>     /**
>>
>>      * Used to create the PDU. 
>>
>>      * Gets a list of Strings containing the OID's that needs to be
>> acquired.
>>
>>      * @param OIDList String List
>>
>>      * @return PDU
>>
>>      */
>>
>>     private PDU createPDU(List<String> OIDList) {
>>
>>         PDU pdu = new ScopedPDU();
>>
>>         for (String oid :OIDList ) {
>>
>>             pdu.add(new VariableBinding(new OID(oid)));
>>
>>         }
>>
>>         pdu.setType(PDU.GETBULK);
>>
>>         return pdu;
>>
>>     }
>>
>>  
>>
>>     private UserTarget createTarget(Address targetAddress, String
>> userName) {
>>
>>         UserTarget target = new UserTarget();
>>
>>         target.setAddress(targetAddress);
>>
>>         target.setRetries(0);
>>
>>         target.setTimeout(5000);
>>
>>         target.setVersion(SnmpConstants.version3);
>>
>>         target.setSecurityLevel(SecurityLevel.AUTH_NOPRIV);
>>
>>         target.setSecurityName(new OctetString(userName));
>>
>>         return target;
>>
>>     }
>>
>>  
>>
>>     private void closeTransport(TransportMapping transport) throws
>> IOException {
>>
>>             transport.close();
>>
>>     }
>>
>> }
>>
>>  
>>
>> Where it goes wrong: (snmp.java)
>>
>>  
>>
>> public ResponseEvent send(PDU pdu, Target target,
>>
>>                             TransportMapping transport) throws
>> IOException {
>>
>>     if (!pdu.isConfirmedPdu()) {
>>
>>       sendMessage(pdu, target, transport, null);
>>
>>       return null;
>>
>>     }
>>
>>     if (timer == null) {
>>
>>       createPendingTimer();
>>
>>     }
>>
>>     SyncResponseListener syncResponse = new SyncResponseListener();
>>
>>     PendingRequest retryRequest = null;
>>
>>     synchronized (syncResponse) {
>>
>>       PduHandle handle = null;
>>
>>       PendingRequest request =
>>
>>           new PendingRequest(syncResponse, target, pdu, target,
>> transport);
>>
>>       handle = sendMessage(pdu, target, transport, request);
>>
>>       try {
>>
>>         syncResponse.wait();
>>
>>         retryRequest = (PendingRequest)
> pendingRequests.remove(handle);
>>         if (logger.isDebugEnabled()) {
>>
>>           logger.debug("Removed pending request with handle:
> "+handle);
>>         }
>>
>>         request.setFinished();
>>
>>         request.cancel();
>>
>>       }
>>
>>       catch (InterruptedException iex) {
>>
>>         logger.warn(iex);
>>
>>         // ignore
>>
>>       }
>>
>>     }
>>
>>     if (retryRequest != null) {
>>
>>       retryRequest.setFinished();
>>
>>       retryRequest.cancel();
>>
>>     }
>>
>>     return syncResponse.response;
>>
>>   }
>>
>>  
>>
>>   private synchronized void createPendingTimer() {
>>
>>     if (timer == null) {
>>
>>       timer = SNMP4JSettings.getTimerFactory().createTimer();
>>
>>     }
>>
>>   }
>>
>>  
>>
>> Hope you can help! 
>>
>>  
>>
>>  
>>
>> Met vriendelijke groet / Kind Regards,
>>
>>  
>>
>> ing. Harry van Oosten
>>
>>  
>>
>> Software engineer
>>
>> _________________________________________
>>
>>  
>>
>>
>>
>>
>>
>>  
>>
>>
>>
>> This e-mail and any attachment is for authorised use by the intended
>> recipient(s) only. It may contain proprietary material, confidential
>> information and/or be subject to legal privilege. It should not be
>> copied, disclosed to, retained or used by, any other party. If you
are
>> not an intended recipient then please promptly delete this e-mail and
>> any attachment and all copies and inform the sender. Thank you.
>>
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>>
>>
>> This e-mail and any attachment is for authorised use by the intended
> recipient(s) only. It may contain proprietary material, confidential
> information and/or be subject to legal privilege. It should not be
> copied, disclosed to, retained or used by, any other party. If you are
> not an intended recipient then please promptly delete this e-mail and
> any attachment and all copies and inform the sender. Thank you.
>>
>> _______________________________________________
>> SNMP4J mailing list
>> SNMP4J at agentpp.org
>> http://lists.agentpp.org/mailman/listinfo/snmp4j
>>   
> 
> 
> 
> This e-mail and any attachment is for authorised use by the intended
recipient(s) only. It may contain proprietary material, confidential
information and/or be subject to legal privilege. It should not be
copied, disclosed to, retained or used by, any other party. If you are
not an intended recipient then please promptly delete this e-mail and
any attachment and all copies and inform the sender. Thank you.
> 
> 

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



This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you.





More information about the SNMP4J mailing list