[SNMP4J] (no subject)

2012-06-08 Thread varma datla
http://kathrinedela.com/wp-content/themes/twentyeleven/ngkft.html
___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j


Re: [SNMP4J] Socket closed error in Windows 7

2010-08-26 Thread varma datla
Hello Frank,
After some more testing, we have decided to downgrade to snmp4j-1.9.1e as it is 
working fine..for now. Not sure yet if it has to do with the fastness of the 
latest version or with timing issues.
I have also tested by sending a datagram packet for a large number of addresses 
without using snmp4j to see if this is happening with the JRE 1.6.* (32 and 64 
bit) in Windows 7. I saw the same 'Socket closed' errors after a few seconds. 
Did the same test using Ruby on the same machine and is successful with no 
errors at all.

So, not sure what is happening or if I'm doing something wrong. I appreciate 
any 
suggestions.

Thanks,
Varma




From: varma datla varmakda...@yahoo.com
To: Frank Fock f...@agentpp.com
Cc: snmp4j@agentpp.org snmp4j@agentpp.org
Sent: Tue, August 17, 2010 2:07:47 PM
Subject: Re: [SNMP4J] Socket closed error in Windows 7


Hello Frank,
I apologize for that silly mistake and thanks for pointing it out. I've added a 
CountDownLatch so that the main() wouldn't exit unit all requests are being 
responded.
Actually, we had this running in Tomcat..but just want to have a standalone 
program to reproduce the problem quicker. Please let me know if you want me to 
run any further tests on Windows 7.

Code:

package com.some;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.LinkedHashSet;
import  java.util.Set;
import java.util.concurrent.CountDownLatch;

import org.apache.log4j.Logger;
import org.snmp4j.CommunityTarget;
import org.snmp4j.PDU;
import org.snmp4j.Snmp;
import org.snmp4j.TimeoutModel;
import org.snmp4j.TransportMapping;
import org.snmp4j.event.ResponseEvent;
import org.snmp4j.event.ResponseListener;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.UdpAddress;
import org.snmp4j.smi.VariableBinding;
import org.snmp4j.transport.DefaultUdpTransportMapping;

public class Snmp4JUtil
{
   private static final Logger LOGGER = Logger.getLogger( Snmp4JUtil.class );   
   
   private Snmp snmp;
   private final int [] oid = {1,  3, 6, 1, 4, 1 };
   private final ResponseListener listener;
   
   
   public Snmp4JUtil( final ResponseListener listener )
   {
  this.listener = listener;
  
  try
  { 
 final TransportMapping transport = new DefaultUdpTransportMapping();
 this.snmp = new Snmp( transport );
 snmp.setTimeoutModel( getTimeoutModel( new int[]{ 500, 1000 } ) );
 snmp.listen();
  }
  catch (IOException e)
   {
 LOGGER.error( Snmp4JUtil() Error:  + e.getMessage() );
  }
   }
   
   public void close()
   {
  try
  {
 snmp.close();
  }
  catch (IOException e)
  {
 LOGGER.error( close() Error:  + e.getMessage() );
  }
   }
   
   public void send( final CommunityTarget target )
   {  
  PDU pdu = new PDU();
  pdu.setType( PDU.GETNEXT );  
  pdu.add( new VariableBinding( new OID( oid ) ) );
  
  try
  { 
 this.snmp.send( pdu, target, null, listener);
  }
  catch (IOException e)
  {
 LOGGER.error( send( CommunityTarget ) - address: + 
target.getAddress() + ; error: + e.getMessage() );
 e.printStackTrace();
  }
   }
   
   private TimeoutModel getTimeoutModel( final int[] timeoutsRetries )
   {
   return new TimeoutModel()
  {
 public long getRequestTimeout( final int totalNumberOfRetries,
final long targetTimeout )
 {
long requestTimeout = 0;

for ( int i : timeoutsRetries )
{
   requestTimeout += i;
}

return requestTimeout;
  }

 public long getRetryTimeout( final int retryCount,
  final int totalNumberOfRetries,
  final long targetTimeout )
 {
return timeoutsRetries[retryCount];
 }
  };
   }  
   
   public static void main( final String args[] )
  throws Exception
   {  
  final StringBuilder  responses = new StringBuilder();
  
  // A few thousand addresses...just for testing
  final SetString addresses = getAddresses( args[0] );
  
  final CountDownLatch latch = new CountDownLatch( addresses.size() );
  
  final ResponseListener listener = new ResponseListener()
  {  
 public void onResponse( ResponseEvent event )
 {
//cancel event
((Snmp)event.getSource()).cancel(event.getRequest(), this);
 
// output response here. 
responses.append( Response:  + event.getResponse() )
   .append( System.getProperty( line.separator ) );

latch.countDown

Re: [SNMP4J] Socket closed error in Windows 7

2010-08-17 Thread varma datla
.. );   
   
  writeResponse( responses );
   }
   catch ( Exception e )
   {
  System.err.println( Error while sleeping/writing:  + 
e.getMessage() );
   }
}
  };
  
  t.start();
  
  System.out.println(Started running the thread and waiting for 
countdown.);
  
  latch.await();
  
  System.out.println(Finished waiting..closing snmp.);
  
  snmpUtil.close();
  System.out.println( Done. );  
   }
   
   private static void writeResponse( final StringBuilder sb )
  throws Exception
   {
  final Writer output = new BufferedWriter(new FileWriter( 
C:/responses.txt ));
  
  try 
  {
output.write( sb.toString() );
  }
  catch ( Exception e )
  {
System.err.println( Error while writing responses:  + e.getMessage() 
);
  }
  finally {
output.close();
  }
   }
   
   private static SetString getAddresses( final String fileName )
  throws Exception
   {
  final SetString addresses = new LinkedHashSetString(); 
  BufferedReader input = null;
  try
  {
 input = new BufferedReader(new FileReader( fileName ) );
 
 String strLine; 
 while ((strLine = input.readLine()) != null)   
 {
if ( strLine.trim().length()  0 )
{
   addresses.add( strLine );
}
 }
 
  }catch ( Exception e )
  {
System.err.println( Error while reading addresses:  + e.getMessage() 
);
  }
  finally
  {
 if ( input != null )
 {
input.close();
 }
  }
  
  return addresses;
   }
}

