|
1 | 1 | /* |
2 | | - * iperf, Copyright (c) 2014-2022, The Regents of the University of |
| 2 | + * iperf, Copyright (c) 2014-2026, The Regents of the University of |
3 | 3 | * California, through Lawrence Berkeley National Laboratory (subject |
4 | 4 | * to receipt of any required approvals from the U.S. Dept. of |
5 | 5 | * Energy). All rights reserved. |
@@ -156,22 +156,68 @@ iperf_udp_recv(struct iperf_stream *sp) |
156 | 156 | sent_time.usecs = usec; |
157 | 157 | } |
158 | 158 |
|
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 | + */ |
160 | 172 | if (pcount >= sp->packet_count + 1) { |
| 173 | + |
| 174 | + /* Forward, but is there a gap in sequence numbers? */ |
161 | 175 | if (pcount > sp->packet_count + 1) { |
| 176 | + /* There's a gap so count that as a loss. */ |
162 | 177 | 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); |
163 | 180 | } |
| 181 | + /* Update the highest sequence number seen so far. */ |
164 | 182 | sp->packet_count = pcount; |
165 | 183 | } else { |
| 184 | + |
| 185 | + /* |
| 186 | + * Sequence number went backward (or was stationary?!?). |
| 187 | + * This counts as an out-of-order packet. |
| 188 | + */ |
166 | 189 | 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 | + */ |
167 | 197 | if (sp->cnt_error > 0) |
168 | 198 | 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); |
169 | 203 | } |
170 | 204 |
|
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 | + */ |
172 | 216 | iperf_time_now(&arrival_time); |
173 | 217 | iperf_time_diff(&arrival_time, &sent_time, &temp_time); |
174 | 218 | transit = iperf_time_in_secs(&temp_time); |
| 219 | + |
| 220 | + /* Hack to handle the first packet by initializing prev_transit. */ |
175 | 221 | if (first_packet) |
176 | 222 | sp->prev_transit = transit; |
177 | 223 | d = transit - sp->prev_transit; |
@@ -234,7 +280,7 @@ iperf_udp_send(struct iperf_stream *sp) |
234 | 280 | while (buf_sz > 0 && dgram_buf + dgram_sz <= dgram_buf_end) { |
235 | 281 | cnt++; |
236 | 282 |
|
237 | | - if (sp->test->debug) |
| 283 | + if (sp->test->debug_level >= DEBUG_LEVEL_DEBUG) |
238 | 284 | printf("%d (%d) remaining %d\n", cnt, dgram_sz, buf_sz); |
239 | 285 |
|
240 | 286 | /* Prevent buffer underflow */ |
|
0 commit comments