test: the mock can release a withheld packet past the reorder window

This commit is contained in:
Martino Ferrari committed 2026-10-08 17:49:11 +02:00
1 parent 45958a441a
commit 85ba835d61
1 file changed
+19 -9
+19 -9
View File
@@ -278,6 +278,17 @@ def main():
"rather than cancelling it, since the held packet waits for the next packet " "rather than cancelling it, since the held packet waits for the next packet "
"actually sent. 0 = never", "actually sent. 0 = never",
) )
ap.add_argument(
"--reorder-delay-ms",
type=float,
default=0.0,
metavar="MS",
help="hold a withheld packet this many milliseconds instead of releasing it "
"immediately behind the packet that overtook it. Under the receiver's reorder "
"window the packet is resequenced and no hole is ever seen; past it the hole is "
"committed first and the packet has to backfill it -- which is the only way to "
"reach the backfill path at all, since a 0 ms delay always wins the race.",
)
args = ap.parse_args() args = ap.parse_args()
dt = args.stream_scale / args.rate # stream seconds per sample dt = args.stream_scale / args.rate # stream seconds per sample
@@ -309,7 +320,7 @@ def main():
t_stream = 0.0 t_stream = 0.0
started = None started = None
next_send = time.monotonic() next_send = time.monotonic()
held = None # (counter, datagram) built but withheld, for --reorder-every held = None # (counter, datagram, release_deadline) built but withheld, for --reorder-every
drop_left = 0 drop_left = 0
dropped = 0 dropped = 0
inverted = 0 inverted = 0
@@ -401,21 +412,20 @@ def main():
and held is None and held is None
and counter % args.reorder_every == 0 and counter % args.reorder_every == 0
): ):
held = (counter, pkt) held = (counter, pkt, now + args.reorder_delay_ms / 1000.0)
else: else:
sock.sendto(pkt, peer) sock.sendto(pkt, peer)
if held is not None: if held is not None and now >= held[2]:
# Out of order on the wire now: the receiver has already taken this # Within the receiver's reorder window, this packet is put back in order and
# packet's counter, so the held one no longer advances it and is stale by # costs nothing. Past the window, the receiver has already committed a hole
# definition -- one counter gap for the packet that overtook it, one stale # and this packet is what fills it.
# packet for the one that lost, and the loser's samples are gone.
sock.sendto(held[1], peer) sock.sendto(held[1], peer)
inverted += 1 inverted += 1
if not noted_reorder: if not noted_reorder:
noted_reorder = True noted_reorder = True
print( print(
"mock udpstreamer: sent packet %d before %d" "mock udpstreamer: sent packet %d before %d, releasing it %.1f ms late"
% (counter, held[0]), % (counter, held[0], args.reorder_delay_ms),
flush=True, flush=True,
) )
held = None held = None