[SNMP4J] Strange problem with multithreaded SNMPv3-Scan
chk-world at gmx.de
chk-world at gmx.de
Tue Nov 9 11:56:45 CET 2004
In-Reply-To=24557.1099935606 at www13.gmx.net
Hi Frank and Mathias,
thanks for your reply to my question. I tried to set the tcp and udp buffer
size and file-max value to the following on my linux system:
sysctl -w net.core.wmem_max=524287 (was 128k)
sysctl -w net.core.rmem_max=524287 (was 128k)
sysctl -w net.core.wmem_default=524287 (was 64k)
sysctl -w net.core.rmem_default=524287 (was 64k)
sysctl -w net.core.optmem_max=20480 (was 10k)
fs.file-max = 91750 (was that high allready)
This doesn't change anything. Also setting to low values doesn't brought
more errors.
> As Mathias already pointed out, increasing the UDP buffer size on your
> system may help. Without knowing more about your request sending
> code, it is hard to help more specific.
I attached an example at the end of this message.
If I run more than 4 Threads at the same time I get response = null back
when doing response=snmp.sendPDU(request, uTarget) from agents who answer
correctly if using only 4 Threads.
When playing with some timeout values sometimes I get:
org.snmp4j.MessageException: Message processing model 3 returned error:
-1402
Best regards and thanks,
Chris
PS: I'm using a webmailer, so the In-Reply-To doens't get set in the mail,
sorry for that.
----------------------------
import java.io.IOException;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.snmp4j.*;
import EDU.oswego.cs.dl.util.concurrent.LinkedQueue;
import EDU.oswego.cs.dl.util.concurrent.PooledExecutor;
public class SNMPv3DeviceDiscovery
{
private class RunnableSender implements Runnable
{
public static final int DEFAULT = 0;
String ipAddress = null;
OID authProtocol;
OID privProtocol;
OctetString privPassphrase;
OctetString authPassphrase;
OctetString authoritativeEngineID;
OctetString contextEngineID;
OctetString contextName = new OctetString();
OctetString securityName = new OctetString();
int version = SnmpConstants.version3;
int retries = 1;
int timeout = 1500;
int pduType = PDU.GET;
VariableBinding variableBinding;
int operation = DEFAULT;
Snmp snmp;
USM usm = null;
PDU response = null;
PDU request = null;
UserTarget uTarget;
/* unchanged from SnmpRequest from
org/snmp4j/tools/console/SnmpRequest.java */
private void printVariableBindings(PDU response) {...}
private void printReport(PDU response) {...}
private RunnableSender(String ipAddress)
{
this.ipAddress = ipAddress;
variableBinding = new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"));
authProtocol = AuthMD5.ID;
securityName = new OctetString("user");
authPassphrase = new OctetString("authPwd");
privPassphrase = new OctetString("privPwd");
version = SnmpConstants.version3;
privProtocol = PrivDES.ID;
uTarget = new UserTarget();
uTarget.setSecurityLevel(SecurityLevel.AUTH_PRIV);
uTarget.setSecurityName(securityName);
uTarget.setVersion(version);
uTarget.setRetries(retries);
uTarget.setTimeout(timeout);
uTarget.setAddress(new UdpAddress(ipAddress + "/161"));
request = new ScopedPDU();
request.setType(pduType);
request.add(variableBinding);
}
public void run()
{
try
{
DefaultUdpTransportMapping dutm = new DefaultUdpTransportMapping();
dutm.setAsyncMsgProcessingSupported(false);
TransportMapping transport = dutm;
snmp = new Snmp(transport);
usm = new USM(SecurityProtocols.getInstance(), new
OctetString(((MPv3) snmp
.getMessageProcessingModel(MessageProcessingModel.MPv3)).createLocalEngineID()),
0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.getUSM().addUser(securityName,
new UsmUser(securityName, authProtocol, authPassphrase,
privProtocol, privPassphrase));
snmp.listen();
} catch (IOException e1)
{
e1.printStackTrace();
}
try
{
response = snmp.sendPDU(request, uTarget);
} catch (IOException e)
{
e.printStackTrace();
} // catch
if (response == null)
{
System.out.print("host: " + ipAddress + " --- ");
System.out.println("Request timed out.");
} else if (response.getType() == PDU.REPORT)
{
System.out.print("host: " + ipAddress + " --- ");
printReport(response);
} else
{
System.out.println("Response received with requestID=" +
response.getRequestID() + ", errorIndex="
+ response.getErrorIndex() + ", " + "errorStatus=" +
response.getErrorStatus());
System.out.print("host: " + ipAddress + " --- ");
printVariableBindings(response);
} // if response
close();
} // run
public void close() {
try {
SecurityModels.getInstance().removeSecurityModel(new
Integer32(usm.getID()));
usm = null;
snmp.close();
} catch (IOException e2) {
e2.printStackTrace();
}
}
} // RunnableSender
public void ipLoop() throws InterruptedException
{
// the second parameter is the maxPoolSize, if this value (and the
// minPoolSize are bigger than 4 I get timeouts.
PooledExecutor pooledExecutor = new PooledExecutor(new LinkedQueue(), 4);
pooledExecutor.setMinimumPoolSize(4);
for (int i = 1; i < 10; i++)
{
pooledExecutor.execute(new RunnableSender("10.137.1." +
Integer.toString(i)));
}//for
}//ipLoop
public static void main(String[] args) throws InterruptedException{
Logger.getRootLogger().setLevel(Level.OFF);
CounterSupport.getInstance().addCounterListener(new
DefaultCounterListener());
SNMPv3DeviceDiscovery snmpRequest = new SNMPv3DeviceDiscovery();
snmpRequest.ipLoop();
Thread.sleep(20000);
System.exit(0);
}
}
--
NEU +++ DSL Komplett von GMX +++ http://www.gmx.net/de/go/dsl
GMX DSL-Netzanschluss + Tarif zum supergünstigen Komplett-Preis!
More information about the SNMP4J
mailing list