Make client/server options mutually exclusive.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Mark Nellemann 2023-06-26 09:37:07 +02:00
parent dd011c9f36
commit 0f5ee37933
4 changed files with 18 additions and 21 deletions

View file

@ -1,3 +1,3 @@
projectId = jperf projectId = jperf
projectGroup = biz.nellemann.jperf projectGroup = biz.nellemann.jperf
projectVersion = 0.0.2 projectVersion = 0.0.3

View file

@ -20,20 +20,24 @@ public class Application implements Callable<Integer> {
final Logger log = LoggerFactory.getLogger(Application.class); 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")
String remoteServer; RunMode runMode;
@CommandLine.Option(names = { "-s", "--server" }, description = "run server and wait for client") static class RunMode {
boolean runServer = false; @CommandLine.Option(names = { "-c", "--connect" }, required = true, description = "Connect to remote server", paramLabel = "HOST")
String remoteServer;
@CommandLine.Option(names = { "-l", "--pkt-size" }, paramLabel = "SIZE", description = "datagram size in bytes, max 65507 [default: ${DEFAULT-VALUE}]") @CommandLine.Option(names = { "-s", "--server" }, required = true, description = "Run server and wait for client")
//int packetSize = 16384; // Min: 256 Max: 65507 boolean runServer = false;
}
@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 int packetSize = 65507; // Min: 256 Max: 65507
@CommandLine.Option(names = { "-n", "--pkt-num" }, paramLabel = "NUM", description = "number of packets to send [default: ${DEFAULT-VALUE}]") @CommandLine.Option(names = { "-n", "--pkt-num" }, paramLabel = "NUM", description = "Number of packets to send [default: ${DEFAULT-VALUE}]")
int packetCount = 5000; 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; int port = 4445;
@ -41,12 +45,10 @@ public class Application implements Callable<Integer> {
@Override @Override
public Integer call() throws Exception { // your business logic goes here... public Integer call() throws Exception { // your business logic goes here...
if(runServer) { if(runMode.runServer) {
runServer(); runServer();
} } else if(runMode.remoteServer != null) {
runClient(runMode.remoteServer);
if(remoteServer != null) {
runClient(remoteServer);
} }
return 0; return 0;

View file

@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory;
* *
* Datagram consists of the following * Datagram consists of the following
* <p> * <p>
* <------------------------- HEADER 32 bytes --------------> <---------- DATA min 32 bytes --------> * <------------------------- HEADER 32 bytes --------------> <---------- DATA bytes min 32, max 65475 -------->
* _long _int _int _long _long * _long _int _int _long _long
* 8_bytes 4_bytes 4_bytes 8_bytes 8_bytes * 8_bytes 4_bytes 4_bytes 8_bytes 8_bytes
* MAGIC-ID TYPE LENGTH CUR_PKT MAX_PKT * MAGIC-ID TYPE LENGTH CUR_PKT MAX_PKT
@ -24,10 +24,7 @@ public class Datagram {
final Logger log = LoggerFactory.getLogger(Datagram.class); final Logger log = LoggerFactory.getLogger(Datagram.class);
private final Random random = new Random();
private final int HEADER_LENGTH = 32; private final int HEADER_LENGTH = 32;
private final byte[] MAGIC_ID = "jPerfTok".getBytes(StandardCharsets.UTF_8); // Must be 8-bytes private final byte[] MAGIC_ID = "jPerfTok".getBytes(StandardCharsets.UTF_8); // Must be 8-bytes
private final int type; private final int type;

View file

@ -22,8 +22,6 @@ public class UdpClient {
private final DatagramSocket socket; private final DatagramSocket socket;
private byte[] buf = new byte[256]; private byte[] buf = new byte[256];
private long packetsSent = 0;
private long bytesSent = 0;
private int packetCount; private int packetCount;
private int packetSize; private int packetSize;