aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2020-05-12 16:26:55 -0700
committerGitHub <noreply@github.com>2020-05-12 16:26:55 -0700
commit2609dd71235e980524dcafa58b8b4038edc2601f (patch)
tree58c41e45d667d41ffe574610e74884986589bb53
parent1521d9b522fa2ee5a35c8d06a3372290938660bf (diff)
downloadiperf3-2609dd71235e980524dcafa58b8b4038edc2601f.tar.gz
fix(udp): Properly initialize for the first UDP packet received. (#990)
This fixes a problem where UDP tests between systems with significant clock skew would register large amounts of jitter at the start of the test. Fixes #842. Analysis done by (and solution inspired by) @davidBar-On.
-rw-r--r--src/iperf_udp.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/iperf_udp.c b/src/iperf_udp.c
index 2245825..ab6be5e 100644
--- a/src/iperf_udp.c
+++ b/src/iperf_udp.c
@@ -66,6 +66,7 @@ iperf_udp_recv(struct iperf_stream *sp)
uint64_t pcount;
int r;
int size = sp->settings->blksize;
+ int first_packet = 0;
double transit = 0, d = 0;
struct iperf_time sent_time, arrival_time, temp_time;
@@ -81,9 +82,19 @@ iperf_udp_recv(struct iperf_stream *sp)
/* Only count bytes received while we're in the correct state. */
if (sp->test->state == TEST_RUNNING) {
+
+ /*
+ * For jitter computation below, it's important to know if this
+ * packet is the first packet received.
+ */
+ if (sp->result->bytes_received == 0) {
+ first_packet = 1;
+ }
+
sp->result->bytes_received += r;
sp->result->bytes_received_this_interval += r;
+ /* Dig the various counters out of the incoming UDP packet */
if (sp->test->udp_counters_64bit) {
memcpy(&sec, sp->buffer, sizeof(sec));
memcpy(&usec, sp->buffer+4, sizeof(usec));
@@ -168,6 +179,11 @@ iperf_udp_recv(struct iperf_stream *sp)
iperf_time_diff(&arrival_time, &sent_time, &temp_time);
transit = iperf_time_in_secs(&temp_time);
+
+ /* Hack to handle the first packet by initializing prev_transit. */
+ if (first_packet)
+ sp->prev_transit = transit;
+
d = transit - sp->prev_transit;
if (d < 0)
d = -d;