diff --git a/gradle.properties b/gradle.properties index 3b1c07f..baf5c51 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ projectId = jperf projectGroup = biz.nellemann.jperf -projectVersion = 0.0.2 +projectVersion = 0.0.3 diff --git a/src/main/java/biz/nellemann/jperf/Application.java b/src/main/java/biz/nellemann/jperf/Application.java index 3748326..772180e 100644 --- a/src/main/java/biz/nellemann/jperf/Application.java +++ b/src/main/java/biz/nellemann/jperf/Application.java @@ -20,20 +20,24 @@ public class Application implements Callable { final Logger log = LoggerFactory.getLogger(Application.class); - @CommandLine.Option(names = { "-c", "--connect" }, paramLabel = "SERVER", description = "run client and connect to remote server") - String remoteServer; + @CommandLine.ArgGroup(exclusive = true, multiplicity = "1") + RunMode runMode; - @CommandLine.Option(names = { "-s", "--server" }, description = "run server and wait for client") - boolean runServer = false; + static class RunMode { + @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}]") - //int packetSize = 16384; // Min: 256 Max: 65507 + @CommandLine.Option(names = { "-s", "--server" }, required = true, description = "Run server and wait for client") + 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 - @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 { @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; diff --git a/src/main/java/biz/nellemann/jperf/Datagram.java b/src/main/java/biz/nellemann/jperf/Datagram.java index 4ddc014..12300c4 100644 --- a/src/main/java/biz/nellemann/jperf/Datagram.java +++ b/src/main/java/biz/nellemann/jperf/Datagram.java @@ -13,7 +13,7 @@ import org.slf4j.LoggerFactory; * * Datagram consists of the following *

- * <------------------------- 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; diff --git a/src/main/java/biz/nellemann/jperf/UdpClient.java b/src/main/java/biz/nellemann/jperf/UdpClient.java index 8859e19..642929a 100644 --- a/src/main/java/biz/nellemann/jperf/UdpClient.java +++ b/src/main/java/biz/nellemann/jperf/UdpClient.java @@ -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;