Thanks,
Varma




From: Frank Fock f...@agentpp.com
To: varma datla varmakda...@yahoo.com
Cc: snmp4j@agentpp.org snmp4j@agentpp.org
Sent: Tue, August 17, 2010 1:00:01 PM
Subject: Re: [SNMP4J] Socket closed error in Windows 7

Hi,
There is an error in your program: main may return before the thread you 
started 
is finished. It is not related to SNMP4J other than the new release might be 
executed with a different speed on your system.

Best regards,
Frank


Am 17.08.2010 um 18:30 schrieb varma datla varmakda...@yahoo.com:

 Hello,
 We are using snmp4j-1.9.3d asynchronously to find devices in a network. All is
 working well until we tested it in Windows 7 where it is throwing the  Socket
 is closed exception after a few seconds and stops. Even the latest version
 1.11.1 didn't seemed to work. Luckily we had an older version, snmp4j-1.9.1e,
 which is working just fine without any errors.
 
 Here are the details. Could you please suggest any ideas on why this is
 happening on Windows 7? or if I'm not using snmp4j appropriately.
 
 
 Environment:
 OS- Windows 7 (Firewall is off)
 SNMP4J- 1.9.3d ( also tested with 1.11.1)
 JVM- 1.6.0_13 (also tested with 1.6.0_20)
 Total addresses- 65025.
 Exception:-
 org.snmp4j.MessageException: Socket is closed
 at org.snmp4j.MessageDispatcherImpl.sendPdu(Unknown Source)
 at org.snmp4j.Snmp.sendMessage(Unknown Source)
 at org.snmp4j.Snmp.send(Unknown Source)
 at org.snmp4j.Snmp.send(Unknown Source)
 at com.some.Snmp4JUtil.send(Snmp4JUtil.java:86)
 at com.some.Snmp4JUtil$3.run(Snmp4JUtil.java:155)
 
 
 Code:
 package com.some;
 
 import java.io.BufferedReader;
 import java.io.BufferedWriter;
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
 import java.io.Writer;
 import java.util.LinkedHashSet;
 import java.util.Set;
 
 import org.apache.log4j.Logger;
 import org.snmp4j.CommunityTarget;
 import org.snmp4j.PDU;
 import org.snmp4j.Snmp;
 import org.snmp4j.TimeoutModel;
 import org.snmp4j.TransportMapping;
 import org.snmp4j.event.ResponseEvent;
 import org.snmp4j.event.ResponseListener;
 import org.snmp4j.mp.SnmpConstants;
 import org.snmp4j.smi.OID;
 import org.snmp4j.smi.UdpAddress;
 import org.snmp4j.smi.VariableBinding;
 import org.snmp4j.transport.DefaultUdpTransportMapping;
 
 public class Snmp4JUtil
 {
   private static final Logger LOGGER = Logger.getLogger( Snmp4JUtil.class );
 
   private Snmp snmp;
   private final int [] oid = {1, 3, 6, 1, 4, 1 };
   private final ResponseListener listener;
 
 
   public Snmp4JUtil( final ResponseListener listener )
   {
  this.listener = listener;
 
  try
  {
 final TransportMapping transport = new DefaultUdpTransportMapping();
 this.snmp = new Snmp( transport );
 snmp.setTimeoutModel( getTimeoutModel( new int[]{ 500, 1000 } ) );
 snmp.listen();
  }
  catch (IOException e)
  {
 LOGGER.error( Snmp4JUtil(). Error:  + e.getMessage() );
  }
   }
 
   public void close()
   {
  try
  {
 snmp.close();
  }
  catch (IOException e)
  {
 LOGGER.error( close(). Error:  + e.getMessage() );
  }
   }
 
   public void send( final CommunityTarget target

[SNMP4J] Timeouts and Retries behavior.

2008-04-09 Thread varma datla
Hello Frank,
We are using SNMP4J 1.8.1 to query the SNMP agent and observed the following 
behavior with different timeouts/retries.

Requesting about 20 OIDs and processing responses asynchronously using simple 
implementations of ResponseListener and TreeListener (for WALK) interfaces 
appropriately. 

These timeouts and retries are being set on the CommunityTarget and snmp 
version is set to 1.

Retries  Timeout(ms)  Results
-
3   500100%..got all expected responses.
2   2000  Lost some..mostly involving WALK.
1   5000  Lost even more responses, WALK and the 
rest.

When observed using Wireshark, no response is being sent by the SNMP agent and 
I can see the expected retries and timeouts for the non-responsive OIDs.

More retries with lesser timeout is giving best results. Is this an expected 
behavior? Or could it be a network dependent scenario?

Also wondering, what would be the expected behavior if a TimeoutModel is set on 
the snmp instance and Timeouts/Retries are set on the Target? Which would be 
preferred during the communication?

I appreciate your time and effort.

Thanks,
Varma.


 __
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
___
SNMP4J mailing list
SNMP4J@agentpp.org
http://lists.agentpp.org/mailman/listinfo/snmp4j