Make client/server options mutually exclusive.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
dd011c9f36
commit
0f5ee37933
|
@ -1,3 +1,3 @@
|
|||
projectId = jperf
|
||||
projectGroup = biz.nellemann.jperf
|
||||
projectVersion = 0.0.2
|
||||
projectVersion = 0.0.3
|
||||
|
|
|
@ -20,20 +20,24 @@ public class Application implements Callable<Integer> {
|
|||
final Logger log = LoggerFactory.getLogger(Application.class);
|
||||
|
||||
|
||||
@CommandLine.Option(names = { "-c", "--connect" }, paramLabel = "SERVER", description = "run client and connect to remote server")
|
||||
@CommandLine.ArgGroup(exclusive = true, multiplicity = "1")
|
||||
RunMode runMode;
|
||||
|
||||
static class RunMode {
|
||||
@CommandLine.Option(names = { "-c", "--connect" }, required = true, description = "Connect to remote server", paramLabel = "HOST")
|
||||
String remoteServer;
|
||||
|
||||
@CommandLine.Option(names = { "-s", "--server" }, description = "run server and wait for client")
|
||||
@CommandLine.Option(names = { "-s", "--server" }, required = true, description = "Run server and wait for client")
|
||||
boolean runServer = false;
|
||||
}
|
||||
|
||||
@CommandLine.Option(names = { "-l", "--pkt-size" }, paramLabel = "SIZE", description = "datagram size in bytes, max 65507 [default: ${DEFAULT-VALUE}]")
|
||||
//int packetSize = 16384; // Min: 256 Max: 65507
|
||||
@CommandLine.Option(names = { "-l", "--pkt-len" }, paramLabel = "SIZE", description = "Datagram size in bytes, max 65507 [default: ${DEFAULT-VALUE}]")
|
||||
int packetSize = 65507; // Min: 256 Max: 65507
|
||||
|
||||
@CommandLine.Option(names = { "-n", "--pkt-num" }, paramLabel = "NUM", description = "number of packets to send [default: ${DEFAULT-VALUE}]")
|
||||
int packetCount = 5000;
|
||||
@CommandLine.Option(names = { "-n", "--pkt-num" }, paramLabel = "NUM", description = "Number of packets to send [default: ${DEFAULT-VALUE}]")
|
||||
int packetCount = 150_000;
|
||||
|
||||
@CommandLine.Option(names = { "-p", "--port" }, paramLabel = "PORT", description = "network port [default: ${DEFAULT-VALUE}]")
|
||||
@CommandLine.Option(names = { "-p", "--port" }, paramLabel = "PORT", description = "Network port [default: ${DEFAULT-VALUE}]")
|
||||
int port = 4445;
|
||||
|
||||
|
||||
|
@ -41,12 +45,10 @@ public class Application implements Callable<Integer> {
|
|||
@Override
|
||||
public Integer call() throws Exception { // your business logic goes here...
|
||||
|
||||
if(runServer) {
|
||||
if(runMode.runServer) {
|
||||
runServer();
|
||||
}
|
||||
|
||||
if(remoteServer != null) {
|
||||
runClient(remoteServer);
|
||||
} else if(runMode.remoteServer != null) {
|
||||
runClient(runMode.remoteServer);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
|
|||
*
|
||||
* Datagram consists of the following
|
||||
* <p>
|
||||
* <------------------------- HEADER 32 bytes --------------> <---------- DATA min 32 bytes -------->
|
||||
* <------------------------- HEADER 32 bytes --------------> <---------- DATA bytes min 32, max 65475 -------->
|
||||
* _long _int _int _long _long
|
||||
* 8_bytes 4_bytes 4_bytes 8_bytes 8_bytes
|
||||
* MAGIC-ID TYPE LENGTH CUR_PKT MAX_PKT
|
||||
|
@ -24,10 +24,7 @@ public class Datagram {
|
|||
|
||||
final Logger log = LoggerFactory.getLogger(Datagram.class);
|
||||
|
||||
private final Random random = new Random();
|
||||
|
||||
private final int HEADER_LENGTH = 32;
|
||||
|
||||
private final byte[] MAGIC_ID = "jPerfTok".getBytes(StandardCharsets.UTF_8); // Must be 8-bytes
|
||||
|
||||
private final int type;
|
||||
|
|
|
@ -22,8 +22,6 @@ public class UdpClient {
|
|||
private final DatagramSocket socket;
|
||||
|
||||
private byte[] buf = new byte[256];
|
||||
private long packetsSent = 0;
|
||||
private long bytesSent = 0;
|
||||
|
||||
private int packetCount;
|
||||
private int packetSize;
|
||||
|
|
Loading…
Reference in a new issue