rwebtransport 0.2.2 → 0.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +523 -140
- package/Cargo.toml +5 -5
- package/README.md +8 -4
- package/crates/echo-server/src/bin/gen-test-cert.rs +1 -1
- package/crates/native/Cargo.toml +2 -0
- package/crates/native/src/config.rs +69 -8
- package/crates/native/src/driver.rs +253 -90
- package/crates/native/src/lib.rs +80 -57
- package/crates/native/src/parser_memory.rs +203 -0
- package/crates/native/src/server.rs +215 -183
- package/crates/native/src/session.rs +1341 -243
- package/crates/native/src/test_support.rs +119 -0
- package/crates/wtcore/Cargo.toml +1 -0
- package/crates/wtcore/src/h3.rs +250 -46
- package/dist/index.js +218 -75
- package/dist/index.js.map +7 -1
- package/dist/index.mjs +214 -69
- package/dist/index.mjs.map +7 -1
- package/dist/native.d.ts +10 -4
- package/dist/server.d.ts +1 -0
- package/package.json +84 -78
- package/prebuilds/darwin-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-arm64/rwebtransport.node +0 -0
- package/prebuilds/linux-x64/rwebtransport.node +0 -0
- package/prebuilds/win32-x64/rwebtransport.node +0 -0
- package/scripts/build-linux-prebuilt.sh +46 -0
- package/scripts/build-ts.js +41 -0
- package/scripts/build.js +10 -3
- package/vendor/quiche/AGENTS.md +10 -0
- package/vendor/quiche/Cargo.lock +239 -248
- package/vendor/quiche/Cargo.toml +23 -10
- package/vendor/quiche/examples/Makefile +4 -4
- package/vendor/quiche/examples/client.rs +10 -28
- package/vendor/quiche/examples/http3-client.rs +20 -34
- package/vendor/quiche/examples/http3-server.rs +47 -78
- package/vendor/quiche/examples/server.rs +19 -49
- package/vendor/quiche/include/quiche.h +35 -4
- package/vendor/quiche/src/build.rs +17 -0
- package/vendor/quiche/src/cid.rs +129 -61
- package/vendor/quiche/src/crypto/boringssl.rs +98 -86
- package/vendor/quiche/src/crypto/mod.rs +64 -77
- package/vendor/quiche/src/dgram.rs +2 -3
- package/vendor/quiche/src/error.rs +22 -20
- package/vendor/quiche/src/ffi.rs +558 -280
- package/vendor/quiche/src/flowcontrol.rs +0 -7
- package/vendor/quiche/src/frame.rs +134 -135
- package/vendor/quiche/src/h3/ffi.rs +73 -60
- package/vendor/quiche/src/h3/frame.rs +70 -90
- package/vendor/quiche/src/h3/mod.rs +1024 -593
- package/vendor/quiche/src/h3/qpack/decoder.rs +248 -34
- package/vendor/quiche/src/h3/qpack/dynamic_table.rs +859 -0
- package/vendor/quiche/src/h3/qpack/encoder.rs +14 -17
- package/vendor/quiche/src/h3/qpack/mod.rs +48 -0
- package/vendor/quiche/src/h3/qpack/static_table.rs +86 -73
- package/vendor/quiche/src/h3/stream.rs +1009 -194
- package/vendor/quiche/src/lib.rs +1361 -1195
- package/vendor/quiche/src/minmax.rs +2 -6
- package/vendor/quiche/src/packet.rs +420 -552
- package/vendor/quiche/src/path.rs +202 -72
- package/vendor/quiche/src/pmtud.rs +18 -16
- package/vendor/quiche/src/ranges.rs +184 -82
- package/vendor/quiche/src/recovery/AGENTS.md +5 -2
- package/vendor/quiche/src/recovery/bandwidth.rs +59 -40
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +2 -2
- package/vendor/quiche/src/recovery/congestion/cubic.rs +38 -47
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +54 -60
- package/vendor/quiche/src/recovery/congestion/hystart.rs +6 -10
- package/vendor/quiche/src/recovery/congestion/mod.rs +110 -42
- package/vendor/quiche/src/recovery/congestion/prr.rs +4 -1
- package/vendor/quiche/src/recovery/congestion/recovery.rs +91 -95
- package/vendor/quiche/src/recovery/congestion/reno.rs +17 -12
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +8 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +159 -247
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +9 -14
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +18 -15
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +43 -28
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +349 -76
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +147 -195
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +29 -27
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min.rs +180 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/global_min_tests.rs +221 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm.rs +395 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/hmm_tests.rs +473 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/rtt_jump_detector/mod.rs +175 -0
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +33 -26
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +107 -60
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +64 -11
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +34 -25
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +81 -86
- package/vendor/quiche/src/recovery/mod.rs +414 -173
- package/vendor/quiche/src/recovery/rtt.rs +8 -5
- package/vendor/quiche/src/stream/mod.rs +864 -133
- package/vendor/quiche/src/stream/recv_buf.rs +476 -172
- package/vendor/quiche/src/stream/send_buf.rs +343 -81
- package/vendor/quiche/src/test_utils.rs +78 -64
- package/vendor/quiche/src/tests.rs +2559 -1335
- package/vendor/quiche/src/tls/boringssl.rs +60 -63
- package/vendor/quiche/src/tls/mod.rs +146 -193
- package/vendor/quiche/src/transport_params.rs +87 -103
|
@@ -67,12 +67,10 @@ impl<T> ConnectionStateMap<T> {
|
|
|
67
67
|
return self.packet_map.pop_front().and_then(|(_, v)| v);
|
|
68
68
|
}
|
|
69
69
|
// Use binary search
|
|
70
|
-
let ret =
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Err(_) => None,
|
|
75
|
-
};
|
|
70
|
+
let ret = match self.packet_map.binary_search_by_key(&pkt_num, |&(n, _)| n) {
|
|
71
|
+
Ok(found) => self.packet_map.get_mut(found).and_then(|(_, v)| v.take()),
|
|
72
|
+
Err(_) => None,
|
|
73
|
+
};
|
|
76
74
|
|
|
77
75
|
while let Some((_, None)) = self.packet_map.front() {
|
|
78
76
|
self.packet_map.pop_front();
|
|
@@ -95,7 +93,7 @@ impl<T> ConnectionStateMap<T> {
|
|
|
95
93
|
Some(&(p, _)) if p < least_acked => {
|
|
96
94
|
self.packet_map.pop_front();
|
|
97
95
|
true
|
|
98
|
-
}
|
|
96
|
+
}
|
|
99
97
|
_ => false,
|
|
100
98
|
} {}
|
|
101
99
|
}
|
|
@@ -289,11 +287,7 @@ impl MaxAckHeightTracker {
|
|
|
289
287
|
aggregation_epoch_bytes: 0,
|
|
290
288
|
last_sent_packet_number_before_epoch: 0,
|
|
291
289
|
num_ack_aggregation_epochs: 0,
|
|
292
|
-
ack_aggregation_bandwidth_threshold: if overestimate_avoidance {
|
|
293
|
-
2.0
|
|
294
|
-
} else {
|
|
295
|
-
1.0
|
|
296
|
-
},
|
|
290
|
+
ack_aggregation_bandwidth_threshold: if overestimate_avoidance { 2.0 } else { 1.0 },
|
|
297
291
|
start_new_aggregation_epoch_after_full_round: true,
|
|
298
292
|
reduce_extra_acked_on_bandwidth_increase: true,
|
|
299
293
|
}
|
|
@@ -314,16 +308,20 @@ impl MaxAckHeightTracker {
|
|
|
314
308
|
|
|
315
309
|
#[allow(clippy::too_many_arguments)]
|
|
316
310
|
fn update(
|
|
317
|
-
&mut self,
|
|
318
|
-
|
|
319
|
-
|
|
311
|
+
&mut self,
|
|
312
|
+
bandwidth_estimate: Bandwidth,
|
|
313
|
+
is_new_max_bandwidth: bool,
|
|
314
|
+
round_trip_count: usize,
|
|
315
|
+
last_sent_packet_number: u64,
|
|
316
|
+
last_acked_packet_number: u64,
|
|
317
|
+
ack_time: Instant,
|
|
318
|
+
bytes_acked: usize,
|
|
320
319
|
) -> usize {
|
|
321
320
|
let mut force_new_epoch = false;
|
|
322
321
|
|
|
323
322
|
if self.reduce_extra_acked_on_bandwidth_increase && is_new_max_bandwidth {
|
|
324
323
|
// Save and clear existing entries.
|
|
325
|
-
let mut best =
|
|
326
|
-
self.max_ack_height_filter.get_best().unwrap_or_default();
|
|
324
|
+
let mut best = self.max_ack_height_filter.get_best().unwrap_or_default();
|
|
327
325
|
let mut second_best = self
|
|
328
326
|
.max_ack_height_filter
|
|
329
327
|
.get_second_best()
|
|
@@ -342,32 +340,26 @@ impl MaxAckHeightTracker {
|
|
|
342
340
|
self.max_ack_height_filter.update(best, best.round);
|
|
343
341
|
}
|
|
344
342
|
|
|
345
|
-
let expected_bytes_acked =
|
|
346
|
-
.to_bytes_per_period(second_best.time_delta)
|
|
347
|
-
as usize;
|
|
343
|
+
let expected_bytes_acked =
|
|
344
|
+
bandwidth_estimate.to_bytes_per_period(second_best.time_delta) as usize;
|
|
348
345
|
if expected_bytes_acked < second_best.bytes_acked {
|
|
349
|
-
second_best.extra_acked =
|
|
350
|
-
second_best.bytes_acked - expected_bytes_acked;
|
|
346
|
+
second_best.extra_acked = second_best.bytes_acked - expected_bytes_acked;
|
|
351
347
|
self.max_ack_height_filter
|
|
352
348
|
.update(second_best, second_best.round);
|
|
353
349
|
}
|
|
354
350
|
|
|
355
|
-
let expected_bytes_acked =
|
|
356
|
-
.to_bytes_per_period(third_best.time_delta)
|
|
357
|
-
as usize;
|
|
351
|
+
let expected_bytes_acked =
|
|
352
|
+
bandwidth_estimate.to_bytes_per_period(third_best.time_delta) as usize;
|
|
358
353
|
if expected_bytes_acked < third_best.bytes_acked {
|
|
359
|
-
third_best.extra_acked =
|
|
360
|
-
third_best.bytes_acked - expected_bytes_acked;
|
|
354
|
+
third_best.extra_acked = third_best.bytes_acked - expected_bytes_acked;
|
|
361
355
|
self.max_ack_height_filter
|
|
362
356
|
.update(third_best, third_best.round);
|
|
363
357
|
}
|
|
364
358
|
}
|
|
365
359
|
|
|
366
|
-
//
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
last_acked_packet_number >
|
|
370
|
-
self.last_sent_packet_number_before_epoch
|
|
360
|
+
// Start a new epoch if this epoch includes any acknowledged packet.
|
|
361
|
+
if self.start_new_aggregation_epoch_after_full_round
|
|
362
|
+
&& last_acked_packet_number > self.last_sent_packet_number_before_epoch
|
|
371
363
|
{
|
|
372
364
|
force_new_epoch = true;
|
|
373
365
|
}
|
|
@@ -377,11 +369,10 @@ impl MaxAckHeightTracker {
|
|
|
377
369
|
_ => {
|
|
378
370
|
self.aggregation_epoch_bytes = bytes_acked;
|
|
379
371
|
self.aggregation_epoch_start_time = Some(ack_time);
|
|
380
|
-
self.last_sent_packet_number_before_epoch =
|
|
381
|
-
last_sent_packet_number;
|
|
372
|
+
self.last_sent_packet_number_before_epoch = last_sent_packet_number;
|
|
382
373
|
self.num_ack_aggregation_epochs += 1;
|
|
383
374
|
return 0;
|
|
384
|
-
}
|
|
375
|
+
}
|
|
385
376
|
};
|
|
386
377
|
|
|
387
378
|
// Compute how many bytes are expected to be delivered, assuming max
|
|
@@ -389,11 +380,10 @@ impl MaxAckHeightTracker {
|
|
|
389
380
|
let aggregation_delta = ack_time.duration_since(epoch_start_time);
|
|
390
381
|
let expected_bytes_acked =
|
|
391
382
|
bandwidth_estimate.to_bytes_per_period(aggregation_delta) as usize;
|
|
392
|
-
// Reset the current aggregation epoch as soon as the ack arrival rate
|
|
393
|
-
// less than or equal to the max bandwidth.
|
|
394
|
-
if self.aggregation_epoch_bytes
|
|
395
|
-
(self.ack_aggregation_bandwidth_threshold *
|
|
396
|
-
expected_bytes_acked as f64) as usize
|
|
383
|
+
// Reset the current aggregation epoch as soon as the ack arrival rate
|
|
384
|
+
// is less than or equal to the max bandwidth.
|
|
385
|
+
if self.aggregation_epoch_bytes
|
|
386
|
+
<= (self.ack_aggregation_bandwidth_threshold * expected_bytes_acked as f64) as usize
|
|
397
387
|
{
|
|
398
388
|
// Reset to start measuring a new aggregation epoch.
|
|
399
389
|
self.aggregation_epoch_bytes = bytes_acked;
|
|
@@ -406,8 +396,7 @@ impl MaxAckHeightTracker {
|
|
|
406
396
|
self.aggregation_epoch_bytes += bytes_acked;
|
|
407
397
|
|
|
408
398
|
// Compute how many extra bytes were delivered vs max bandwidth.
|
|
409
|
-
let extra_bytes_acked =
|
|
410
|
-
self.aggregation_epoch_bytes - expected_bytes_acked;
|
|
399
|
+
let extra_bytes_acked = self.aggregation_epoch_bytes - expected_bytes_acked;
|
|
411
400
|
|
|
412
401
|
let new_event = ExtraAckedEvent {
|
|
413
402
|
extra_acked: extra_bytes_acked,
|
|
@@ -422,22 +411,14 @@ impl MaxAckHeightTracker {
|
|
|
422
411
|
}
|
|
423
412
|
}
|
|
424
413
|
|
|
425
|
-
impl From<(Instant, usize, usize, &BandwidthSampler)>
|
|
426
|
-
for ConnectionStateOnSentPacket
|
|
427
|
-
{
|
|
414
|
+
impl From<(Instant, usize, usize, &BandwidthSampler)> for ConnectionStateOnSentPacket {
|
|
428
415
|
fn from(
|
|
429
|
-
(sent_time, size, bytes_in_flight, sampler): (
|
|
430
|
-
Instant,
|
|
431
|
-
usize,
|
|
432
|
-
usize,
|
|
433
|
-
&BandwidthSampler,
|
|
434
|
-
),
|
|
416
|
+
(sent_time, size, bytes_in_flight, sampler): (Instant, usize, usize, &BandwidthSampler),
|
|
435
417
|
) -> Self {
|
|
436
418
|
ConnectionStateOnSentPacket {
|
|
437
419
|
sent_time,
|
|
438
420
|
size,
|
|
439
|
-
total_bytes_sent_at_last_acked_packet: sampler
|
|
440
|
-
.total_bytes_sent_at_last_acked_packet,
|
|
421
|
+
total_bytes_sent_at_last_acked_packet: sampler.total_bytes_sent_at_last_acked_packet,
|
|
441
422
|
last_acked_packet_sent_time: sampler.last_acked_packet_sent_time,
|
|
442
423
|
last_acked_packet_ack_time: sampler.last_acked_packet_ack_time,
|
|
443
424
|
send_time_state: SendTimeState {
|
|
@@ -454,10 +435,7 @@ impl From<(Instant, usize, usize, &BandwidthSampler)>
|
|
|
454
435
|
|
|
455
436
|
impl RecentAckPoints {
|
|
456
437
|
fn update(&mut self, ack_time: Instant, total_bytes_acked: usize) {
|
|
457
|
-
assert!(
|
|
458
|
-
total_bytes_acked >=
|
|
459
|
-
self.ack_points[1].map(|p| p.total_bytes_acked).unwrap_or(0)
|
|
460
|
-
);
|
|
438
|
+
assert!(total_bytes_acked >= self.ack_points[1].map(|p| p.total_bytes_acked).unwrap_or(0));
|
|
461
439
|
|
|
462
440
|
self.ack_points[0] = self.ack_points[1];
|
|
463
441
|
self.ack_points[1] = Some(AckPoint {
|
|
@@ -487,7 +465,8 @@ impl RecentAckPoints {
|
|
|
487
465
|
|
|
488
466
|
impl BandwidthSampler {
|
|
489
467
|
pub(crate) fn new(
|
|
490
|
-
max_height_tracker_window_length: usize,
|
|
468
|
+
max_height_tracker_window_length: usize,
|
|
469
|
+
overestimate_avoidance: bool,
|
|
491
470
|
choose_a0_point_fix: bool,
|
|
492
471
|
) -> Self {
|
|
493
472
|
BandwidthSampler {
|
|
@@ -523,8 +502,12 @@ impl BandwidthSampler {
|
|
|
523
502
|
}
|
|
524
503
|
|
|
525
504
|
pub(crate) fn on_packet_sent(
|
|
526
|
-
&mut self,
|
|
527
|
-
|
|
505
|
+
&mut self,
|
|
506
|
+
sent_time: Instant,
|
|
507
|
+
packet_number: u64,
|
|
508
|
+
bytes: usize,
|
|
509
|
+
bytes_in_flight: usize,
|
|
510
|
+
has_retransmittable_data: bool,
|
|
528
511
|
) {
|
|
529
512
|
self.last_sent_packet = packet_number;
|
|
530
513
|
|
|
@@ -572,9 +555,13 @@ impl BandwidthSampler {
|
|
|
572
555
|
}
|
|
573
556
|
|
|
574
557
|
pub(crate) fn on_congestion_event(
|
|
575
|
-
&mut self,
|
|
576
|
-
|
|
577
|
-
|
|
558
|
+
&mut self,
|
|
559
|
+
ack_time: Instant,
|
|
560
|
+
acked_packets: &[Acked],
|
|
561
|
+
lost_packets: &[Lost],
|
|
562
|
+
mut max_bandwidth: Option<Bandwidth>,
|
|
563
|
+
est_bandwidth_upper_bound: Bandwidth,
|
|
564
|
+
round_trip_count: usize,
|
|
578
565
|
) -> CongestionEventSample {
|
|
579
566
|
let mut last_lost_packet_send_state = SendTimeState::default();
|
|
580
567
|
let mut last_acked_packet_send_state = SendTimeState::default();
|
|
@@ -582,8 +569,7 @@ impl BandwidthSampler {
|
|
|
582
569
|
let mut last_acked_packet_num = 0u64;
|
|
583
570
|
|
|
584
571
|
for packet in lost_packets {
|
|
585
|
-
let send_state =
|
|
586
|
-
self.on_packet_lost(packet.packet_number, packet.bytes_lost);
|
|
572
|
+
let send_state = self.on_packet_lost(packet.packet_number, packet.bytes_lost);
|
|
587
573
|
if send_state.is_valid {
|
|
588
574
|
last_lost_packet_send_state = send_state;
|
|
589
575
|
last_lost_packet_num = packet.packet_number;
|
|
@@ -603,11 +589,10 @@ impl BandwidthSampler {
|
|
|
603
589
|
let mut max_send_rate = None;
|
|
604
590
|
let mut max_ack_rate = None;
|
|
605
591
|
for packet in acked_packets {
|
|
606
|
-
let sample =
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
};
|
|
592
|
+
let sample = match self.on_packet_acknowledged(ack_time, packet.pkt_num) {
|
|
593
|
+
Some(sample) if sample.state_at_send.is_valid => sample,
|
|
594
|
+
_ => continue,
|
|
595
|
+
};
|
|
611
596
|
|
|
612
597
|
last_acked_packet_send_state = sample.state_at_send;
|
|
613
598
|
last_acked_packet_num = packet.pkt_num;
|
|
@@ -620,14 +605,13 @@ impl BandwidthSampler {
|
|
|
620
605
|
|
|
621
606
|
if Some(sample.bandwidth) > event_sample.sample_max_bandwidth {
|
|
622
607
|
event_sample.sample_max_bandwidth = Some(sample.bandwidth);
|
|
623
|
-
event_sample.sample_is_app_limited =
|
|
624
|
-
sample.state_at_send.is_app_limited;
|
|
608
|
+
event_sample.sample_is_app_limited = sample.state_at_send.is_app_limited;
|
|
625
609
|
}
|
|
626
610
|
max_send_rate = max_send_rate.max(sample.send_rate);
|
|
627
611
|
max_ack_rate = max_ack_rate.max(Some(sample.ack_rate));
|
|
628
612
|
|
|
629
|
-
let inflight_sample =
|
|
630
|
-
last_acked_packet_send_state.total_bytes_acked;
|
|
613
|
+
let inflight_sample =
|
|
614
|
+
self.total_bytes_acked - last_acked_packet_send_state.total_bytes_acked;
|
|
631
615
|
if inflight_sample > event_sample.sample_max_inflight {
|
|
632
616
|
event_sample.sample_max_inflight = inflight_sample;
|
|
633
617
|
}
|
|
@@ -638,20 +622,17 @@ impl BandwidthSampler {
|
|
|
638
622
|
} else if !last_acked_packet_send_state.is_valid {
|
|
639
623
|
event_sample.last_packet_send_state = last_lost_packet_send_state;
|
|
640
624
|
} else {
|
|
641
|
-
// If
|
|
642
|
-
//
|
|
643
|
-
//
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
last_lost_packet_send_state
|
|
650
|
-
};
|
|
625
|
+
// If a loss alarm for two in-flight packets fires late, the first
|
|
626
|
+
// packet may already be acknowledged. Reevaluating loss detection
|
|
627
|
+
// could then declare the second packet lost.
|
|
628
|
+
event_sample.last_packet_send_state = if last_acked_packet_num > last_lost_packet_num {
|
|
629
|
+
last_acked_packet_send_state
|
|
630
|
+
} else {
|
|
631
|
+
last_lost_packet_send_state
|
|
632
|
+
};
|
|
651
633
|
}
|
|
652
634
|
|
|
653
|
-
let is_new_max_bandwidth =
|
|
654
|
-
event_sample.sample_max_bandwidth > max_bandwidth;
|
|
635
|
+
let is_new_max_bandwidth = event_sample.sample_max_bandwidth > max_bandwidth;
|
|
655
636
|
max_bandwidth = event_sample.sample_max_bandwidth.max(max_bandwidth);
|
|
656
637
|
|
|
657
638
|
if self.limit_max_ack_height_tracker_by_send_rate {
|
|
@@ -664,11 +645,8 @@ impl BandwidthSampler {
|
|
|
664
645
|
est_bandwidth_upper_bound
|
|
665
646
|
};
|
|
666
647
|
|
|
667
|
-
event_sample.extra_acked =
|
|
668
|
-
bandwidth_estimate,
|
|
669
|
-
is_new_max_bandwidth,
|
|
670
|
-
round_trip_count,
|
|
671
|
-
);
|
|
648
|
+
event_sample.extra_acked =
|
|
649
|
+
self.on_ack_event_end(bandwidth_estimate, is_new_max_bandwidth, round_trip_count);
|
|
672
650
|
|
|
673
651
|
event_sample.sample_max_send_rate = max_send_rate;
|
|
674
652
|
event_sample.sample_max_ack_rate = max_ack_rate;
|
|
@@ -676,9 +654,7 @@ impl BandwidthSampler {
|
|
|
676
654
|
event_sample
|
|
677
655
|
}
|
|
678
656
|
|
|
679
|
-
fn on_packet_lost(
|
|
680
|
-
&mut self, packet_number: u64, bytes_lost: usize,
|
|
681
|
-
) -> SendTimeState {
|
|
657
|
+
fn on_packet_lost(&mut self, packet_number: u64, bytes_lost: usize) -> SendTimeState {
|
|
682
658
|
let mut send_time_state = SendTimeState::default();
|
|
683
659
|
|
|
684
660
|
self.total_bytes_lost += bytes_lost;
|
|
@@ -691,7 +667,9 @@ impl BandwidthSampler {
|
|
|
691
667
|
}
|
|
692
668
|
|
|
693
669
|
fn on_ack_event_end(
|
|
694
|
-
&mut self,
|
|
670
|
+
&mut self,
|
|
671
|
+
bandwidth_estimate: Bandwidth,
|
|
672
|
+
is_new_max_bandwidth: bool,
|
|
695
673
|
round_trip_count: usize,
|
|
696
674
|
) -> usize {
|
|
697
675
|
let newly_acked_bytes =
|
|
@@ -711,9 +689,8 @@ impl BandwidthSampler {
|
|
|
711
689
|
self.last_acked_packet_ack_time,
|
|
712
690
|
newly_acked_bytes,
|
|
713
691
|
);
|
|
714
|
-
// If `extra_acked` is zero,
|
|
715
|
-
//
|
|
716
|
-
// last ack point of the previous epoch, as a A0 candidate.
|
|
692
|
+
// If `extra_acked` is zero, this ACK starts a new aggregation epoch.
|
|
693
|
+
// Save the previous epoch's last ACK point as an A0 candidate.
|
|
717
694
|
if self.overestimate_avoidance && extra_acked == 0 {
|
|
718
695
|
self.a0_candidates.push_back(
|
|
719
696
|
self.recent_ack_points
|
|
@@ -726,14 +703,15 @@ impl BandwidthSampler {
|
|
|
726
703
|
}
|
|
727
704
|
|
|
728
705
|
fn on_packet_acknowledged(
|
|
729
|
-
&mut self,
|
|
706
|
+
&mut self,
|
|
707
|
+
ack_time: Instant,
|
|
708
|
+
packet_number: u64,
|
|
730
709
|
) -> Option<BandwidthSample> {
|
|
731
710
|
self.last_acked_packet = packet_number;
|
|
732
711
|
let sent_packet = self.connection_state_map.take(packet_number)?;
|
|
733
712
|
|
|
734
713
|
self.total_bytes_acked += sent_packet.size;
|
|
735
|
-
self.total_bytes_sent_at_last_acked_packet =
|
|
736
|
-
sent_packet.send_time_state.total_bytes_sent;
|
|
714
|
+
self.total_bytes_sent_at_last_acked_packet = sent_packet.send_time_state.total_bytes_sent;
|
|
737
715
|
self.last_acked_packet_sent_time = sent_packet.sent_time;
|
|
738
716
|
self.last_acked_packet_ack_time = ack_time;
|
|
739
717
|
if self.overestimate_avoidance {
|
|
@@ -742,13 +720,10 @@ impl BandwidthSampler {
|
|
|
742
720
|
}
|
|
743
721
|
|
|
744
722
|
if self.is_app_limited {
|
|
745
|
-
// Exit app-limited phase
|
|
746
|
-
//
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
// end of the app limit phase.
|
|
750
|
-
if self.end_of_app_limited_phase.is_none() ||
|
|
751
|
-
Some(packet_number) > self.end_of_app_limited_phase
|
|
723
|
+
// Exit the app-limited phase if no end packet was recorded, or if
|
|
724
|
+
// this acknowledged packet was sent after the recorded end packet.
|
|
725
|
+
if self.end_of_app_limited_phase.is_none()
|
|
726
|
+
|| Some(packet_number) > self.end_of_app_limited_phase
|
|
752
727
|
{
|
|
753
728
|
self.is_app_limited = false;
|
|
754
729
|
}
|
|
@@ -756,12 +731,10 @@ impl BandwidthSampler {
|
|
|
756
731
|
|
|
757
732
|
// No send rate indicates that the sampler is supposed to discard the
|
|
758
733
|
// current send rate sample and use only the ack rate.
|
|
759
|
-
let send_rate = if sent_packet.sent_time >
|
|
760
|
-
sent_packet.last_acked_packet_sent_time
|
|
761
|
-
{
|
|
734
|
+
let send_rate = if sent_packet.sent_time > sent_packet.last_acked_packet_sent_time {
|
|
762
735
|
Some(Bandwidth::from_bytes_and_time_delta(
|
|
763
|
-
sent_packet.send_time_state.total_bytes_sent
|
|
764
|
-
sent_packet.total_bytes_sent_at_last_acked_packet,
|
|
736
|
+
sent_packet.send_time_state.total_bytes_sent
|
|
737
|
+
- sent_packet.total_bytes_sent_at_last_acked_packet,
|
|
765
738
|
sent_packet.sent_time - sent_packet.last_acked_packet_sent_time,
|
|
766
739
|
))
|
|
767
740
|
} else {
|
|
@@ -819,7 +792,8 @@ impl BandwidthSampler {
|
|
|
819
792
|
}
|
|
820
793
|
|
|
821
794
|
fn choose_a0_point(
|
|
822
|
-
a0_candidates: &mut VecDeque<AckPoint>,
|
|
795
|
+
a0_candidates: &mut VecDeque<AckPoint>,
|
|
796
|
+
total_bytes_acked: usize,
|
|
823
797
|
choose_a0_point_fix: bool,
|
|
824
798
|
) -> Option<AckPoint> {
|
|
825
799
|
if a0_candidates.is_empty() {
|
|
@@ -849,9 +823,7 @@ impl BandwidthSampler {
|
|
|
849
823
|
}
|
|
850
824
|
|
|
851
825
|
#[allow(dead_code)]
|
|
852
|
-
pub(crate) fn reset_max_ack_height_tracker(
|
|
853
|
-
&mut self, new_height: usize, new_time: usize,
|
|
854
|
-
) {
|
|
826
|
+
pub(crate) fn reset_max_ack_height_tracker(&mut self, new_height: usize, new_time: usize) {
|
|
855
827
|
self.max_ack_height_tracker.reset(new_height, new_time);
|
|
856
828
|
}
|
|
857
829
|
|
|
@@ -899,11 +871,7 @@ mod bandwidth_sampler_tests {
|
|
|
899
871
|
|
|
900
872
|
impl TestSender {
|
|
901
873
|
fn new(overestimate_avoidance: bool, choose_a0_point_fix: bool) -> Self {
|
|
902
|
-
let sampler = BandwidthSampler::new(
|
|
903
|
-
0,
|
|
904
|
-
overestimate_avoidance,
|
|
905
|
-
choose_a0_point_fix,
|
|
906
|
-
);
|
|
874
|
+
let sampler = BandwidthSampler::new(0, overestimate_avoidance, choose_a0_point_fix);
|
|
907
875
|
TestSender {
|
|
908
876
|
sampler_app_limited_at_start: sampler.is_app_limited(),
|
|
909
877
|
sampler,
|
|
@@ -996,9 +964,7 @@ mod bandwidth_sampler_tests {
|
|
|
996
964
|
sample.last_packet_send_state
|
|
997
965
|
}
|
|
998
966
|
|
|
999
|
-
fn on_congestion_event(
|
|
1000
|
-
&mut self, acked: &[u64], lost: &[u64],
|
|
1001
|
-
) -> CongestionEventSample {
|
|
967
|
+
fn on_congestion_event(&mut self, acked: &[u64], lost: &[u64]) -> CongestionEventSample {
|
|
1002
968
|
let acked = acked
|
|
1003
969
|
.iter()
|
|
1004
970
|
.map(|pkt| {
|
|
@@ -1027,16 +993,12 @@ mod bandwidth_sampler_tests {
|
|
|
1027
993
|
self.round_trip_count,
|
|
1028
994
|
);
|
|
1029
995
|
|
|
1030
|
-
self.max_bandwidth =
|
|
1031
|
-
self.max_bandwidth.max(sample.sample_max_bandwidth.unwrap());
|
|
996
|
+
self.max_bandwidth = self.max_bandwidth.max(sample.sample_max_bandwidth.unwrap());
|
|
1032
997
|
|
|
1033
998
|
sample
|
|
1034
999
|
}
|
|
1035
1000
|
|
|
1036
|
-
fn send_packet(
|
|
1037
|
-
&mut self, pkt_num: u64, pkt_sz: usize,
|
|
1038
|
-
has_retransmittable_data: bool,
|
|
1039
|
-
) {
|
|
1001
|
+
fn send_packet(&mut self, pkt_num: u64, pkt_sz: usize, has_retransmittable_data: bool) {
|
|
1040
1002
|
self.sampler.on_packet_sent(
|
|
1041
1003
|
self.clock,
|
|
1042
1004
|
pkt_num,
|
|
@@ -1062,8 +1024,8 @@ mod bandwidth_sampler_tests {
|
|
|
1062
1024
|
self.advance_time(time_between_packets);
|
|
1063
1025
|
}
|
|
1064
1026
|
|
|
1065
|
-
//
|
|
1066
|
-
// before.
|
|
1027
|
+
// Acknowledge packets 1 to 20 while sending new packets at the same
|
|
1028
|
+
// rate as before.
|
|
1067
1029
|
for i in 1..=20 {
|
|
1068
1030
|
self.ack_packet(i);
|
|
1069
1031
|
self.send_packet(i + 20, REGULAR_PACKET_SIZE, true);
|
|
@@ -1077,8 +1039,7 @@ mod bandwidth_sampler_tests {
|
|
|
1077
1039
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1078
1040
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1079
1041
|
) {
|
|
1080
|
-
let mut test_sender =
|
|
1081
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1042
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1082
1043
|
let mut time_between_packets = Duration::from_millis(10);
|
|
1083
1044
|
let mut expected_bandwidth =
|
|
1084
1045
|
Bandwidth::from_bytes_per_second(REGULAR_PACKET_SIZE as u64 * 100);
|
|
@@ -1112,8 +1073,7 @@ mod bandwidth_sampler_tests {
|
|
|
1112
1073
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1113
1074
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1114
1075
|
) {
|
|
1115
|
-
let mut test_sender =
|
|
1116
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1076
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1117
1077
|
let time_between_packets = Duration::from_millis(10);
|
|
1118
1078
|
|
|
1119
1079
|
// Send packets 1-5.
|
|
@@ -1182,21 +1142,15 @@ mod bandwidth_sampler_tests {
|
|
|
1182
1142
|
assert_eq!(0, send_time_state.total_bytes_acked);
|
|
1183
1143
|
assert_eq!(0, send_time_state.total_bytes_lost);
|
|
1184
1144
|
} else {
|
|
1185
|
-
assert_eq!(
|
|
1186
|
-
|
|
1187
|
-
send_time_state.total_bytes_acked
|
|
1188
|
-
);
|
|
1189
|
-
assert_eq!(
|
|
1190
|
-
REGULAR_PACKET_SIZE * 2,
|
|
1191
|
-
send_time_state.total_bytes_lost
|
|
1192
|
-
);
|
|
1145
|
+
assert_eq!(REGULAR_PACKET_SIZE, send_time_state.total_bytes_acked);
|
|
1146
|
+
assert_eq!(REGULAR_PACKET_SIZE * 2, send_time_state.total_bytes_lost);
|
|
1193
1147
|
}
|
|
1194
1148
|
|
|
1195
1149
|
// This equation works because there is no neutered bytes.
|
|
1196
1150
|
assert_eq!(
|
|
1197
|
-
send_time_state.total_bytes_sent
|
|
1198
|
-
send_time_state.total_bytes_acked
|
|
1199
|
-
send_time_state.total_bytes_lost,
|
|
1151
|
+
send_time_state.total_bytes_sent
|
|
1152
|
+
- send_time_state.total_bytes_acked
|
|
1153
|
+
- send_time_state.total_bytes_lost,
|
|
1200
1154
|
send_time_state.bytes_in_flight
|
|
1201
1155
|
);
|
|
1202
1156
|
|
|
@@ -1211,11 +1165,9 @@ mod bandwidth_sampler_tests {
|
|
|
1211
1165
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1212
1166
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1213
1167
|
) {
|
|
1214
|
-
let mut test_sender =
|
|
1215
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1168
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1216
1169
|
let time_between_packets = Duration::from_millis(1);
|
|
1217
|
-
let expected_bandwidth =
|
|
1218
|
-
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1170
|
+
let expected_bandwidth = Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1219
1171
|
|
|
1220
1172
|
test_sender.send_40_and_ack_first_20(time_between_packets);
|
|
1221
1173
|
|
|
@@ -1237,8 +1189,7 @@ mod bandwidth_sampler_tests {
|
|
|
1237
1189
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1238
1190
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1239
1191
|
) {
|
|
1240
|
-
let mut test_sender =
|
|
1241
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1192
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1242
1193
|
let time_between_packets = Duration::from_millis(1);
|
|
1243
1194
|
let expected_bandwidth =
|
|
1244
1195
|
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 / 2 * 8);
|
|
@@ -1285,8 +1236,7 @@ mod bandwidth_sampler_tests {
|
|
|
1285
1236
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1286
1237
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1287
1238
|
) {
|
|
1288
|
-
let mut test_sender =
|
|
1289
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1239
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1290
1240
|
let time_between_packets = Duration::from_millis(1);
|
|
1291
1241
|
let expected_bandwidth =
|
|
1292
1242
|
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 / 2 * 8);
|
|
@@ -1295,29 +1245,21 @@ mod bandwidth_sampler_tests {
|
|
|
1295
1245
|
// controlled.
|
|
1296
1246
|
for i in 1..=20 {
|
|
1297
1247
|
let has_retransmittable_data = i % 2 == 0;
|
|
1298
|
-
test_sender.send_packet(
|
|
1299
|
-
i,
|
|
1300
|
-
REGULAR_PACKET_SIZE,
|
|
1301
|
-
has_retransmittable_data,
|
|
1302
|
-
);
|
|
1248
|
+
test_sender.send_packet(i, REGULAR_PACKET_SIZE, has_retransmittable_data);
|
|
1303
1249
|
test_sender.advance_time(time_between_packets);
|
|
1304
1250
|
}
|
|
1305
1251
|
|
|
1306
1252
|
// Ensure only congestion controlled packets are tracked.
|
|
1307
1253
|
assert_eq!(10, test_sender.number_of_tracked_packets());
|
|
1308
1254
|
|
|
1309
|
-
//
|
|
1310
|
-
// new packets at the same rate as before.
|
|
1255
|
+
// Acknowledge packets 2 to 21, ignoring every even-numbered packet,
|
|
1256
|
+
// while sending new packets at the same rate as before.
|
|
1311
1257
|
for i in 1..=20 {
|
|
1312
1258
|
if i % 2 == 0 {
|
|
1313
1259
|
test_sender.ack_packet(i);
|
|
1314
1260
|
}
|
|
1315
1261
|
let has_retransmittable_data = i % 2 == 0;
|
|
1316
|
-
test_sender.send_packet(
|
|
1317
|
-
i + 20,
|
|
1318
|
-
REGULAR_PACKET_SIZE,
|
|
1319
|
-
has_retransmittable_data,
|
|
1320
|
-
);
|
|
1262
|
+
test_sender.send_packet(i + 20, REGULAR_PACKET_SIZE, has_retransmittable_data);
|
|
1321
1263
|
test_sender.advance_time(time_between_packets);
|
|
1322
1264
|
}
|
|
1323
1265
|
|
|
@@ -1344,11 +1286,9 @@ mod bandwidth_sampler_tests {
|
|
|
1344
1286
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1345
1287
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1346
1288
|
) {
|
|
1347
|
-
let mut test_sender =
|
|
1348
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1289
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1349
1290
|
let time_between_packets = Duration::from_millis(1);
|
|
1350
|
-
let expected_bandwidth =
|
|
1351
|
-
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1291
|
+
let expected_bandwidth = Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1352
1292
|
|
|
1353
1293
|
test_sender.send_40_and_ack_first_20(time_between_packets);
|
|
1354
1294
|
|
|
@@ -1377,16 +1317,14 @@ mod bandwidth_sampler_tests {
|
|
|
1377
1317
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1378
1318
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1379
1319
|
) {
|
|
1380
|
-
let mut test_sender =
|
|
1381
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1320
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1382
1321
|
let time_between_packets = Duration::from_millis(1);
|
|
1383
|
-
let expected_bandwidth =
|
|
1384
|
-
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1322
|
+
let expected_bandwidth = Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1385
1323
|
|
|
1386
1324
|
test_sender.send_40_and_ack_first_20(time_between_packets);
|
|
1387
1325
|
|
|
1388
|
-
//
|
|
1389
|
-
// to 60.
|
|
1326
|
+
// Acknowledge packets 21 to 40 in reverse order while sending packets
|
|
1327
|
+
// 41 to 60.
|
|
1390
1328
|
for i in 0..20 {
|
|
1391
1329
|
let last_bandwidth = test_sender.ack_packet(40 - i).bandwidth;
|
|
1392
1330
|
assert_eq!(expected_bandwidth, last_bandwidth);
|
|
@@ -1412,11 +1350,9 @@ mod bandwidth_sampler_tests {
|
|
|
1412
1350
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1413
1351
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1414
1352
|
) {
|
|
1415
|
-
let mut test_sender =
|
|
1416
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1353
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1417
1354
|
let time_between_packets = Duration::from_millis(1);
|
|
1418
|
-
let expected_bandwidth =
|
|
1419
|
-
Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1355
|
+
let expected_bandwidth = Bandwidth::from_kbits_per_second(REGULAR_PACKET_SIZE as u64 * 8);
|
|
1420
1356
|
|
|
1421
1357
|
for i in 1..=20 {
|
|
1422
1358
|
test_sender.send_packet(i, REGULAR_PACKET_SIZE, true);
|
|
@@ -1426,16 +1362,15 @@ mod bandwidth_sampler_tests {
|
|
|
1426
1362
|
for i in 1..=20 {
|
|
1427
1363
|
let sample = test_sender.ack_packet(i);
|
|
1428
1364
|
assert_eq!(
|
|
1429
|
-
sample.state_at_send.is_app_limited,
|
|
1430
|
-
test_sender.sampler_app_limited_at_start,
|
|
1365
|
+
sample.state_at_send.is_app_limited, test_sender.sampler_app_limited_at_start,
|
|
1431
1366
|
"{i}"
|
|
1432
1367
|
);
|
|
1433
1368
|
test_sender.send_packet(i + 20, REGULAR_PACKET_SIZE, true);
|
|
1434
1369
|
test_sender.advance_time(time_between_packets);
|
|
1435
1370
|
}
|
|
1436
1371
|
|
|
1437
|
-
// We are now app-limited.
|
|
1438
|
-
// for now.
|
|
1372
|
+
// We are now app-limited. Acknowledge 21 to 40 as usual, but do not
|
|
1373
|
+
// send anything for now.
|
|
1439
1374
|
test_sender.sampler.on_app_limited();
|
|
1440
1375
|
for i in 21..=40 {
|
|
1441
1376
|
let sample = test_sender.ack_packet(i);
|
|
@@ -1453,8 +1388,8 @@ mod bandwidth_sampler_tests {
|
|
|
1453
1388
|
test_sender.advance_time(time_between_packets);
|
|
1454
1389
|
}
|
|
1455
1390
|
|
|
1456
|
-
//
|
|
1457
|
-
//
|
|
1391
|
+
// Acknowledge packets 41 to 60 while sending packets 61 to 80. These
|
|
1392
|
+
// app-limited ACKs should underestimate bandwidth.
|
|
1458
1393
|
for i in 41..=60 {
|
|
1459
1394
|
let sample = test_sender.ack_packet(i);
|
|
1460
1395
|
assert!(sample.state_at_send.is_app_limited, "{i}");
|
|
@@ -1467,8 +1402,8 @@ mod bandwidth_sampler_tests {
|
|
|
1467
1402
|
expected_bandwidth * 0.7
|
|
1468
1403
|
);
|
|
1469
1404
|
} else {
|
|
1470
|
-
// Needs further investigation
|
|
1471
|
-
// sample.bandwidth
|
|
1405
|
+
// Needs further investigation. With `overestimate_avoidance`,
|
|
1406
|
+
// `sample.bandwidth` rises 17 packets too soon.
|
|
1472
1407
|
assert_eq!(sample.bandwidth, expected_bandwidth, "{i}");
|
|
1473
1408
|
}
|
|
1474
1409
|
test_sender.send_packet(i + 20, REGULAR_PACKET_SIZE, true);
|
|
@@ -1495,8 +1430,7 @@ mod bandwidth_sampler_tests {
|
|
|
1495
1430
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1496
1431
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1497
1432
|
) {
|
|
1498
|
-
let mut test_sender =
|
|
1499
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1433
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1500
1434
|
let time_between_packets = Duration::from_millis(1);
|
|
1501
1435
|
let rtt = Duration::from_millis(800);
|
|
1502
1436
|
let num_packets = 10;
|
|
@@ -1517,9 +1451,8 @@ mod bandwidth_sampler_tests {
|
|
|
1517
1451
|
test_sender.advance_time(time_between_packets);
|
|
1518
1452
|
}
|
|
1519
1453
|
|
|
1520
|
-
// The final
|
|
1521
|
-
//
|
|
1522
|
-
// than 10%. The specific value of the error depends on the
|
|
1454
|
+
// The final sample for the first flight should underestimate the real
|
|
1455
|
+
// bandwidth by no more than 10%. The exact error depends on the
|
|
1523
1456
|
// difference between the RTT and the time it takes to exhaust the
|
|
1524
1457
|
// congestion window (i.e. in the limit when all packets are sent
|
|
1525
1458
|
// simultaneously, last sample would indicate the real bandwidth).
|
|
@@ -1533,8 +1466,7 @@ mod bandwidth_sampler_tests {
|
|
|
1533
1466
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1534
1467
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1535
1468
|
) {
|
|
1536
|
-
let mut test_sender =
|
|
1537
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1469
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1538
1470
|
|
|
1539
1471
|
for i in 1..=5 {
|
|
1540
1472
|
test_sender.send_packet(i, REGULAR_PACKET_SIZE, true);
|
|
@@ -1556,8 +1488,7 @@ mod bandwidth_sampler_tests {
|
|
|
1556
1488
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1557
1489
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1558
1490
|
) {
|
|
1559
|
-
let mut test_sender =
|
|
1560
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1491
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1561
1492
|
test_sender.send_packet(1, REGULAR_PACKET_SIZE, true);
|
|
1562
1493
|
assert_eq!(test_sender.sampler.total_bytes_neutered, 0);
|
|
1563
1494
|
test_sender.advance_time(Duration::from_millis(10));
|
|
@@ -1607,13 +1538,10 @@ mod bandwidth_sampler_tests {
|
|
|
1607
1538
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1608
1539
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1609
1540
|
) {
|
|
1610
|
-
let mut test_sender =
|
|
1611
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1541
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1612
1542
|
let time_between_packets = Duration::from_millis(10);
|
|
1613
|
-
let sending_rate =
|
|
1614
|
-
REGULAR_PACKET_SIZE,
|
|
1615
|
-
time_between_packets,
|
|
1616
|
-
);
|
|
1543
|
+
let sending_rate =
|
|
1544
|
+
Bandwidth::from_bytes_and_time_delta(REGULAR_PACKET_SIZE, time_between_packets);
|
|
1617
1545
|
|
|
1618
1546
|
for i in 1..21 {
|
|
1619
1547
|
test_sender.send_packet(i, REGULAR_PACKET_SIZE, true);
|
|
@@ -1649,13 +1577,10 @@ mod bandwidth_sampler_tests {
|
|
|
1649
1577
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1650
1578
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1651
1579
|
) {
|
|
1652
|
-
let mut test_sender =
|
|
1653
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1580
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1654
1581
|
let time_between_packets = Duration::from_millis(10);
|
|
1655
|
-
let sending_rate =
|
|
1656
|
-
REGULAR_PACKET_SIZE,
|
|
1657
|
-
time_between_packets,
|
|
1658
|
-
);
|
|
1582
|
+
let sending_rate =
|
|
1583
|
+
Bandwidth::from_bytes_and_time_delta(REGULAR_PACKET_SIZE, time_between_packets);
|
|
1659
1584
|
|
|
1660
1585
|
for i in 1..21 {
|
|
1661
1586
|
test_sender.send_packet(i, REGULAR_PACKET_SIZE, true);
|
|
@@ -1696,13 +1621,10 @@ mod bandwidth_sampler_tests {
|
|
|
1696
1621
|
#[values(false, true)] overestimate_avoidance: bool,
|
|
1697
1622
|
#[values(false, true)] choose_a0_point_fix: bool,
|
|
1698
1623
|
) {
|
|
1699
|
-
let mut test_sender =
|
|
1700
|
-
TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1624
|
+
let mut test_sender = TestSender::new(overestimate_avoidance, choose_a0_point_fix);
|
|
1701
1625
|
let time_between_packets = Duration::from_millis(10);
|
|
1702
|
-
let first_packet_sending_rate =
|
|
1703
|
-
REGULAR_PACKET_SIZE,
|
|
1704
|
-
time_between_packets,
|
|
1705
|
-
);
|
|
1626
|
+
let first_packet_sending_rate =
|
|
1627
|
+
Bandwidth::from_bytes_and_time_delta(REGULAR_PACKET_SIZE, time_between_packets);
|
|
1706
1628
|
|
|
1707
1629
|
// Send packets 1 to 4 and ack packet 1.
|
|
1708
1630
|
test_sender.send_packet(1, REGULAR_PACKET_SIZE, true);
|
|
@@ -1755,8 +1677,7 @@ mod max_ack_height_tracker_tests {
|
|
|
1755
1677
|
|
|
1756
1678
|
impl TestTracker {
|
|
1757
1679
|
fn new(overestimate_avoidance: bool) -> Self {
|
|
1758
|
-
let mut tracker =
|
|
1759
|
-
MaxAckHeightTracker::new(10, overestimate_avoidance);
|
|
1680
|
+
let mut tracker = MaxAckHeightTracker::new(10, overestimate_avoidance);
|
|
1760
1681
|
tracker.ack_aggregation_bandwidth_threshold = 1.8;
|
|
1761
1682
|
tracker.start_new_aggregation_epoch_after_full_round = true;
|
|
1762
1683
|
let start = Instant::now();
|
|
@@ -1777,28 +1698,27 @@ mod max_ack_height_tracker_tests {
|
|
|
1777
1698
|
// which any ack event will cause tracker_.Update() to start a new
|
|
1778
1699
|
// aggregation.
|
|
1779
1700
|
fn aggregation_episode(
|
|
1780
|
-
&mut self,
|
|
1781
|
-
|
|
1701
|
+
&mut self,
|
|
1702
|
+
aggregation_bandwidth: Bandwidth,
|
|
1703
|
+
aggregation_duration: Duration,
|
|
1704
|
+
bytes_per_ack: usize,
|
|
1782
1705
|
expect_new_aggregation_epoch: bool,
|
|
1783
1706
|
) {
|
|
1784
1707
|
assert!(aggregation_bandwidth >= self.bandwidth);
|
|
1785
1708
|
let start_time = self.now;
|
|
1786
1709
|
|
|
1787
|
-
let aggregation_bytes =
|
|
1788
|
-
(aggregation_bandwidth * aggregation_duration) as usize;
|
|
1710
|
+
let aggregation_bytes = (aggregation_bandwidth * aggregation_duration) as usize;
|
|
1789
1711
|
|
|
1790
1712
|
let num_acks = aggregation_bytes / bytes_per_ack;
|
|
1791
1713
|
assert_eq!(aggregation_bytes, num_acks * bytes_per_ack);
|
|
1792
1714
|
|
|
1793
|
-
let time_between_acks =
|
|
1794
|
-
aggregation_duration.as_micros() as u64 / num_acks as u64
|
|
1795
|
-
);
|
|
1715
|
+
let time_between_acks =
|
|
1716
|
+
Duration::from_micros(aggregation_duration.as_micros() as u64 / num_acks as u64);
|
|
1796
1717
|
assert_eq!(aggregation_duration, time_between_acks * num_acks as u32);
|
|
1797
1718
|
|
|
1798
1719
|
// The total duration of aggregation time and quiet period.
|
|
1799
1720
|
let total_duration = Duration::from_micros(
|
|
1800
|
-
(aggregation_bytes as u64 * 8 * 1000000) /
|
|
1801
|
-
self.bandwidth.to_bits_per_second(),
|
|
1721
|
+
(aggregation_bytes as u64 * 8 * 1000000) / self.bandwidth.to_bits_per_second(),
|
|
1802
1722
|
);
|
|
1803
1723
|
|
|
1804
1724
|
assert_eq!(aggregation_bytes as u64, self.bandwidth * total_duration);
|
|
@@ -1820,8 +1740,8 @@ mod max_ack_height_tracker_tests {
|
|
|
1820
1740
|
// and the the current tracker implementation
|
|
1821
1741
|
// can identify it, or [2] We are not really
|
|
1822
1742
|
// aggregating acks.
|
|
1823
|
-
if (bytes == 0 && expect_new_aggregation_epoch)
|
|
1824
|
-
(aggregation_bandwidth == self.bandwidth)
|
|
1743
|
+
if (bytes == 0 && expect_new_aggregation_epoch)
|
|
1744
|
+
|| (aggregation_bandwidth == self.bandwidth)
|
|
1825
1745
|
{
|
|
1826
1746
|
assert_eq!(0, extra_acked);
|
|
1827
1747
|
} else {
|
|
@@ -1841,8 +1761,10 @@ mod max_ack_height_tracker_tests {
|
|
|
1841
1761
|
}
|
|
1842
1762
|
|
|
1843
1763
|
fn test_inner(
|
|
1844
|
-
overestimate_avoidance: bool,
|
|
1845
|
-
|
|
1764
|
+
overestimate_avoidance: bool,
|
|
1765
|
+
bandwidth_gain: f64,
|
|
1766
|
+
agg_duration: Duration,
|
|
1767
|
+
byte_per_ack: usize,
|
|
1846
1768
|
) {
|
|
1847
1769
|
let mut test_tracker = TestTracker::new(overestimate_avoidance);
|
|
1848
1770
|
|
|
@@ -1873,30 +1795,22 @@ mod max_ack_height_tracker_tests {
|
|
|
1873
1795
|
}
|
|
1874
1796
|
|
|
1875
1797
|
#[rstest]
|
|
1876
|
-
fn very_aggregated_large_acks(
|
|
1877
|
-
#[values(false, true)] overestimate_avoidance: bool,
|
|
1878
|
-
) {
|
|
1798
|
+
fn very_aggregated_large_acks(#[values(false, true)] overestimate_avoidance: bool) {
|
|
1879
1799
|
test_inner(overestimate_avoidance, 20.0, Duration::from_millis(6), 1200)
|
|
1880
1800
|
}
|
|
1881
1801
|
|
|
1882
1802
|
#[rstest]
|
|
1883
|
-
fn very_aggregated_small_acks(
|
|
1884
|
-
#[values(false, true)] overestimate_avoidance: bool,
|
|
1885
|
-
) {
|
|
1803
|
+
fn very_aggregated_small_acks(#[values(false, true)] overestimate_avoidance: bool) {
|
|
1886
1804
|
test_inner(overestimate_avoidance, 20., Duration::from_millis(6), 300)
|
|
1887
1805
|
}
|
|
1888
1806
|
|
|
1889
1807
|
#[rstest]
|
|
1890
|
-
fn somewhat_aggregated_large_acks(
|
|
1891
|
-
#[values(false, true)] overestimate_avoidance: bool,
|
|
1892
|
-
) {
|
|
1808
|
+
fn somewhat_aggregated_large_acks(#[values(false, true)] overestimate_avoidance: bool) {
|
|
1893
1809
|
test_inner(overestimate_avoidance, 2.0, Duration::from_millis(50), 1000)
|
|
1894
1810
|
}
|
|
1895
1811
|
|
|
1896
1812
|
#[rstest]
|
|
1897
|
-
fn somewhat_aggregated_small_acks(
|
|
1898
|
-
#[values(false, true)] overestimate_avoidance: bool,
|
|
1899
|
-
) {
|
|
1813
|
+
fn somewhat_aggregated_small_acks(#[values(false, true)] overestimate_avoidance: bool) {
|
|
1900
1814
|
test_inner(overestimate_avoidance, 2.0, Duration::from_millis(50), 100)
|
|
1901
1815
|
}
|
|
1902
1816
|
|
|
@@ -1913,9 +1827,7 @@ mod max_ack_height_tracker_tests {
|
|
|
1913
1827
|
}
|
|
1914
1828
|
|
|
1915
1829
|
#[rstest]
|
|
1916
|
-
fn start_new_epoch_after_a_full_round(
|
|
1917
|
-
#[values(false, true)] overestimate_avoidance: bool,
|
|
1918
|
-
) {
|
|
1830
|
+
fn start_new_epoch_after_a_full_round(#[values(false, true)] overestimate_avoidance: bool) {
|
|
1919
1831
|
let mut test_tracker = TestTracker::new(overestimate_avoidance);
|
|
1920
1832
|
|
|
1921
1833
|
test_tracker.last_sent_packet_number = 10;
|