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
|
@@ -59,7 +59,9 @@ impl ProbeRTT {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
fn into_probe_bw(
|
|
62
|
-
mut self,
|
|
62
|
+
mut self,
|
|
63
|
+
now: Instant,
|
|
64
|
+
congestion_event: Option<&BBRv2CongestionEvent>,
|
|
63
65
|
params: &Params,
|
|
64
66
|
) -> Mode {
|
|
65
67
|
self.leave(now, congestion_event);
|
|
@@ -87,29 +89,31 @@ impl ModeImpl for ProbeRTT {
|
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
fn on_congestion_event(
|
|
90
|
-
mut self,
|
|
91
|
-
|
|
92
|
+
mut self,
|
|
93
|
+
_prior_in_flight: usize,
|
|
94
|
+
event_time: Instant,
|
|
95
|
+
_acked_packets: &[Acked],
|
|
96
|
+
_lost_packets: &[Lost],
|
|
92
97
|
congestion_event: &mut BBRv2CongestionEvent,
|
|
93
|
-
_target_bytes_inflight: usize,
|
|
94
|
-
|
|
98
|
+
_target_bytes_inflight: usize,
|
|
99
|
+
params: &Params,
|
|
100
|
+
_recovery_stats: &mut RecoveryStats,
|
|
101
|
+
_cwnd: usize,
|
|
95
102
|
) -> Mode {
|
|
96
103
|
match self.exit_time {
|
|
97
104
|
None => {
|
|
98
|
-
if congestion_event.bytes_in_flight <=
|
|
99
|
-
self.
|
|
100
|
-
{
|
|
101
|
-
self.exit_time = Some(
|
|
102
|
-
congestion_event.event_time + params.probe_rtt_duration,
|
|
103
|
-
)
|
|
105
|
+
if congestion_event.bytes_in_flight <= self.inflight_target(params) {
|
|
106
|
+
self.exit_time = Some(congestion_event.event_time + params.probe_rtt_duration)
|
|
104
107
|
}
|
|
105
108
|
Mode::ProbeRTT(self)
|
|
106
|
-
}
|
|
107
|
-
Some(exit_time) =>
|
|
109
|
+
}
|
|
110
|
+
Some(exit_time) => {
|
|
108
111
|
if congestion_event.event_time > exit_time {
|
|
109
112
|
self.into_probe_bw(event_time, Some(congestion_event), params)
|
|
110
113
|
} else {
|
|
111
114
|
Mode::ProbeRTT(self)
|
|
112
|
-
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
113
117
|
}
|
|
114
118
|
}
|
|
115
119
|
|
|
@@ -118,36 +122,34 @@ impl ModeImpl for ProbeRTT {
|
|
|
118
122
|
.model
|
|
119
123
|
.inflight_lo()
|
|
120
124
|
.min(self.model.inflight_hi_with_headroom(params));
|
|
121
|
-
Limits::no_greater_than(
|
|
122
|
-
inflight_upper_bound.min(self.inflight_target(params)),
|
|
123
|
-
)
|
|
125
|
+
Limits::no_greater_than(inflight_upper_bound.min(self.inflight_target(params)))
|
|
124
126
|
}
|
|
125
127
|
|
|
126
128
|
fn on_exit_quiescence(
|
|
127
|
-
self,
|
|
129
|
+
self,
|
|
130
|
+
now: Instant,
|
|
131
|
+
_quiescence_start_time: Instant,
|
|
132
|
+
params: &Params,
|
|
128
133
|
) -> Mode {
|
|
129
134
|
match self.exit_time {
|
|
130
135
|
None => self.into_probe_bw(now, None, params),
|
|
131
|
-
Some(exit_time) if now > exit_time =>
|
|
132
|
-
self.into_probe_bw(now, None, params),
|
|
136
|
+
Some(exit_time) if now > exit_time => self.into_probe_bw(now, None, params),
|
|
133
137
|
Some(_) => Mode::ProbeRTT(self),
|
|
134
138
|
}
|
|
135
139
|
}
|
|
136
140
|
|
|
137
141
|
fn enter(
|
|
138
|
-
&mut self,
|
|
139
|
-
|
|
142
|
+
&mut self,
|
|
143
|
+
_now: Instant,
|
|
144
|
+
_congestion_event: Option<&BBRv2CongestionEvent>,
|
|
145
|
+
params: &Params,
|
|
140
146
|
) {
|
|
141
147
|
self.model.set_pacing_gain(params.probe_rtt_pacing_gain);
|
|
142
148
|
self.model.set_cwnd_gain(params.probe_rtt_cwnd_gain);
|
|
143
149
|
self.exit_time = None;
|
|
144
150
|
}
|
|
145
151
|
|
|
146
|
-
fn leave(
|
|
147
|
-
&mut self, _now: Instant,
|
|
148
|
-
_congestion_event: Option<&BBRv2CongestionEvent>,
|
|
149
|
-
) {
|
|
150
|
-
}
|
|
152
|
+
fn leave(&mut self, _now: Instant, _congestion_event: Option<&BBRv2CongestionEvent>) {}
|
|
151
153
|
}
|
|
152
154
|
|
|
153
155
|
#[cfg(test)]
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
// Copyright (C) 2026, Cloudflare, Inc.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
|
5
|
+
// modification, are permitted provided that the following conditions are
|
|
6
|
+
// met:
|
|
7
|
+
//
|
|
8
|
+
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
// this list of conditions and the following disclaimer.
|
|
10
|
+
//
|
|
11
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
// documentation and/or other materials provided with the distribution.
|
|
14
|
+
//
|
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
|
|
27
|
+
use std::time::Duration;
|
|
28
|
+
use std::time::Instant;
|
|
29
|
+
|
|
30
|
+
use super::RttJumpUpdate;
|
|
31
|
+
|
|
32
|
+
// An RTT jump is a sustained RTT increase above the connection-lifetime minimum
|
|
33
|
+
// RTT. The GlobalMin detector treats samples above 3x that baseline as
|
|
34
|
+
// elevated, counts a jump only after repeated elevated samples persist for a
|
|
35
|
+
// baseline-scaled dwell period, and clears the episode when RTT falls back to
|
|
36
|
+
// 3x baseline or below.
|
|
37
|
+
//
|
|
38
|
+
// GlobalMin episode lifecycle:
|
|
39
|
+
//
|
|
40
|
+
// elevated sustained elevated clear
|
|
41
|
+
// Idle -------> Active -----------------> Persistent
|
|
42
|
+
// ^ | |
|
|
43
|
+
// | | clear | clear
|
|
44
|
+
// +--------------+---------------------------+
|
|
45
|
+
//
|
|
46
|
+
// Sample trace:
|
|
47
|
+
//
|
|
48
|
+
// __A__ __P__
|
|
49
|
+
// __A__| | __A__A__| |__P__
|
|
50
|
+
// | | | |
|
|
51
|
+
// I__| |___I___| |___I
|
|
52
|
+
// I__|
|
|
53
|
+
//
|
|
54
|
+
// I = Idle
|
|
55
|
+
// A = Active
|
|
56
|
+
// P = Persistent
|
|
57
|
+
|
|
58
|
+
/// Tracks the lifecycle of a global-min RTT jump episode.
|
|
59
|
+
#[derive(Debug, Default, Clone, Copy)]
|
|
60
|
+
enum GlobalMinEpisode {
|
|
61
|
+
/// No elevation currently observed.
|
|
62
|
+
#[default]
|
|
63
|
+
Idle,
|
|
64
|
+
/// A jump has been observed but not yet sustained long enough to be
|
|
65
|
+
/// considered persistent.
|
|
66
|
+
Active {
|
|
67
|
+
elevated_samples: usize,
|
|
68
|
+
episode_start_time: Instant,
|
|
69
|
+
},
|
|
70
|
+
/// The elevated RTT has been confirmed as a persistent network condition.
|
|
71
|
+
Persistent,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Multiplicative factor over the global-min RTT baseline above which a sample
|
|
75
|
+
/// is classified as an RTT jump.
|
|
76
|
+
const GLOBAL_MIN_JUMP_THRESHOLD: f32 = 3.0;
|
|
77
|
+
|
|
78
|
+
/// Elevated RTT samples required before an active episode becomes persistent.
|
|
79
|
+
const GLOBAL_MIN_CONFIRM_SAMPLES: usize = 3;
|
|
80
|
+
|
|
81
|
+
/// Minimum episode duration, expressed as a multiple of the global-min RTT
|
|
82
|
+
/// baseline, required before an active episode becomes persistent.
|
|
83
|
+
const GLOBAL_MIN_CONFIRM_DURATION_MULTIPLIER: u32 = 3;
|
|
84
|
+
|
|
85
|
+
#[derive(Debug, Default)]
|
|
86
|
+
pub(super) struct GlobalMinDetector {
|
|
87
|
+
/// Connection-lifetime minimum RTT sample used by the detector.
|
|
88
|
+
baseline: Option<Duration>,
|
|
89
|
+
/// Lifecycle state used to distinguish transient RTT spikes from persistent
|
|
90
|
+
/// increases.
|
|
91
|
+
episode: GlobalMinEpisode,
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
impl GlobalMinDetector {
|
|
95
|
+
/// Global-min RTT jump detector step: connection-lifetime minimum baseline
|
|
96
|
+
/// with a strict multiplicative jump test and a sample/duration
|
|
97
|
+
/// confirmation gate.
|
|
98
|
+
pub(super) fn on_rtt_sample(
|
|
99
|
+
&mut self,
|
|
100
|
+
rtt_sample: Duration,
|
|
101
|
+
event_time: Instant,
|
|
102
|
+
full_bandwidth_reached: bool,
|
|
103
|
+
) -> RttJumpUpdate {
|
|
104
|
+
if !full_bandwidth_reached {
|
|
105
|
+
self.update_baseline(rtt_sample);
|
|
106
|
+
return RttJumpUpdate::None;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let Some(baseline) = self.baseline else {
|
|
110
|
+
self.update_baseline(rtt_sample);
|
|
111
|
+
return RttJumpUpdate::None;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
let is_jump = rtt_sample > baseline.mul_f32(GLOBAL_MIN_JUMP_THRESHOLD);
|
|
115
|
+
let is_clear = !is_jump;
|
|
116
|
+
let mut update = RttJumpUpdate::None;
|
|
117
|
+
|
|
118
|
+
match self.episode {
|
|
119
|
+
GlobalMinEpisode::Idle => {
|
|
120
|
+
if is_jump {
|
|
121
|
+
self.episode = GlobalMinEpisode::Active {
|
|
122
|
+
elevated_samples: 1,
|
|
123
|
+
episode_start_time: event_time,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
GlobalMinEpisode::Active {
|
|
129
|
+
elevated_samples,
|
|
130
|
+
episode_start_time,
|
|
131
|
+
} => {
|
|
132
|
+
if is_clear {
|
|
133
|
+
self.episode = GlobalMinEpisode::Idle;
|
|
134
|
+
} else {
|
|
135
|
+
let elevated_samples = elevated_samples + 1;
|
|
136
|
+
let dwell = baseline * GLOBAL_MIN_CONFIRM_DURATION_MULTIPLIER;
|
|
137
|
+
let samples_ok = elevated_samples >= GLOBAL_MIN_CONFIRM_SAMPLES;
|
|
138
|
+
let time_ok = event_time.saturating_duration_since(episode_start_time) >= dwell;
|
|
139
|
+
|
|
140
|
+
if samples_ok && time_ok {
|
|
141
|
+
update = RttJumpUpdate::PersistentConfirmed { episode_start_time };
|
|
142
|
+
self.episode = GlobalMinEpisode::Persistent;
|
|
143
|
+
} else {
|
|
144
|
+
self.episode = GlobalMinEpisode::Active {
|
|
145
|
+
elevated_samples,
|
|
146
|
+
episode_start_time,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
GlobalMinEpisode::Persistent => {
|
|
153
|
+
if is_clear {
|
|
154
|
+
self.episode = GlobalMinEpisode::Idle;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
self.update_baseline(rtt_sample);
|
|
160
|
+
update
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
fn update_baseline(&mut self, rtt_sample: Duration) {
|
|
164
|
+
self.baseline = Some(self.baseline.map_or(rtt_sample, |min| min.min(rtt_sample)));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
#[cfg(test)]
|
|
168
|
+
pub(super) fn is_rtt_jump_active(&self) -> bool {
|
|
169
|
+
!matches!(self.episode, GlobalMinEpisode::Idle)
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#[cfg(test)]
|
|
173
|
+
pub(super) fn is_rtt_jump_persistent(&self) -> bool {
|
|
174
|
+
matches!(self.episode, GlobalMinEpisode::Persistent)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#[cfg(test)]
|
|
179
|
+
#[path = "global_min_tests.rs"]
|
|
180
|
+
mod tests;
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
// Copyright (C) 2026, Cloudflare, Inc.
|
|
2
|
+
// All rights reserved.
|
|
3
|
+
//
|
|
4
|
+
// Redistribution and use in source and binary forms, with or without
|
|
5
|
+
// modification, are permitted provided that the following conditions are
|
|
6
|
+
// met:
|
|
7
|
+
//
|
|
8
|
+
// * Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
// this list of conditions and the following disclaimer.
|
|
10
|
+
//
|
|
11
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
// documentation and/or other materials provided with the distribution.
|
|
14
|
+
//
|
|
15
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
16
|
+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
17
|
+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
18
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
19
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
20
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
22
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
23
|
+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
24
|
+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
25
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
26
|
+
|
|
27
|
+
use std::time::Duration;
|
|
28
|
+
use std::time::Instant;
|
|
29
|
+
|
|
30
|
+
use crate::recovery::gcongestion::BbrRttJumpDetector;
|
|
31
|
+
|
|
32
|
+
use super::super::RttJumpDetector;
|
|
33
|
+
use super::*;
|
|
34
|
+
|
|
35
|
+
const RTT: Duration = Duration::from_millis(50);
|
|
36
|
+
const RTT_3X: Duration = Duration::from_millis(150);
|
|
37
|
+
const RTT_JUMP: Duration = Duration::from_millis(151);
|
|
38
|
+
const LOW_RTT: Duration = Duration::from_millis(10);
|
|
39
|
+
const HIGH_RTT: Duration = Duration::from_millis(500);
|
|
40
|
+
const HIGH_RTT_JUMP: Duration = Duration::from_millis(1501);
|
|
41
|
+
|
|
42
|
+
fn ms(millis: u64) -> Duration {
|
|
43
|
+
Duration::from_millis(millis)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fn sample(detector: &mut RttJumpDetector, base: Instant, offset: Duration, rtt: Duration) {
|
|
47
|
+
sample_with_full_bandwidth(detector, base, offset, rtt, true);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fn sample_with_full_bandwidth(
|
|
51
|
+
detector: &mut RttJumpDetector,
|
|
52
|
+
base: Instant,
|
|
53
|
+
offset: Duration,
|
|
54
|
+
rtt: Duration,
|
|
55
|
+
full_bandwidth_reached: bool,
|
|
56
|
+
) {
|
|
57
|
+
detector.on_rtt_sample(rtt, base + offset, full_bandwidth_reached);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fn global_min_detector() -> RttJumpDetector {
|
|
61
|
+
RttJumpDetector::new(BbrRttJumpDetector::GlobalMin)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[test]
|
|
65
|
+
fn global_min_detector_uses_strict_3x_threshold() {
|
|
66
|
+
let base = Instant::now();
|
|
67
|
+
|
|
68
|
+
let mut at_edge = global_min_detector();
|
|
69
|
+
sample(&mut at_edge, base, ms(10), RTT);
|
|
70
|
+
sample(&mut at_edge, base, ms(20), RTT_3X);
|
|
71
|
+
assert!(!at_edge.is_rtt_jump_active());
|
|
72
|
+
|
|
73
|
+
let mut just_above = global_min_detector();
|
|
74
|
+
sample(&mut just_above, base, ms(10), RTT);
|
|
75
|
+
sample(&mut just_above, base, ms(20), RTT_JUMP);
|
|
76
|
+
assert!(just_above.is_rtt_jump_active());
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
#[test]
|
|
80
|
+
fn global_min_detector_clears_active_at_or_below_threshold() {
|
|
81
|
+
let base = Instant::now();
|
|
82
|
+
|
|
83
|
+
let mut at_edge = global_min_detector();
|
|
84
|
+
sample(&mut at_edge, base, ms(10), RTT);
|
|
85
|
+
sample(&mut at_edge, base, ms(20), RTT_JUMP);
|
|
86
|
+
assert!(at_edge.is_rtt_jump_active());
|
|
87
|
+
sample(&mut at_edge, base, ms(30), RTT_3X);
|
|
88
|
+
assert!(!at_edge.is_rtt_jump_active());
|
|
89
|
+
|
|
90
|
+
let mut below_edge = global_min_detector();
|
|
91
|
+
sample(&mut below_edge, base, ms(10), RTT);
|
|
92
|
+
sample(&mut below_edge, base, ms(20), RTT_JUMP);
|
|
93
|
+
assert!(below_edge.is_rtt_jump_active());
|
|
94
|
+
sample(&mut below_edge, base, ms(30), RTT);
|
|
95
|
+
assert!(!below_edge.is_rtt_jump_active());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#[test]
|
|
99
|
+
fn global_min_detector_sustained_step_becomes_persistent() {
|
|
100
|
+
let mut detector = global_min_detector();
|
|
101
|
+
let base = Instant::now();
|
|
102
|
+
|
|
103
|
+
sample(&mut detector, base, ms(10), RTT);
|
|
104
|
+
sample(&mut detector, base, ms(20), RTT_JUMP);
|
|
105
|
+
assert!(detector.is_rtt_jump_active());
|
|
106
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
107
|
+
|
|
108
|
+
sample(&mut detector, base, ms(30), RTT_JUMP);
|
|
109
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
110
|
+
|
|
111
|
+
sample(&mut detector, base, ms(170), RTT_JUMP);
|
|
112
|
+
assert!(detector.is_rtt_jump_persistent());
|
|
113
|
+
assert_eq!(detector.rtt_persistent_jump_count(), 1);
|
|
114
|
+
assert_eq!(detector.last_persistent_jump_time(), Some(base + ms(20)));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[test]
|
|
118
|
+
fn global_min_detector_clears_persistent_at_or_below_threshold() {
|
|
119
|
+
let mut detector = global_min_detector();
|
|
120
|
+
let base = Instant::now();
|
|
121
|
+
|
|
122
|
+
sample(&mut detector, base, ms(10), RTT);
|
|
123
|
+
sample(&mut detector, base, ms(20), RTT_JUMP);
|
|
124
|
+
sample(&mut detector, base, ms(30), RTT_JUMP);
|
|
125
|
+
sample(&mut detector, base, ms(170), RTT_JUMP);
|
|
126
|
+
assert!(detector.is_rtt_jump_persistent());
|
|
127
|
+
|
|
128
|
+
sample(&mut detector, base, ms(180), RTT_3X);
|
|
129
|
+
assert!(!detector.is_rtt_jump_active());
|
|
130
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
131
|
+
assert_eq!(detector.rtt_persistent_jump_count(), 1);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[test]
|
|
135
|
+
fn global_min_detector_tracks_downward_baseline() {
|
|
136
|
+
let mut detector = global_min_detector();
|
|
137
|
+
let base = Instant::now();
|
|
138
|
+
|
|
139
|
+
sample(&mut detector, base, ms(100), ms(100));
|
|
140
|
+
sample(&mut detector, base, ms(200), ms(299));
|
|
141
|
+
assert!(!detector.is_rtt_jump_active());
|
|
142
|
+
|
|
143
|
+
sample(&mut detector, base, ms(300), RTT);
|
|
144
|
+
assert!(!detector.is_rtt_jump_active());
|
|
145
|
+
|
|
146
|
+
sample(&mut detector, base, ms(400), RTT_JUMP);
|
|
147
|
+
assert!(detector.is_rtt_jump_active());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#[test]
|
|
151
|
+
fn global_min_detector_repeated_elevation_waits_for_dwell() {
|
|
152
|
+
let mut detector = global_min_detector();
|
|
153
|
+
let base = Instant::now();
|
|
154
|
+
|
|
155
|
+
sample(&mut detector, base, ms(10), RTT);
|
|
156
|
+
sample(&mut detector, base, ms(20), RTT_JUMP);
|
|
157
|
+
sample(&mut detector, base, ms(30), RTT_JUMP);
|
|
158
|
+
sample(&mut detector, base, ms(40), RTT_JUMP);
|
|
159
|
+
|
|
160
|
+
assert!(detector.is_rtt_jump_active());
|
|
161
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
162
|
+
assert_eq!(detector.rtt_persistent_jump_count(), 0);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#[test]
|
|
166
|
+
fn global_min_detector_ignores_jumps_before_full_bandwidth() {
|
|
167
|
+
let mut detector = global_min_detector();
|
|
168
|
+
let base = Instant::now();
|
|
169
|
+
|
|
170
|
+
sample_with_full_bandwidth(&mut detector, base, ms(10), RTT, false);
|
|
171
|
+
sample_with_full_bandwidth(&mut detector, base, ms(20), RTT_JUMP, false);
|
|
172
|
+
sample_with_full_bandwidth(&mut detector, base, ms(30), RTT_JUMP, false);
|
|
173
|
+
sample_with_full_bandwidth(&mut detector, base, ms(170), RTT_JUMP, false);
|
|
174
|
+
|
|
175
|
+
assert!(!detector.is_rtt_jump_active());
|
|
176
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
177
|
+
assert_eq!(detector.rtt_persistent_jump_count(), 0);
|
|
178
|
+
|
|
179
|
+
sample(&mut detector, base, ms(180), RTT_JUMP);
|
|
180
|
+
assert!(detector.is_rtt_jump_active());
|
|
181
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
182
|
+
|
|
183
|
+
sample(&mut detector, base, ms(190), RTT_JUMP);
|
|
184
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
185
|
+
|
|
186
|
+
sample(&mut detector, base, ms(330), RTT_JUMP);
|
|
187
|
+
assert!(detector.is_rtt_jump_persistent());
|
|
188
|
+
assert_eq!(detector.rtt_persistent_jump_count(), 1);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#[test]
|
|
192
|
+
fn global_min_detector_uses_baseline_scaled_dwell() {
|
|
193
|
+
let mut detector = global_min_detector();
|
|
194
|
+
let base = Instant::now();
|
|
195
|
+
|
|
196
|
+
sample(&mut detector, base, ms(10), HIGH_RTT);
|
|
197
|
+
sample(&mut detector, base, ms(20), HIGH_RTT_JUMP);
|
|
198
|
+
sample(&mut detector, base, ms(100), HIGH_RTT_JUMP);
|
|
199
|
+
sample(&mut detector, base, ms(200), HIGH_RTT_JUMP);
|
|
200
|
+
|
|
201
|
+
assert!(detector.is_rtt_jump_active());
|
|
202
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
203
|
+
|
|
204
|
+
sample(&mut detector, base, ms(1520), HIGH_RTT_JUMP);
|
|
205
|
+
assert!(detector.is_rtt_jump_persistent());
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
#[test]
|
|
209
|
+
fn global_min_detector_handles_low_rtt_dwell() {
|
|
210
|
+
let mut detector = global_min_detector();
|
|
211
|
+
let base = Instant::now();
|
|
212
|
+
let jump = LOW_RTT.mul_f32(GLOBAL_MIN_JUMP_THRESHOLD) + ms(1);
|
|
213
|
+
|
|
214
|
+
sample(&mut detector, base, ms(10), LOW_RTT);
|
|
215
|
+
sample(&mut detector, base, ms(20), jump);
|
|
216
|
+
sample(&mut detector, base, ms(30), jump);
|
|
217
|
+
assert!(!detector.is_rtt_jump_persistent());
|
|
218
|
+
|
|
219
|
+
sample(&mut detector, base, ms(50), jump);
|
|
220
|
+
assert!(detector.is_rtt_jump_persistent());
|
|
221
|
+
}
|