From c4869be014d60738af5ec1c58f107c147f9d14f2 Mon Sep 17 00:00:00 2001 From: Mark Nellemann Date: Mon, 26 Jun 2023 12:56:46 +0200 Subject: [PATCH] Cleanup --- README.md | 20 +++++++---- build.gradle | 3 -- settings.gradle | 12 +------ .../java/biz/nellemann/jperf/Application.java | 19 ++++++++--- .../java/biz/nellemann/jperf/DataType.java | 15 ++++++++ .../java/biz/nellemann/jperf/Datagram.java | 16 ++++++++- .../java/biz/nellemann/jperf/Statistics.java | 15 ++++++++ .../java/biz/nellemann/jperf/UdpClient.java | 16 ++++++++- .../java/biz/nellemann/jperf/UdpServer.java | 15 ++++++++ .../biz/nellemann/jperf/VersionProvider.java | 34 +++++++++++++++++++ 10 files changed, 138 insertions(+), 27 deletions(-) create mode 100644 src/main/java/biz/nellemann/jperf/VersionProvider.java diff --git a/README.md b/README.md index 56fa3d2..3629080 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ # jPerf -Small utility to measure network performance. +Small utility to measure network performance between two hosts. ## Requirements -You need Java (JRE) version 11 or later to run jperf. +You need Java (JRE) version 8 or later to run jperf. ## Usage Instructions @@ -12,20 +12,26 @@ You need Java (JRE) version 11 or later to run jperf. - Run **/opt/jperf/bin/jperf**, if installed from package - Or as **java -jar /path/to/jperf.jar** -To change the temporary directory where disk-load files are written to, use the *-Djava.io.tmpdir=/mytempdir* option. - ```shell -Usage: ... +Usage: jperf [-hV] [-l=SIZE] [-n=NUM] [-p=PORT] (-c=HOST | -s) +Network performance measurement tool. + -c, --connect=HOST Connect to remote server + -h, --help Show this help message and exit. + -l, --pkt-len=SIZE Datagram size in bytes, max 65507 [default: 65507] + -n, --pkt-num=NUM Number of packets to send [default: 150000] + -p, --port=PORT Network port [default: 4445] + -s, --server Run server and wait for client + -V, --version Print version information and exit. ``` ## Development Information -You need Java (JDK) version 11 or later to build jperf. +You need Java (JDK) version 8 or later to build jperf. ### Build & Test Use the gradle build tool, which will download all required dependencies: ```shell -./gradlew clean build run +./gradlew clean build ``` diff --git a/build.gradle b/build.gradle index c7eaa1d..b54450a 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,6 @@ dependencies { implementation 'ch.qos.logback:logback-classic:1.3.8' } -// Apply a specific Java toolchain to ease working on different environments. java { toolchain { languageVersion = JavaLanguageVersion.of(8) @@ -33,12 +32,10 @@ java { application { - // Define the main class for the application. mainClass = 'biz.nellemann.jperf.Application' } tasks.named('test') { - // Use JUnit Platform for unit tests. useJUnitPlatform() } diff --git a/settings.gradle b/settings.gradle index a2d12b2..dbf3c4b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,15 +1,5 @@ -/* - * This file was generated by the Gradle 'init' task. - * - * The settings file is used to specify which projects to include in your build. - * - * Detailed information about configuring a multi-project build in Gradle can be found - * in the user manual at https://docs.gradle.org/8.1.1/userguide/multi_project_builds.html - */ - plugins { - // Apply the foojay-resolver plugin to allow automatic download of JDKs - id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' + id 'org.gradle.toolchains.foojay-resolver-convention' version '0.5.0' } rootProject.name = 'jperf' diff --git a/src/main/java/biz/nellemann/jperf/Application.java b/src/main/java/biz/nellemann/jperf/Application.java index 772180e..419ee19 100644 --- a/src/main/java/biz/nellemann/jperf/Application.java +++ b/src/main/java/biz/nellemann/jperf/Application.java @@ -1,5 +1,17 @@ /* - * This Java source file was generated by the Gradle 'init' task. + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ package biz.nellemann.jperf; @@ -13,8 +25,7 @@ import java.io.IOException; import java.net.SocketException; import java.util.concurrent.Callable; -@Command(name = "jperf", mixinStandardHelpOptions = true, version = "0.1", - description = "Network performance measurement tool.") +@Command(name = "jperf", mixinStandardHelpOptions = true, versionProvider = VersionProvider.class, description = "Network performance measurement tool.") public class Application implements Callable { final Logger log = LoggerFactory.getLogger(Application.class); @@ -43,7 +54,7 @@ public class Application implements Callable { @Override - public Integer call() throws Exception { // your business logic goes here... + public Integer call() throws Exception { if(runMode.runServer) { runServer(); diff --git a/src/main/java/biz/nellemann/jperf/DataType.java b/src/main/java/biz/nellemann/jperf/DataType.java index b2d6de4..a6386bc 100644 --- a/src/main/java/biz/nellemann/jperf/DataType.java +++ b/src/main/java/biz/nellemann/jperf/DataType.java @@ -1,3 +1,18 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ package biz.nellemann.jperf; public enum DataType { diff --git a/src/main/java/biz/nellemann/jperf/Datagram.java b/src/main/java/biz/nellemann/jperf/Datagram.java index 12300c4..f98905d 100644 --- a/src/main/java/biz/nellemann/jperf/Datagram.java +++ b/src/main/java/biz/nellemann/jperf/Datagram.java @@ -1,10 +1,24 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ package biz.nellemann.jperf; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import java.util.Random; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/biz/nellemann/jperf/Statistics.java b/src/main/java/biz/nellemann/jperf/Statistics.java index 0db926c..b802eaa 100644 --- a/src/main/java/biz/nellemann/jperf/Statistics.java +++ b/src/main/java/biz/nellemann/jperf/Statistics.java @@ -1,3 +1,18 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ package biz.nellemann.jperf; import java.time.Duration; diff --git a/src/main/java/biz/nellemann/jperf/UdpClient.java b/src/main/java/biz/nellemann/jperf/UdpClient.java index 642929a..5eb61f0 100644 --- a/src/main/java/biz/nellemann/jperf/UdpClient.java +++ b/src/main/java/biz/nellemann/jperf/UdpClient.java @@ -1,3 +1,18 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ package biz.nellemann.jperf; import java.io.IOException; @@ -6,7 +21,6 @@ import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; -import java.time.Instant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/biz/nellemann/jperf/UdpServer.java b/src/main/java/biz/nellemann/jperf/UdpServer.java index 256b96f..cc9ee87 100644 --- a/src/main/java/biz/nellemann/jperf/UdpServer.java +++ b/src/main/java/biz/nellemann/jperf/UdpServer.java @@ -1,3 +1,18 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ package biz.nellemann.jperf; import java.io.IOException; diff --git a/src/main/java/biz/nellemann/jperf/VersionProvider.java b/src/main/java/biz/nellemann/jperf/VersionProvider.java new file mode 100644 index 0000000..71e8b92 --- /dev/null +++ b/src/main/java/biz/nellemann/jperf/VersionProvider.java @@ -0,0 +1,34 @@ +/* + Copyright 2023 mark.nellemann@gmail.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ +package biz.nellemann.jperf; + +import picocli.CommandLine; + +import java.io.IOException; +import java.util.jar.Attributes; +import java.util.jar.Manifest; + +class VersionProvider implements CommandLine.IVersionProvider { + + public String[] getVersion() throws IOException { + + Manifest manifest = new Manifest(getClass().getResourceAsStream("/META-INF/MANIFEST.MF")); + Attributes attrs = manifest.getMainAttributes(); + + return new String[] { "${COMMAND-FULL-NAME} " + attrs.getValue("Build-Version") }; + } + +} \ No newline at end of file