rwebtransport 0.1.0 → 0.1.1
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 +666 -666
- package/Cargo.toml +31 -31
- package/LICENSE +202 -202
- package/NOTICE +41 -41
- package/README.md +550 -550
- package/crates/echo-server/Cargo.toml +20 -20
- package/crates/echo-server/src/main.rs +666 -666
- package/crates/native/Cargo.toml +23 -23
- package/crates/native/src/config.rs +129 -129
- package/crates/native/src/driver.rs +463 -463
- package/crates/native/src/lib.rs +821 -821
- package/crates/native/src/server.rs +718 -718
- package/crates/native/src/session.rs +1191 -1191
- package/crates/native/src/tls.rs +96 -96
- package/crates/wtcore/Cargo.toml +15 -15
- package/crates/wtcore/src/h3.rs +226 -226
- package/crates/wtcore/src/lib.rs +9 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +80 -79
- 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/bench.mjs +180 -180
- package/scripts/build.js +67 -67
- package/scripts/postinstall.js +67 -67
- package/scripts/setup-unix.sh +129 -129
- package/scripts/setup-windows.ps1 +229 -229
- package/vendor/quiche/AGENTS.md +75 -75
- package/vendor/quiche/COPYING +23 -23
- package/vendor/quiche/Cargo.lock +1212 -1212
- package/vendor/quiche/Cargo.toml +215 -215
- package/vendor/quiche/README.md +466 -466
- package/vendor/quiche/examples/Makefile +46 -46
- package/vendor/quiche/examples/README.md +20 -20
- package/vendor/quiche/examples/cert-big.crt +90 -90
- package/vendor/quiche/examples/cert.crt +18 -18
- package/vendor/quiche/examples/cert.key +28 -28
- package/vendor/quiche/examples/client.c +343 -343
- package/vendor/quiche/examples/client.rs +281 -281
- package/vendor/quiche/examples/gen-certs.sh +15 -15
- package/vendor/quiche/examples/http3-client.c +473 -473
- package/vendor/quiche/examples/http3-client.rs +349 -349
- package/vendor/quiche/examples/http3-server.c +614 -614
- package/vendor/quiche/examples/http3-server.rs +680 -680
- package/vendor/quiche/examples/qpack-decode.rs +87 -87
- package/vendor/quiche/examples/qpack-encode.rs +88 -88
- package/vendor/quiche/examples/rootca.crt +21 -21
- package/vendor/quiche/examples/server.c +529 -529
- package/vendor/quiche/examples/server.rs +529 -529
- package/vendor/quiche/include/quiche.h +1282 -1282
- package/vendor/quiche/src/buffers.rs +105 -105
- package/vendor/quiche/src/build.rs +66 -66
- package/vendor/quiche/src/cid.rs +1079 -1079
- package/vendor/quiche/src/crypto/boringssl.rs +373 -373
- package/vendor/quiche/src/crypto/mod.rs +671 -671
- package/vendor/quiche/src/dgram.rs +118 -118
- package/vendor/quiche/src/error.rs +263 -263
- package/vendor/quiche/src/ffi.rs +2290 -2290
- package/vendor/quiche/src/flowcontrol.rs +246 -246
- package/vendor/quiche/src/frame.rs +2172 -2172
- package/vendor/quiche/src/h3/AGENTS.md +54 -54
- package/vendor/quiche/src/h3/ffi.rs +442 -442
- package/vendor/quiche/src/h3/frame.rs +1404 -1404
- package/vendor/quiche/src/h3/mod.rs +8223 -8223
- package/vendor/quiche/src/h3/qpack/decoder.rs +288 -288
- package/vendor/quiche/src/h3/qpack/encoder.rs +235 -235
- package/vendor/quiche/src/h3/qpack/mod.rs +202 -202
- package/vendor/quiche/src/h3/qpack/static_table.rs +323 -323
- package/vendor/quiche/src/h3/stream.rs +1595 -1595
- package/vendor/quiche/src/lib.rs +9556 -9556
- package/vendor/quiche/src/minmax.rs +446 -446
- package/vendor/quiche/src/packet.rs +2334 -2334
- package/vendor/quiche/src/path.rs +1374 -1374
- package/vendor/quiche/src/pmtud.rs +652 -652
- package/vendor/quiche/src/rand.rs +64 -64
- package/vendor/quiche/src/range_buf.rs +186 -186
- package/vendor/quiche/src/ranges.rs +755 -755
- package/vendor/quiche/src/recovery/AGENTS.md +80 -80
- package/vendor/quiche/src/recovery/bandwidth.rs +565 -565
- package/vendor/quiche/src/recovery/bytes_in_flight.rs +179 -179
- package/vendor/quiche/src/recovery/congestion/cubic.rs +1038 -1038
- package/vendor/quiche/src/recovery/congestion/delivery_rate.rs +514 -514
- package/vendor/quiche/src/recovery/congestion/hystart.rs +241 -241
- package/vendor/quiche/src/recovery/congestion/mod.rs +361 -361
- package/vendor/quiche/src/recovery/congestion/prr.rs +238 -238
- package/vendor/quiche/src/recovery/congestion/recovery.rs +1170 -1170
- package/vendor/quiche/src/recovery/congestion/reno.rs +291 -291
- package/vendor/quiche/src/recovery/congestion/test_sender.rs +201 -201
- package/vendor/quiche/src/recovery/gcongestion/bbr/bandwidth_sampler.rs +1947 -1947
- package/vendor/quiche/src/recovery/gcongestion/bbr/windowed_filter.rs +158 -158
- package/vendor/quiche/src/recovery/gcongestion/bbr.rs +37 -37
- package/vendor/quiche/src/recovery/gcongestion/bbr2/drain.rs +120 -120
- package/vendor/quiche/src/recovery/gcongestion/bbr2/mode.rs +318 -318
- package/vendor/quiche/src/recovery/gcongestion/bbr2/network_model.rs +784 -784
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_bw.rs +729 -729
- package/vendor/quiche/src/recovery/gcongestion/bbr2/probe_rtt.rs +175 -175
- package/vendor/quiche/src/recovery/gcongestion/bbr2/startup.rs +190 -190
- package/vendor/quiche/src/recovery/gcongestion/bbr2.rs +855 -855
- package/vendor/quiche/src/recovery/gcongestion/mod.rs +275 -275
- package/vendor/quiche/src/recovery/gcongestion/pacer.rs +294 -294
- package/vendor/quiche/src/recovery/gcongestion/recovery.rs +1384 -1384
- package/vendor/quiche/src/recovery/mod.rs +3086 -3086
- package/vendor/quiche/src/recovery/rtt.rs +152 -152
- package/vendor/quiche/src/stream/mod.rs +2210 -2210
- package/vendor/quiche/src/stream/recv_buf.rs +1236 -1236
- package/vendor/quiche/src/stream/send_buf.rs +849 -849
- package/vendor/quiche/src/test_utils.rs +681 -681
- package/vendor/quiche/src/tests.rs +12922 -12922
- package/vendor/quiche/src/tls/boringssl.rs +375 -375
- package/vendor/quiche/src/tls/mod.rs +1245 -1245
- package/vendor/quiche/src/transport_params.rs +628 -628
|
@@ -1,318 +1,318 @@
|
|
|
1
|
-
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
// Copyright (C) 2023, Cloudflare, Inc.
|
|
6
|
-
// All rights reserved.
|
|
7
|
-
//
|
|
8
|
-
// Redistribution and use in source and binary forms, with or without
|
|
9
|
-
// modification, are permitted provided that the following conditions are
|
|
10
|
-
// met:
|
|
11
|
-
//
|
|
12
|
-
// * Redistributions of source code must retain the above copyright notice,
|
|
13
|
-
// this list of conditions and the following disclaimer.
|
|
14
|
-
//
|
|
15
|
-
// * Redistributions in binary form must reproduce the above copyright
|
|
16
|
-
// notice, this list of conditions and the following disclaimer in the
|
|
17
|
-
// documentation and/or other materials provided with the distribution.
|
|
18
|
-
//
|
|
19
|
-
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
20
|
-
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
-
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
22
|
-
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
23
|
-
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
24
|
-
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
25
|
-
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
26
|
-
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
27
|
-
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
28
|
-
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
29
|
-
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
-
|
|
31
|
-
use std::fmt::Debug;
|
|
32
|
-
use std::time::Duration;
|
|
33
|
-
use std::time::Instant;
|
|
34
|
-
|
|
35
|
-
use crate::recovery::gcongestion::bbr2::Params;
|
|
36
|
-
use crate::recovery::gcongestion::Lost;
|
|
37
|
-
use crate::recovery::RecoveryStats;
|
|
38
|
-
|
|
39
|
-
use super::drain::Drain;
|
|
40
|
-
use super::network_model::BBRv2NetworkModel;
|
|
41
|
-
use super::probe_bw::ProbeBW;
|
|
42
|
-
use super::probe_rtt::ProbeRTT;
|
|
43
|
-
use super::startup::Startup;
|
|
44
|
-
use super::Acked;
|
|
45
|
-
use super::BBRv2CongestionEvent;
|
|
46
|
-
use super::Limits;
|
|
47
|
-
|
|
48
|
-
#[derive(Debug, Default, PartialEq)]
|
|
49
|
-
pub(super) enum CyclePhase {
|
|
50
|
-
#[default]
|
|
51
|
-
NotStarted,
|
|
52
|
-
Up,
|
|
53
|
-
Down,
|
|
54
|
-
Cruise,
|
|
55
|
-
Refill,
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
impl CyclePhase {
|
|
59
|
-
pub(super) fn pacing_gain(&self, params: &Params) -> f32 {
|
|
60
|
-
match self {
|
|
61
|
-
CyclePhase::Up => params.probe_bw_probe_up_pacing_gain,
|
|
62
|
-
CyclePhase::Down => params.probe_bw_probe_down_pacing_gain,
|
|
63
|
-
_ => params.probe_bw_default_pacing_gain,
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
pub(super) fn cwnd_gain(&self, params: &Params) -> f32 {
|
|
68
|
-
match self {
|
|
69
|
-
CyclePhase::Up => params.probe_bw_up_cwnd_gain,
|
|
70
|
-
_ => params.probe_bw_cwnd_gain,
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
#[derive(Debug)]
|
|
76
|
-
pub(super) struct Cycle {
|
|
77
|
-
pub(super) start_time: Instant,
|
|
78
|
-
pub(super) phase: CyclePhase,
|
|
79
|
-
pub(super) rounds_in_phase: usize,
|
|
80
|
-
pub(super) phase_start_time: Instant,
|
|
81
|
-
pub(super) rounds_since_probe: usize,
|
|
82
|
-
pub(super) probe_wait_time: Option<Duration>,
|
|
83
|
-
pub(super) probe_up_rounds: usize,
|
|
84
|
-
pub(super) probe_up_bytes: Option<usize>,
|
|
85
|
-
pub(super) probe_up_acked: usize,
|
|
86
|
-
pub(super) probe_up_app_limited_since_inflight_hi_limited: bool,
|
|
87
|
-
// Whether max bandwidth filter window has advanced in this cycle. It is
|
|
88
|
-
// advanced once per cycle.
|
|
89
|
-
pub(super) has_advanced_max_bw: bool,
|
|
90
|
-
pub(super) is_sample_from_probing: bool,
|
|
91
|
-
|
|
92
|
-
pub(super) last_cycle_probed_too_high: bool,
|
|
93
|
-
pub(super) last_cycle_stopped_risky_probe: bool,
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
impl Default for Cycle {
|
|
97
|
-
fn default() -> Self {
|
|
98
|
-
let now = Instant::now();
|
|
99
|
-
|
|
100
|
-
Cycle {
|
|
101
|
-
start_time: now,
|
|
102
|
-
phase_start_time: now,
|
|
103
|
-
|
|
104
|
-
phase: CyclePhase::NotStarted,
|
|
105
|
-
rounds_in_phase: 0,
|
|
106
|
-
rounds_since_probe: 0,
|
|
107
|
-
probe_wait_time: None,
|
|
108
|
-
probe_up_rounds: 0,
|
|
109
|
-
probe_up_bytes: None,
|
|
110
|
-
probe_up_acked: 0,
|
|
111
|
-
probe_up_app_limited_since_inflight_hi_limited: false,
|
|
112
|
-
has_advanced_max_bw: false,
|
|
113
|
-
is_sample_from_probing: false,
|
|
114
|
-
last_cycle_probed_too_high: false,
|
|
115
|
-
last_cycle_stopped_risky_probe: false,
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
#[enum_dispatch::enum_dispatch]
|
|
121
|
-
pub(super) trait ModeImpl: Debug {
|
|
122
|
-
#[cfg(feature = "qlog")]
|
|
123
|
-
fn state_str(&self) -> &'static str;
|
|
124
|
-
|
|
125
|
-
fn enter(
|
|
126
|
-
&mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
|
|
127
|
-
params: &Params,
|
|
128
|
-
);
|
|
129
|
-
|
|
130
|
-
fn leave(
|
|
131
|
-
&mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
|
|
132
|
-
);
|
|
133
|
-
|
|
134
|
-
fn is_probing_for_bandwidth(&self) -> bool;
|
|
135
|
-
|
|
136
|
-
#[allow(clippy::too_many_arguments)]
|
|
137
|
-
fn on_congestion_event(
|
|
138
|
-
self, prior_in_flight: usize, event_time: Instant,
|
|
139
|
-
acked_packets: &[Acked], lost_packets: &[Lost],
|
|
140
|
-
congestion_event: &mut BBRv2CongestionEvent,
|
|
141
|
-
target_bytes_inflight: usize, params: &Params,
|
|
142
|
-
recovery_stats: &mut RecoveryStats, cwnd: usize,
|
|
143
|
-
) -> Mode;
|
|
144
|
-
|
|
145
|
-
fn get_cwnd_limits(&self, params: &Params) -> Limits<usize>;
|
|
146
|
-
|
|
147
|
-
fn on_exit_quiescence(
|
|
148
|
-
self, now: Instant, quiescence_start_time: Instant, params: &Params,
|
|
149
|
-
) -> Mode;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
#[enum_dispatch::enum_dispatch(ModeImpl)]
|
|
153
|
-
#[derive(Debug)]
|
|
154
|
-
pub(super) enum Mode {
|
|
155
|
-
Startup(Startup),
|
|
156
|
-
Drain(Drain),
|
|
157
|
-
ProbeBW(ProbeBW),
|
|
158
|
-
ProbeRTT(ProbeRTT),
|
|
159
|
-
Placheolder(Placeholder),
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
impl Default for Mode {
|
|
163
|
-
fn default() -> Self {
|
|
164
|
-
Mode::Placheolder(Placeholder {})
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
impl Mode {
|
|
169
|
-
pub(super) fn startup(model: BBRv2NetworkModel) -> Self {
|
|
170
|
-
Mode::Startup(Startup { model })
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
pub(super) fn drain(model: BBRv2NetworkModel) -> Self {
|
|
174
|
-
Mode::Drain(Drain {
|
|
175
|
-
model,
|
|
176
|
-
cycle: Default::default(),
|
|
177
|
-
})
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
pub(super) fn probe_bw(model: BBRv2NetworkModel, cycle: Cycle) -> Self {
|
|
181
|
-
Mode::ProbeBW(ProbeBW { model, cycle })
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
pub(super) fn probe_rtt(model: BBRv2NetworkModel, cycle: Cycle) -> Self {
|
|
185
|
-
Mode::ProbeRTT(ProbeRTT::new(model, cycle))
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
#[allow(clippy::too_many_arguments)]
|
|
189
|
-
pub(super) fn do_on_congestion_event(
|
|
190
|
-
&mut self, prior_in_flight: usize, event_time: Instant,
|
|
191
|
-
acked_packets: &[Acked], lost_packets: &[Lost],
|
|
192
|
-
congestion_event: &mut BBRv2CongestionEvent,
|
|
193
|
-
target_bytes_inflight: usize, params: &Params,
|
|
194
|
-
recovery_stats: &mut RecoveryStats, cwnd: usize,
|
|
195
|
-
) -> bool {
|
|
196
|
-
let mode_before = std::mem::discriminant(self);
|
|
197
|
-
|
|
198
|
-
*self = std::mem::take(self).on_congestion_event(
|
|
199
|
-
prior_in_flight,
|
|
200
|
-
event_time,
|
|
201
|
-
acked_packets,
|
|
202
|
-
lost_packets,
|
|
203
|
-
congestion_event,
|
|
204
|
-
target_bytes_inflight,
|
|
205
|
-
params,
|
|
206
|
-
recovery_stats,
|
|
207
|
-
cwnd,
|
|
208
|
-
);
|
|
209
|
-
|
|
210
|
-
let mode_after = std::mem::discriminant(self);
|
|
211
|
-
|
|
212
|
-
mode_before != mode_after
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
pub(super) fn do_on_exit_quiescence(
|
|
216
|
-
&mut self, now: Instant, quiescence_start_time: Instant, params: &Params,
|
|
217
|
-
) {
|
|
218
|
-
*self = std::mem::take(self).on_exit_quiescence(
|
|
219
|
-
now,
|
|
220
|
-
quiescence_start_time,
|
|
221
|
-
params,
|
|
222
|
-
)
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
pub fn network_model(&self) -> &BBRv2NetworkModel {
|
|
226
|
-
match self {
|
|
227
|
-
Mode::Startup(Startup { model }) => model,
|
|
228
|
-
Mode::Drain(Drain { model, .. }) => model,
|
|
229
|
-
Mode::ProbeBW(ProbeBW { model, .. }) => model,
|
|
230
|
-
Mode::ProbeRTT(ProbeRTT { model, .. }) => model,
|
|
231
|
-
Mode::Placheolder(_) => unreachable!(),
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
pub fn network_model_mut(&mut self) -> &mut BBRv2NetworkModel {
|
|
236
|
-
match self {
|
|
237
|
-
Mode::Startup(Startup { model }) => model,
|
|
238
|
-
Mode::Drain(Drain { model, .. }) => model,
|
|
239
|
-
Mode::ProbeBW(ProbeBW { model, .. }) => model,
|
|
240
|
-
Mode::ProbeRTT(ProbeRTT { model, .. }) => model,
|
|
241
|
-
Mode::Placheolder(_) => unreachable!(),
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
#[derive(Debug, Default)]
|
|
247
|
-
pub(super) struct Placeholder {}
|
|
248
|
-
|
|
249
|
-
impl ModeImpl for Placeholder {
|
|
250
|
-
#[cfg(feature = "qlog")]
|
|
251
|
-
fn state_str(&self) -> &'static str {
|
|
252
|
-
unreachable!()
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
fn enter(
|
|
256
|
-
&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>, _params: &Params,
|
|
257
|
-
) {
|
|
258
|
-
unreachable!()
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
fn leave(&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>) {
|
|
262
|
-
unreachable!()
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
fn is_probing_for_bandwidth(&self) -> bool {
|
|
266
|
-
unreachable!()
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
fn on_congestion_event(
|
|
270
|
-
self, _: usize, _: Instant, _: &[Acked], _: &[Lost],
|
|
271
|
-
_: &mut BBRv2CongestionEvent, _: usize, _params: &Params,
|
|
272
|
-
_recovery_stats: &mut RecoveryStats, _cwnd: usize,
|
|
273
|
-
) -> Mode {
|
|
274
|
-
unreachable!()
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
fn get_cwnd_limits(&self, _params: &Params) -> Limits<usize> {
|
|
278
|
-
unreachable!()
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
fn on_exit_quiescence(
|
|
282
|
-
self, _: Instant, _: Instant, _params: &Params,
|
|
283
|
-
) -> Mode {
|
|
284
|
-
unreachable!()
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
#[cfg(test)]
|
|
289
|
-
mod tests {
|
|
290
|
-
use super::*;
|
|
291
|
-
use crate::recovery::gcongestion::bbr2::DEFAULT_PARAMS;
|
|
292
|
-
use crate::BbrParams;
|
|
293
|
-
|
|
294
|
-
#[test]
|
|
295
|
-
fn cycle_params() {
|
|
296
|
-
let custom_bbr_settings = BbrParams {
|
|
297
|
-
probe_bw_up_cwnd_gain: Some(2.25),
|
|
298
|
-
probe_bw_cwnd_gain: Some(2.0),
|
|
299
|
-
..Default::default()
|
|
300
|
-
};
|
|
301
|
-
let params = &DEFAULT_PARAMS.with_overrides(&custom_bbr_settings);
|
|
302
|
-
|
|
303
|
-
assert_eq!(CyclePhase::Up.pacing_gain(params), 1.25);
|
|
304
|
-
assert_eq!(CyclePhase::Up.cwnd_gain(params), 2.25);
|
|
305
|
-
|
|
306
|
-
assert_eq!(CyclePhase::Down.pacing_gain(params), 0.9);
|
|
307
|
-
assert_eq!(CyclePhase::Down.cwnd_gain(params), 2.0);
|
|
308
|
-
|
|
309
|
-
assert_eq!(CyclePhase::NotStarted.pacing_gain(params), 1.0);
|
|
310
|
-
assert_eq!(CyclePhase::NotStarted.cwnd_gain(params), 2.0);
|
|
311
|
-
|
|
312
|
-
assert_eq!(CyclePhase::Cruise.pacing_gain(params), 1.0);
|
|
313
|
-
assert_eq!(CyclePhase::Cruise.cwnd_gain(params), 2.0);
|
|
314
|
-
|
|
315
|
-
assert_eq!(CyclePhase::Refill.pacing_gain(params), 1.0);
|
|
316
|
-
assert_eq!(CyclePhase::Refill.cwnd_gain(params), 2.0);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
1
|
+
// Copyright (c) 2015 The Chromium Authors. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a BSD-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
// Copyright (C) 2023, Cloudflare, Inc.
|
|
6
|
+
// All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
// Redistribution and use in source and binary forms, with or without
|
|
9
|
+
// modification, are permitted provided that the following conditions are
|
|
10
|
+
// met:
|
|
11
|
+
//
|
|
12
|
+
// * Redistributions of source code must retain the above copyright notice,
|
|
13
|
+
// this list of conditions and the following disclaimer.
|
|
14
|
+
//
|
|
15
|
+
// * Redistributions in binary form must reproduce the above copyright
|
|
16
|
+
// notice, this list of conditions and the following disclaimer in the
|
|
17
|
+
// documentation and/or other materials provided with the distribution.
|
|
18
|
+
//
|
|
19
|
+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
20
|
+
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
21
|
+
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
22
|
+
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
23
|
+
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
24
|
+
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
25
|
+
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
26
|
+
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
27
|
+
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
28
|
+
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
29
|
+
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
30
|
+
|
|
31
|
+
use std::fmt::Debug;
|
|
32
|
+
use std::time::Duration;
|
|
33
|
+
use std::time::Instant;
|
|
34
|
+
|
|
35
|
+
use crate::recovery::gcongestion::bbr2::Params;
|
|
36
|
+
use crate::recovery::gcongestion::Lost;
|
|
37
|
+
use crate::recovery::RecoveryStats;
|
|
38
|
+
|
|
39
|
+
use super::drain::Drain;
|
|
40
|
+
use super::network_model::BBRv2NetworkModel;
|
|
41
|
+
use super::probe_bw::ProbeBW;
|
|
42
|
+
use super::probe_rtt::ProbeRTT;
|
|
43
|
+
use super::startup::Startup;
|
|
44
|
+
use super::Acked;
|
|
45
|
+
use super::BBRv2CongestionEvent;
|
|
46
|
+
use super::Limits;
|
|
47
|
+
|
|
48
|
+
#[derive(Debug, Default, PartialEq)]
|
|
49
|
+
pub(super) enum CyclePhase {
|
|
50
|
+
#[default]
|
|
51
|
+
NotStarted,
|
|
52
|
+
Up,
|
|
53
|
+
Down,
|
|
54
|
+
Cruise,
|
|
55
|
+
Refill,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
impl CyclePhase {
|
|
59
|
+
pub(super) fn pacing_gain(&self, params: &Params) -> f32 {
|
|
60
|
+
match self {
|
|
61
|
+
CyclePhase::Up => params.probe_bw_probe_up_pacing_gain,
|
|
62
|
+
CyclePhase::Down => params.probe_bw_probe_down_pacing_gain,
|
|
63
|
+
_ => params.probe_bw_default_pacing_gain,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
pub(super) fn cwnd_gain(&self, params: &Params) -> f32 {
|
|
68
|
+
match self {
|
|
69
|
+
CyclePhase::Up => params.probe_bw_up_cwnd_gain,
|
|
70
|
+
_ => params.probe_bw_cwnd_gain,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[derive(Debug)]
|
|
76
|
+
pub(super) struct Cycle {
|
|
77
|
+
pub(super) start_time: Instant,
|
|
78
|
+
pub(super) phase: CyclePhase,
|
|
79
|
+
pub(super) rounds_in_phase: usize,
|
|
80
|
+
pub(super) phase_start_time: Instant,
|
|
81
|
+
pub(super) rounds_since_probe: usize,
|
|
82
|
+
pub(super) probe_wait_time: Option<Duration>,
|
|
83
|
+
pub(super) probe_up_rounds: usize,
|
|
84
|
+
pub(super) probe_up_bytes: Option<usize>,
|
|
85
|
+
pub(super) probe_up_acked: usize,
|
|
86
|
+
pub(super) probe_up_app_limited_since_inflight_hi_limited: bool,
|
|
87
|
+
// Whether max bandwidth filter window has advanced in this cycle. It is
|
|
88
|
+
// advanced once per cycle.
|
|
89
|
+
pub(super) has_advanced_max_bw: bool,
|
|
90
|
+
pub(super) is_sample_from_probing: bool,
|
|
91
|
+
|
|
92
|
+
pub(super) last_cycle_probed_too_high: bool,
|
|
93
|
+
pub(super) last_cycle_stopped_risky_probe: bool,
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
impl Default for Cycle {
|
|
97
|
+
fn default() -> Self {
|
|
98
|
+
let now = Instant::now();
|
|
99
|
+
|
|
100
|
+
Cycle {
|
|
101
|
+
start_time: now,
|
|
102
|
+
phase_start_time: now,
|
|
103
|
+
|
|
104
|
+
phase: CyclePhase::NotStarted,
|
|
105
|
+
rounds_in_phase: 0,
|
|
106
|
+
rounds_since_probe: 0,
|
|
107
|
+
probe_wait_time: None,
|
|
108
|
+
probe_up_rounds: 0,
|
|
109
|
+
probe_up_bytes: None,
|
|
110
|
+
probe_up_acked: 0,
|
|
111
|
+
probe_up_app_limited_since_inflight_hi_limited: false,
|
|
112
|
+
has_advanced_max_bw: false,
|
|
113
|
+
is_sample_from_probing: false,
|
|
114
|
+
last_cycle_probed_too_high: false,
|
|
115
|
+
last_cycle_stopped_risky_probe: false,
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
#[enum_dispatch::enum_dispatch]
|
|
121
|
+
pub(super) trait ModeImpl: Debug {
|
|
122
|
+
#[cfg(feature = "qlog")]
|
|
123
|
+
fn state_str(&self) -> &'static str;
|
|
124
|
+
|
|
125
|
+
fn enter(
|
|
126
|
+
&mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
|
|
127
|
+
params: &Params,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
fn leave(
|
|
131
|
+
&mut self, now: Instant, congestion_event: Option<&BBRv2CongestionEvent>,
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
fn is_probing_for_bandwidth(&self) -> bool;
|
|
135
|
+
|
|
136
|
+
#[allow(clippy::too_many_arguments)]
|
|
137
|
+
fn on_congestion_event(
|
|
138
|
+
self, prior_in_flight: usize, event_time: Instant,
|
|
139
|
+
acked_packets: &[Acked], lost_packets: &[Lost],
|
|
140
|
+
congestion_event: &mut BBRv2CongestionEvent,
|
|
141
|
+
target_bytes_inflight: usize, params: &Params,
|
|
142
|
+
recovery_stats: &mut RecoveryStats, cwnd: usize,
|
|
143
|
+
) -> Mode;
|
|
144
|
+
|
|
145
|
+
fn get_cwnd_limits(&self, params: &Params) -> Limits<usize>;
|
|
146
|
+
|
|
147
|
+
fn on_exit_quiescence(
|
|
148
|
+
self, now: Instant, quiescence_start_time: Instant, params: &Params,
|
|
149
|
+
) -> Mode;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#[enum_dispatch::enum_dispatch(ModeImpl)]
|
|
153
|
+
#[derive(Debug)]
|
|
154
|
+
pub(super) enum Mode {
|
|
155
|
+
Startup(Startup),
|
|
156
|
+
Drain(Drain),
|
|
157
|
+
ProbeBW(ProbeBW),
|
|
158
|
+
ProbeRTT(ProbeRTT),
|
|
159
|
+
Placheolder(Placeholder),
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
impl Default for Mode {
|
|
163
|
+
fn default() -> Self {
|
|
164
|
+
Mode::Placheolder(Placeholder {})
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
impl Mode {
|
|
169
|
+
pub(super) fn startup(model: BBRv2NetworkModel) -> Self {
|
|
170
|
+
Mode::Startup(Startup { model })
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
pub(super) fn drain(model: BBRv2NetworkModel) -> Self {
|
|
174
|
+
Mode::Drain(Drain {
|
|
175
|
+
model,
|
|
176
|
+
cycle: Default::default(),
|
|
177
|
+
})
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
pub(super) fn probe_bw(model: BBRv2NetworkModel, cycle: Cycle) -> Self {
|
|
181
|
+
Mode::ProbeBW(ProbeBW { model, cycle })
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
pub(super) fn probe_rtt(model: BBRv2NetworkModel, cycle: Cycle) -> Self {
|
|
185
|
+
Mode::ProbeRTT(ProbeRTT::new(model, cycle))
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#[allow(clippy::too_many_arguments)]
|
|
189
|
+
pub(super) fn do_on_congestion_event(
|
|
190
|
+
&mut self, prior_in_flight: usize, event_time: Instant,
|
|
191
|
+
acked_packets: &[Acked], lost_packets: &[Lost],
|
|
192
|
+
congestion_event: &mut BBRv2CongestionEvent,
|
|
193
|
+
target_bytes_inflight: usize, params: &Params,
|
|
194
|
+
recovery_stats: &mut RecoveryStats, cwnd: usize,
|
|
195
|
+
) -> bool {
|
|
196
|
+
let mode_before = std::mem::discriminant(self);
|
|
197
|
+
|
|
198
|
+
*self = std::mem::take(self).on_congestion_event(
|
|
199
|
+
prior_in_flight,
|
|
200
|
+
event_time,
|
|
201
|
+
acked_packets,
|
|
202
|
+
lost_packets,
|
|
203
|
+
congestion_event,
|
|
204
|
+
target_bytes_inflight,
|
|
205
|
+
params,
|
|
206
|
+
recovery_stats,
|
|
207
|
+
cwnd,
|
|
208
|
+
);
|
|
209
|
+
|
|
210
|
+
let mode_after = std::mem::discriminant(self);
|
|
211
|
+
|
|
212
|
+
mode_before != mode_after
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
pub(super) fn do_on_exit_quiescence(
|
|
216
|
+
&mut self, now: Instant, quiescence_start_time: Instant, params: &Params,
|
|
217
|
+
) {
|
|
218
|
+
*self = std::mem::take(self).on_exit_quiescence(
|
|
219
|
+
now,
|
|
220
|
+
quiescence_start_time,
|
|
221
|
+
params,
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
pub fn network_model(&self) -> &BBRv2NetworkModel {
|
|
226
|
+
match self {
|
|
227
|
+
Mode::Startup(Startup { model }) => model,
|
|
228
|
+
Mode::Drain(Drain { model, .. }) => model,
|
|
229
|
+
Mode::ProbeBW(ProbeBW { model, .. }) => model,
|
|
230
|
+
Mode::ProbeRTT(ProbeRTT { model, .. }) => model,
|
|
231
|
+
Mode::Placheolder(_) => unreachable!(),
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
pub fn network_model_mut(&mut self) -> &mut BBRv2NetworkModel {
|
|
236
|
+
match self {
|
|
237
|
+
Mode::Startup(Startup { model }) => model,
|
|
238
|
+
Mode::Drain(Drain { model, .. }) => model,
|
|
239
|
+
Mode::ProbeBW(ProbeBW { model, .. }) => model,
|
|
240
|
+
Mode::ProbeRTT(ProbeRTT { model, .. }) => model,
|
|
241
|
+
Mode::Placheolder(_) => unreachable!(),
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
#[derive(Debug, Default)]
|
|
247
|
+
pub(super) struct Placeholder {}
|
|
248
|
+
|
|
249
|
+
impl ModeImpl for Placeholder {
|
|
250
|
+
#[cfg(feature = "qlog")]
|
|
251
|
+
fn state_str(&self) -> &'static str {
|
|
252
|
+
unreachable!()
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
fn enter(
|
|
256
|
+
&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>, _params: &Params,
|
|
257
|
+
) {
|
|
258
|
+
unreachable!()
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
fn leave(&mut self, _: Instant, _: Option<&BBRv2CongestionEvent>) {
|
|
262
|
+
unreachable!()
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
fn is_probing_for_bandwidth(&self) -> bool {
|
|
266
|
+
unreachable!()
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
fn on_congestion_event(
|
|
270
|
+
self, _: usize, _: Instant, _: &[Acked], _: &[Lost],
|
|
271
|
+
_: &mut BBRv2CongestionEvent, _: usize, _params: &Params,
|
|
272
|
+
_recovery_stats: &mut RecoveryStats, _cwnd: usize,
|
|
273
|
+
) -> Mode {
|
|
274
|
+
unreachable!()
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fn get_cwnd_limits(&self, _params: &Params) -> Limits<usize> {
|
|
278
|
+
unreachable!()
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
fn on_exit_quiescence(
|
|
282
|
+
self, _: Instant, _: Instant, _params: &Params,
|
|
283
|
+
) -> Mode {
|
|
284
|
+
unreachable!()
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
#[cfg(test)]
|
|
289
|
+
mod tests {
|
|
290
|
+
use super::*;
|
|
291
|
+
use crate::recovery::gcongestion::bbr2::DEFAULT_PARAMS;
|
|
292
|
+
use crate::BbrParams;
|
|
293
|
+
|
|
294
|
+
#[test]
|
|
295
|
+
fn cycle_params() {
|
|
296
|
+
let custom_bbr_settings = BbrParams {
|
|
297
|
+
probe_bw_up_cwnd_gain: Some(2.25),
|
|
298
|
+
probe_bw_cwnd_gain: Some(2.0),
|
|
299
|
+
..Default::default()
|
|
300
|
+
};
|
|
301
|
+
let params = &DEFAULT_PARAMS.with_overrides(&custom_bbr_settings);
|
|
302
|
+
|
|
303
|
+
assert_eq!(CyclePhase::Up.pacing_gain(params), 1.25);
|
|
304
|
+
assert_eq!(CyclePhase::Up.cwnd_gain(params), 2.25);
|
|
305
|
+
|
|
306
|
+
assert_eq!(CyclePhase::Down.pacing_gain(params), 0.9);
|
|
307
|
+
assert_eq!(CyclePhase::Down.cwnd_gain(params), 2.0);
|
|
308
|
+
|
|
309
|
+
assert_eq!(CyclePhase::NotStarted.pacing_gain(params), 1.0);
|
|
310
|
+
assert_eq!(CyclePhase::NotStarted.cwnd_gain(params), 2.0);
|
|
311
|
+
|
|
312
|
+
assert_eq!(CyclePhase::Cruise.pacing_gain(params), 1.0);
|
|
313
|
+
assert_eq!(CyclePhase::Cruise.cwnd_gain(params), 2.0);
|
|
314
|
+
|
|
315
|
+
assert_eq!(CyclePhase::Refill.pacing_gain(params), 1.0);
|
|
316
|
+
assert_eq!(CyclePhase::Refill.cwnd_gain(params), 2.0);
|
|
317
|
+
}
|
|
318
|
+
}
|