forked from I2P_Developers/i2p.i2p
improve UDP test
This commit is contained in:
@ -3,13 +3,13 @@ package net.i2p.router.transport.udp;
|
|||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.i2p.data.ByteArray;
|
import net.i2p.data.ByteArray;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
import net.i2p.util.ConcurrentHashSet;
|
||||||
import net.i2p.util.I2PThread;
|
import net.i2p.util.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
|
||||||
@ -24,12 +24,12 @@ public class UDPEndpointTestStandalone {
|
|||||||
private final Log _log;
|
private final Log _log;
|
||||||
private UDPEndpoint _endpoints[];
|
private UDPEndpoint _endpoints[];
|
||||||
private volatile boolean _beginTest;
|
private volatile boolean _beginTest;
|
||||||
private final List<ByteArray> _sentNotReceived;
|
private final Set<ByteArray> _sentNotReceived;
|
||||||
|
|
||||||
public UDPEndpointTestStandalone(RouterContext ctx) {
|
public UDPEndpointTestStandalone(RouterContext ctx) {
|
||||||
_context = ctx;
|
_context = ctx;
|
||||||
_log = ctx.logManager().getLog(UDPEndpointTestStandalone.class);
|
_log = ctx.logManager().getLog(UDPEndpointTestStandalone.class);
|
||||||
_sentNotReceived = Collections.synchronizedList(new ArrayList<ByteArray>(1000));
|
_sentNotReceived = new ConcurrentHashSet<ByteArray>(128);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runTest(int numPeers) {
|
public void runTest(int numPeers) {
|
||||||
@ -107,9 +107,12 @@ public class UDPEndpointTestStandalone {
|
|||||||
_log.error("die", uhe);
|
_log.error("die", uhe);
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
int MIN = 1 + UDPPacket.MAC_SIZE + UDPPacket.IV_SIZE;
|
||||||
|
int MAX = PeerState.LARGE_MTU - PacketBuilder.IP_HEADER_SIZE;
|
||||||
_log.debug("Beginning to write");
|
_log.debug("Beginning to write");
|
||||||
for (int curPacket = 0; curPacket < 2000; curPacket++) {
|
for (int curPacket = 0; curPacket < 2000; curPacket++) {
|
||||||
byte data[] = new byte[1024];
|
int sz = MIN + _context.random().nextInt(MAX - MIN - 1);
|
||||||
|
byte data[] = new byte[sz];
|
||||||
_context.random().nextBytes(data);
|
_context.random().nextBytes(data);
|
||||||
int curPeer = (curPacket % _endpoints.length);
|
int curPeer = (curPacket % _endpoints.length);
|
||||||
if (_endpoints[curPeer] == _endpoint)
|
if (_endpoints[curPeer] == _endpoint)
|
||||||
@ -117,22 +120,35 @@ public class UDPEndpointTestStandalone {
|
|||||||
if (curPeer >= _endpoints.length)
|
if (curPeer >= _endpoints.length)
|
||||||
curPeer = 0;
|
curPeer = 0;
|
||||||
UDPPacket packet = builder.buildPacket(data, localhost, _endpoints[curPeer].getListenPort());
|
UDPPacket packet = builder.buildPacket(data, localhost, _endpoints[curPeer].getListenPort());
|
||||||
int outstanding = _sentNotReceived.size() + 1;
|
int outstanding = _sentNotReceived.size() + 1;
|
||||||
_sentNotReceived.add(new ByteArray(data, 0, 1024));
|
_sentNotReceived.add(new ByteArray(data));
|
||||||
_log.debug("Sending packet " + curPacket + " with outstanding " + outstanding);
|
_log.debug("Sending packet " + curPacket + " with " + sz + " byte payload, outstanding " + outstanding);
|
||||||
try {
|
try {
|
||||||
_endpoint.send(packet);
|
_endpoint.send(packet);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
_log.error("die", e);
|
_log.error("die", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
try { Thread.sleep(3); } catch (InterruptedException ie) {}
|
int batch = 32 + _context.random().nextInt(32);
|
||||||
|
if (curPacket % batch == 0 || _sentNotReceived.size() > 100) {
|
||||||
|
try { Thread.sleep(3); } catch (InterruptedException ie) {}
|
||||||
|
}
|
||||||
//if (_log.shouldLog(Log.DEBUG))
|
//if (_log.shouldLog(Log.DEBUG))
|
||||||
// _log.debug("Sent to " + _endpoints[curPeer].getListenPort() + " from " + _endpoint.getListenPort());
|
// _log.debug("Sent to " + _endpoints[curPeer].getListenPort() + " from " + _endpoint.getListenPort());
|
||||||
}
|
}
|
||||||
_log.debug("Done sending packets");
|
_log.debug("Done sending packets");
|
||||||
try { Thread.sleep(10*1000); } catch (InterruptedException e) {}
|
for (int i = 0; i < 20; i++) {
|
||||||
System.exit(0);
|
if (_sentNotReceived.isEmpty())
|
||||||
|
break;
|
||||||
|
try { Thread.sleep(500); } catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
if (_sentNotReceived.isEmpty()) {
|
||||||
|
_log.info("Test passed");
|
||||||
|
System.exit(0);
|
||||||
|
} else {
|
||||||
|
_log.error("Test failed, " + _sentNotReceived.size() + " not received");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user