Skip to content

Commit c9771fd

Browse files
authored
Merge pull request #2007 from esnet/bmah-gsro-follow-up
Minor follow-up commits to GSO/GRO feature
2 parents b36c74f + 593b79d commit c9771fd

File tree

3 files changed

+63
-7
lines changed

3 files changed

+63
-7
lines changed

src/iperf_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* iperf, Copyright (c) 2014-2024, The Regents of the University of
2+
* iperf, Copyright (c) 2014-2026, The Regents of the University of
33
* California, through Lawrence Berkeley National Laboratory (subject
44
* to receipt of any required approvals from the U.S. Dept. of
55
* Energy). All rights reserved.
@@ -920,7 +920,7 @@ void
920920
iperf_on_test_start(struct iperf_test *test)
921921
{
922922
if (test->json_output) {
923-
cJSON_AddItemToObject(test->json_start, "test_start", iperf_json_printf("protocol: %s num_streams: %d blksize: %d omit: %d duration: %d bytes: %d blocks: %d reverse: %d tos: %d target_bitrate: %d bidir: %d fqrate: %d interval: %f", test->protocol->name, (int64_t) test->num_streams, (int64_t) test->settings->blksize, (int64_t) test->omit, (int64_t) test->duration, (int64_t) test->settings->bytes, (int64_t) test->settings->blocks, test->reverse?(int64_t)1:(int64_t)0, (int64_t) test->settings->tos, (int64_t) test->settings->rate, (int64_t) test->bidirectional, (uint64_t) test->settings->fqrate, test->stats_interval));
923+
cJSON_AddItemToObject(test->json_start, "test_start", iperf_json_printf("protocol: %s num_streams: %d blksize: %d omit: %d duration: %d bytes: %d blocks: %d reverse: %d tos: %d target_bitrate: %d bidir: %d fqrate: %d interval: %f gso: %d gro: %d", test->protocol->name, (int64_t) test->num_streams, (int64_t) test->settings->blksize, (int64_t) test->omit, (int64_t) test->duration, (int64_t) test->settings->bytes, (int64_t) test->settings->blocks, test->reverse?(int64_t)1:(int64_t)0, (int64_t) test->settings->tos, (int64_t) test->settings->rate, (int64_t) test->bidirectional, (uint64_t) test->settings->fqrate, test->stats_interval, (uint64_t) test->settings->gso, (uint64_t) test->settings->gro));
924924
} else {
925925
if (test->verbose) {
926926
if (test->settings->bytes)

src/iperf_udp.c

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* iperf, Copyright (c) 2014-2022, The Regents of the University of
2+
* iperf, Copyright (c) 2014-2026, The Regents of the University of
33
* California, through Lawrence Berkeley National Laboratory (subject
44
* to receipt of any required approvals from the U.S. Dept. of
55
* Energy). All rights reserved.
@@ -156,22 +156,68 @@ iperf_udp_recv(struct iperf_stream *sp)
156156
sent_time.usecs = usec;
157157
}
158158

159-
/* Loss/out-of-order accounting - now always executed */
159+
/*
160+
* Try to handle out of order packets. The way we do this
161+
* uses a constant amount of storage but might not be
162+
* correct in all cases. In particular we seem to have the
163+
* assumption that packets can't be duplicated in the network,
164+
* because duplicate packets will possibly cause some problems here.
165+
*
166+
* First figure out if the sequence numbers are going forward.
167+
* Note that pcount is the sequence number read from the packet,
168+
* and sp->packet_count is the highest sequence number seen so
169+
* far (so we're expecting to see the packet with sequence number
170+
* sp->packet_count + 1 arrive next).
171+
*/
160172
if (pcount >= sp->packet_count + 1) {
173+
174+
/* Forward, but is there a gap in sequence numbers? */
161175
if (pcount > sp->packet_count + 1) {
176+
/* There's a gap so count that as a loss. */
162177
sp->cnt_error += (pcount - 1) - sp->packet_count;
178+
if (test->debug_level >= DEBUG_LEVEL_INFO)
179+
fprintf(stderr, "LOST %" PRIu64 " PACKETS - received packet %" PRIu64 " but expected sequence %" PRIu64 " on stream %d\n", (pcount - sp->packet_count + 1), pcount, sp->packet_count + 1, sp->socket);
163180
}
181+
/* Update the highest sequence number seen so far. */
164182
sp->packet_count = pcount;
165183
} else {
184+
185+
/*
186+
* Sequence number went backward (or was stationary?!?).
187+
* This counts as an out-of-order packet.
188+
*/
166189
sp->outoforder_packets++;
190+
191+
/*
192+
* If we have lost packets, then the fact that we are now
193+
* seeing an out-of-order packet offsets a prior sequence
194+
* number gap that was counted as a loss. So we can take
195+
* away a loss.
196+
*/
167197
if (sp->cnt_error > 0)
168198
sp->cnt_error--;
199+
200+
/* Log the out-of-order packet */
201+
if (test->debug_level >= DEBUG_LEVEL_INFO)
202+
fprintf(stderr, "OUT OF ORDER - received packet %" PRIu64 " but expected sequence %" PRIu64 " on stream %d\n", pcount, sp->packet_count + 1, sp->socket);
169203
}
170204

171-
/* Jitter computation - now always executed */
205+
/*
206+
* jitter measurement
207+
*
208+
* This computation is based on RFC 1889 (specifically
209+
* sections 6.3.1 and A.8).
210+
*
211+
* Note that synchronized clocks are not required since
212+
* the source packet delta times are known. Also this
213+
* computation does not require knowing the round-trip
214+
* time.
215+
*/
172216
iperf_time_now(&arrival_time);
173217
iperf_time_diff(&arrival_time, &sent_time, &temp_time);
174218
transit = iperf_time_in_secs(&temp_time);
219+
220+
/* Hack to handle the first packet by initializing prev_transit. */
175221
if (first_packet)
176222
sp->prev_transit = transit;
177223
d = transit - sp->prev_transit;
@@ -234,7 +280,7 @@ iperf_udp_send(struct iperf_stream *sp)
234280
while (buf_sz > 0 && dgram_buf + dgram_sz <= dgram_buf_end) {
235281
cnt++;
236282

237-
if (sp->test->debug)
283+
if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG)
238284
printf("%d (%d) remaining %d\n", cnt, dgram_sz, buf_sz);
239285

240286
/* Prevent buffer underflow */

src/iperf_util.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* iperf, Copyright (c) 2014, 2016, 2017, The Regents of the University of
2+
* iperf, Copyright (c) 2014-2026, The Regents of the University of
33
* California, through Lawrence Berkeley National Laboratory (subject
44
* to receipt of any required approvals from the U.S. Dept. of
55
* Energy). All rights reserved.
@@ -347,6 +347,16 @@ get_optional_features(void)
347347
numfeatures++;
348348
#endif /* HAVE_PTHREAD */
349349

350+
#if defined(HAVE_UDP_GRO) || defined(HAVE_UDP_SEGMENT)
351+
if (numfeatures > 0) {
352+
strncat(features, ", ",
353+
sizeof(features) - strlen(features) - 1);
354+
}
355+
strncat(features, "GSO/GRO support",
356+
sizeof(features) - strlen(features) - 1);
357+
numfeatures++;
358+
#endif /* HAVE_UDP_GRO || HAVE_UDP_SEGMENT */
359+
350360
if (numfeatures == 0) {
351361
strncat(features, "None",
352362
sizeof(features) - strlen(features) - 1);

0 commit comments

Comments
 (0)