rwebtransport 0.1.0 → 0.1.2
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,291 +1,291 @@
|
|
|
1
|
-
// Copyright (C) 2019, 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
|
-
//! Reno Congestion Control
|
|
28
|
-
//!
|
|
29
|
-
//! Note that Slow Start can use HyStart++ when enabled.
|
|
30
|
-
|
|
31
|
-
use std::cmp;
|
|
32
|
-
use std::time::Instant;
|
|
33
|
-
|
|
34
|
-
use super::rtt::RttStats;
|
|
35
|
-
use super::Acked;
|
|
36
|
-
use super::Sent;
|
|
37
|
-
|
|
38
|
-
use super::Congestion;
|
|
39
|
-
use super::CongestionControlOps;
|
|
40
|
-
use crate::recovery::LOSS_REDUCTION_FACTOR;
|
|
41
|
-
use crate::recovery::MINIMUM_WINDOW_PACKETS;
|
|
42
|
-
|
|
43
|
-
pub(crate) static RENO: CongestionControlOps = CongestionControlOps {
|
|
44
|
-
on_init,
|
|
45
|
-
on_packet_sent,
|
|
46
|
-
on_packets_acked,
|
|
47
|
-
congestion_event,
|
|
48
|
-
checkpoint,
|
|
49
|
-
rollback,
|
|
50
|
-
#[cfg(feature = "qlog")]
|
|
51
|
-
state_str,
|
|
52
|
-
debug_fmt,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
pub fn on_init(_r: &mut Congestion) {}
|
|
56
|
-
|
|
57
|
-
pub fn on_packet_sent(
|
|
58
|
-
_r: &mut Congestion, _sent_bytes: usize, _bytes_in_flight: usize,
|
|
59
|
-
_now: Instant,
|
|
60
|
-
) {
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
fn on_packets_acked(
|
|
64
|
-
r: &mut Congestion, _bytes_in_flight: usize, packets: &mut Vec<Acked>,
|
|
65
|
-
now: Instant, rtt_stats: &RttStats,
|
|
66
|
-
) {
|
|
67
|
-
for pkt in packets.drain(..) {
|
|
68
|
-
on_packet_acked(r, &pkt, now, rtt_stats);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
fn on_packet_acked(
|
|
73
|
-
r: &mut Congestion, packet: &Acked, now: Instant, rtt_stats: &RttStats,
|
|
74
|
-
) {
|
|
75
|
-
if r.in_congestion_recovery(packet.time_sent) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if r.app_limited {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if r.congestion_window < r.ssthresh.get() {
|
|
84
|
-
// In Slow slart, bytes_acked_sl is used for counting
|
|
85
|
-
// acknowledged bytes.
|
|
86
|
-
r.bytes_acked_sl += packet.size;
|
|
87
|
-
|
|
88
|
-
if r.hystart.in_css() {
|
|
89
|
-
r.congestion_window += r.hystart.css_cwnd_inc(r.max_datagram_size);
|
|
90
|
-
} else {
|
|
91
|
-
r.congestion_window += r.max_datagram_size;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if r.hystart.on_packet_acked(packet, rtt_stats.latest_rtt, now) {
|
|
95
|
-
// Exit to congestion avoidance if CSS ends.
|
|
96
|
-
r.ssthresh.update(r.congestion_window, true);
|
|
97
|
-
}
|
|
98
|
-
} else {
|
|
99
|
-
// Congestion avoidance.
|
|
100
|
-
r.bytes_acked_ca += packet.size;
|
|
101
|
-
|
|
102
|
-
if r.bytes_acked_ca >= r.congestion_window {
|
|
103
|
-
r.bytes_acked_ca -= r.congestion_window;
|
|
104
|
-
r.congestion_window += r.max_datagram_size;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
fn congestion_event(
|
|
110
|
-
r: &mut Congestion, _bytes_in_flight: usize, _lost_bytes: usize,
|
|
111
|
-
largest_lost_pkt: &Sent, now: Instant,
|
|
112
|
-
) {
|
|
113
|
-
// Start a new congestion event if packet was sent after the
|
|
114
|
-
// start of the previous congestion recovery period.
|
|
115
|
-
let time_sent = largest_lost_pkt.time_sent;
|
|
116
|
-
|
|
117
|
-
if !r.in_congestion_recovery(time_sent) {
|
|
118
|
-
r.congestion_recovery_start_time = Some(now);
|
|
119
|
-
|
|
120
|
-
r.congestion_window =
|
|
121
|
-
(r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
122
|
-
|
|
123
|
-
r.congestion_window = cmp::max(
|
|
124
|
-
r.congestion_window,
|
|
125
|
-
r.max_datagram_size * MINIMUM_WINDOW_PACKETS,
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
r.bytes_acked_ca =
|
|
129
|
-
(r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
130
|
-
|
|
131
|
-
r.ssthresh.update(r.congestion_window, r.hystart.in_css());
|
|
132
|
-
|
|
133
|
-
if r.hystart.in_css() {
|
|
134
|
-
r.hystart.congestion_event();
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
fn checkpoint(_r: &mut Congestion) {}
|
|
140
|
-
|
|
141
|
-
fn rollback(_r: &mut Congestion) -> bool {
|
|
142
|
-
true
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
#[cfg(feature = "qlog")]
|
|
146
|
-
pub fn state_str(r: &Congestion, now: Instant) -> &'static str {
|
|
147
|
-
if r.hystart.in_css() {
|
|
148
|
-
"conservative_slow_start"
|
|
149
|
-
} else if r.congestion_window < r.ssthresh.get() {
|
|
150
|
-
"slow_start"
|
|
151
|
-
} else if r.in_congestion_recovery(now) {
|
|
152
|
-
"recovery"
|
|
153
|
-
} else {
|
|
154
|
-
"congestion_avoidance"
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
fn debug_fmt(_r: &Congestion, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
159
|
-
Ok(())
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
#[cfg(test)]
|
|
163
|
-
mod tests {
|
|
164
|
-
use crate::CongestionControlAlgorithm;
|
|
165
|
-
|
|
166
|
-
use super::*;
|
|
167
|
-
|
|
168
|
-
use crate::recovery::congestion::recovery::LegacyRecovery;
|
|
169
|
-
use crate::recovery::congestion::test_sender::TestSender;
|
|
170
|
-
use crate::recovery::RecoveryOps;
|
|
171
|
-
|
|
172
|
-
use std::time::Duration;
|
|
173
|
-
|
|
174
|
-
fn test_sender() -> TestSender {
|
|
175
|
-
TestSender::new(CongestionControlAlgorithm::Reno, false)
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
#[test]
|
|
179
|
-
fn reno_init() {
|
|
180
|
-
let mut cfg = crate::Config::new(crate::PROTOCOL_VERSION).unwrap();
|
|
181
|
-
cfg.set_cc_algorithm(CongestionControlAlgorithm::Reno);
|
|
182
|
-
|
|
183
|
-
let r = LegacyRecovery::new(&cfg);
|
|
184
|
-
|
|
185
|
-
assert!(r.cwnd() > 0);
|
|
186
|
-
assert_eq!(r.bytes_in_flight(), 0);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
#[test]
|
|
190
|
-
fn reno_slow_start() {
|
|
191
|
-
let mut sender = test_sender();
|
|
192
|
-
let size = sender.max_datagram_size;
|
|
193
|
-
|
|
194
|
-
// Send initcwnd full MSS packets to become no longer app limited
|
|
195
|
-
for _ in 0..sender.initial_congestion_window_packets {
|
|
196
|
-
sender.send_packet(size);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
let cwnd_prev = sender.congestion_window;
|
|
200
|
-
|
|
201
|
-
sender.ack_n_packets(1, size);
|
|
202
|
-
|
|
203
|
-
// Check if cwnd increased by packet size (slow start).
|
|
204
|
-
assert_eq!(sender.congestion_window, cwnd_prev + size);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
#[test]
|
|
208
|
-
fn reno_slow_start_multi_acks() {
|
|
209
|
-
let mut sender = test_sender();
|
|
210
|
-
let size = sender.max_datagram_size;
|
|
211
|
-
|
|
212
|
-
// Send initcwnd full MSS packets to become no longer app limited
|
|
213
|
-
for _ in 0..sender.initial_congestion_window_packets {
|
|
214
|
-
sender.send_packet(size);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
let cwnd_prev = sender.congestion_window;
|
|
218
|
-
|
|
219
|
-
sender.ack_n_packets(3, size);
|
|
220
|
-
|
|
221
|
-
// Acked 3 packets.
|
|
222
|
-
assert_eq!(sender.congestion_window, cwnd_prev + size * 3);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
#[test]
|
|
226
|
-
fn reno_congestion_event() {
|
|
227
|
-
let mut sender = test_sender();
|
|
228
|
-
let size = sender.max_datagram_size;
|
|
229
|
-
|
|
230
|
-
let prev_cwnd = sender.congestion_window;
|
|
231
|
-
|
|
232
|
-
sender.send_packet(size);
|
|
233
|
-
sender.lose_n_packets(1, size, None);
|
|
234
|
-
|
|
235
|
-
// In Reno, after congestion event, cwnd will be cut in half.
|
|
236
|
-
assert_eq!(prev_cwnd / 2, sender.congestion_window);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
#[test]
|
|
240
|
-
fn reno_congestion_avoidance() {
|
|
241
|
-
let mut sender = test_sender();
|
|
242
|
-
let size = sender.max_datagram_size;
|
|
243
|
-
|
|
244
|
-
// Send initcwnd full MSS packets to become no longer app limited
|
|
245
|
-
for _ in 0..14 {
|
|
246
|
-
sender.send_packet(size);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
let rtt = Duration::from_millis(100);
|
|
250
|
-
let prev_cwnd = sender.congestion_window;
|
|
251
|
-
|
|
252
|
-
sender.advance_time(rtt);
|
|
253
|
-
sender.lose_n_packets(1, size, None);
|
|
254
|
-
|
|
255
|
-
// After congestion event, cwnd will be reduced.
|
|
256
|
-
let cur_cwnd = (prev_cwnd as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
257
|
-
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
258
|
-
|
|
259
|
-
sender.update_rtt(rtt);
|
|
260
|
-
sender.advance_time(2 * rtt);
|
|
261
|
-
|
|
262
|
-
sender.ack_n_packets(13, size);
|
|
263
|
-
// Acked packets were sent before the loss event, window does not
|
|
264
|
-
// increase.
|
|
265
|
-
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
266
|
-
|
|
267
|
-
for _ in 0..7 {
|
|
268
|
-
sender.send_packet(size);
|
|
269
|
-
}
|
|
270
|
-
sender.advance_time(rtt);
|
|
271
|
-
sender.ack_n_packets(2, size);
|
|
272
|
-
// Not enough ACKed, window does not increase.
|
|
273
|
-
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
274
|
-
|
|
275
|
-
sender.ack_n_packets(1, size);
|
|
276
|
-
// Expect cwnd increased by MSS
|
|
277
|
-
assert_eq!(sender.congestion_window, cur_cwnd + size);
|
|
278
|
-
|
|
279
|
-
for _ in 0..7 {
|
|
280
|
-
sender.send_packet(size);
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
// Expect a second window increase after a cwnd's worth of ACKs.
|
|
284
|
-
sender.ack_n_packets(5, size);
|
|
285
|
-
// Not yet, one more ACK needed.
|
|
286
|
-
assert_eq!(sender.congestion_window, cur_cwnd + size);
|
|
287
|
-
sender.ack_n_packets(1, size);
|
|
288
|
-
// Expect cwnd increased by MSS
|
|
289
|
-
assert_eq!(sender.congestion_window, cur_cwnd + 2 * size);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
1
|
+
// Copyright (C) 2019, 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
|
+
//! Reno Congestion Control
|
|
28
|
+
//!
|
|
29
|
+
//! Note that Slow Start can use HyStart++ when enabled.
|
|
30
|
+
|
|
31
|
+
use std::cmp;
|
|
32
|
+
use std::time::Instant;
|
|
33
|
+
|
|
34
|
+
use super::rtt::RttStats;
|
|
35
|
+
use super::Acked;
|
|
36
|
+
use super::Sent;
|
|
37
|
+
|
|
38
|
+
use super::Congestion;
|
|
39
|
+
use super::CongestionControlOps;
|
|
40
|
+
use crate::recovery::LOSS_REDUCTION_FACTOR;
|
|
41
|
+
use crate::recovery::MINIMUM_WINDOW_PACKETS;
|
|
42
|
+
|
|
43
|
+
pub(crate) static RENO: CongestionControlOps = CongestionControlOps {
|
|
44
|
+
on_init,
|
|
45
|
+
on_packet_sent,
|
|
46
|
+
on_packets_acked,
|
|
47
|
+
congestion_event,
|
|
48
|
+
checkpoint,
|
|
49
|
+
rollback,
|
|
50
|
+
#[cfg(feature = "qlog")]
|
|
51
|
+
state_str,
|
|
52
|
+
debug_fmt,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
pub fn on_init(_r: &mut Congestion) {}
|
|
56
|
+
|
|
57
|
+
pub fn on_packet_sent(
|
|
58
|
+
_r: &mut Congestion, _sent_bytes: usize, _bytes_in_flight: usize,
|
|
59
|
+
_now: Instant,
|
|
60
|
+
) {
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn on_packets_acked(
|
|
64
|
+
r: &mut Congestion, _bytes_in_flight: usize, packets: &mut Vec<Acked>,
|
|
65
|
+
now: Instant, rtt_stats: &RttStats,
|
|
66
|
+
) {
|
|
67
|
+
for pkt in packets.drain(..) {
|
|
68
|
+
on_packet_acked(r, &pkt, now, rtt_stats);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
fn on_packet_acked(
|
|
73
|
+
r: &mut Congestion, packet: &Acked, now: Instant, rtt_stats: &RttStats,
|
|
74
|
+
) {
|
|
75
|
+
if r.in_congestion_recovery(packet.time_sent) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if r.app_limited {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if r.congestion_window < r.ssthresh.get() {
|
|
84
|
+
// In Slow slart, bytes_acked_sl is used for counting
|
|
85
|
+
// acknowledged bytes.
|
|
86
|
+
r.bytes_acked_sl += packet.size;
|
|
87
|
+
|
|
88
|
+
if r.hystart.in_css() {
|
|
89
|
+
r.congestion_window += r.hystart.css_cwnd_inc(r.max_datagram_size);
|
|
90
|
+
} else {
|
|
91
|
+
r.congestion_window += r.max_datagram_size;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if r.hystart.on_packet_acked(packet, rtt_stats.latest_rtt, now) {
|
|
95
|
+
// Exit to congestion avoidance if CSS ends.
|
|
96
|
+
r.ssthresh.update(r.congestion_window, true);
|
|
97
|
+
}
|
|
98
|
+
} else {
|
|
99
|
+
// Congestion avoidance.
|
|
100
|
+
r.bytes_acked_ca += packet.size;
|
|
101
|
+
|
|
102
|
+
if r.bytes_acked_ca >= r.congestion_window {
|
|
103
|
+
r.bytes_acked_ca -= r.congestion_window;
|
|
104
|
+
r.congestion_window += r.max_datagram_size;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
fn congestion_event(
|
|
110
|
+
r: &mut Congestion, _bytes_in_flight: usize, _lost_bytes: usize,
|
|
111
|
+
largest_lost_pkt: &Sent, now: Instant,
|
|
112
|
+
) {
|
|
113
|
+
// Start a new congestion event if packet was sent after the
|
|
114
|
+
// start of the previous congestion recovery period.
|
|
115
|
+
let time_sent = largest_lost_pkt.time_sent;
|
|
116
|
+
|
|
117
|
+
if !r.in_congestion_recovery(time_sent) {
|
|
118
|
+
r.congestion_recovery_start_time = Some(now);
|
|
119
|
+
|
|
120
|
+
r.congestion_window =
|
|
121
|
+
(r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
122
|
+
|
|
123
|
+
r.congestion_window = cmp::max(
|
|
124
|
+
r.congestion_window,
|
|
125
|
+
r.max_datagram_size * MINIMUM_WINDOW_PACKETS,
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
r.bytes_acked_ca =
|
|
129
|
+
(r.congestion_window as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
130
|
+
|
|
131
|
+
r.ssthresh.update(r.congestion_window, r.hystart.in_css());
|
|
132
|
+
|
|
133
|
+
if r.hystart.in_css() {
|
|
134
|
+
r.hystart.congestion_event();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
fn checkpoint(_r: &mut Congestion) {}
|
|
140
|
+
|
|
141
|
+
fn rollback(_r: &mut Congestion) -> bool {
|
|
142
|
+
true
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#[cfg(feature = "qlog")]
|
|
146
|
+
pub fn state_str(r: &Congestion, now: Instant) -> &'static str {
|
|
147
|
+
if r.hystart.in_css() {
|
|
148
|
+
"conservative_slow_start"
|
|
149
|
+
} else if r.congestion_window < r.ssthresh.get() {
|
|
150
|
+
"slow_start"
|
|
151
|
+
} else if r.in_congestion_recovery(now) {
|
|
152
|
+
"recovery"
|
|
153
|
+
} else {
|
|
154
|
+
"congestion_avoidance"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
fn debug_fmt(_r: &Congestion, _f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
159
|
+
Ok(())
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
#[cfg(test)]
|
|
163
|
+
mod tests {
|
|
164
|
+
use crate::CongestionControlAlgorithm;
|
|
165
|
+
|
|
166
|
+
use super::*;
|
|
167
|
+
|
|
168
|
+
use crate::recovery::congestion::recovery::LegacyRecovery;
|
|
169
|
+
use crate::recovery::congestion::test_sender::TestSender;
|
|
170
|
+
use crate::recovery::RecoveryOps;
|
|
171
|
+
|
|
172
|
+
use std::time::Duration;
|
|
173
|
+
|
|
174
|
+
fn test_sender() -> TestSender {
|
|
175
|
+
TestSender::new(CongestionControlAlgorithm::Reno, false)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
#[test]
|
|
179
|
+
fn reno_init() {
|
|
180
|
+
let mut cfg = crate::Config::new(crate::PROTOCOL_VERSION).unwrap();
|
|
181
|
+
cfg.set_cc_algorithm(CongestionControlAlgorithm::Reno);
|
|
182
|
+
|
|
183
|
+
let r = LegacyRecovery::new(&cfg);
|
|
184
|
+
|
|
185
|
+
assert!(r.cwnd() > 0);
|
|
186
|
+
assert_eq!(r.bytes_in_flight(), 0);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#[test]
|
|
190
|
+
fn reno_slow_start() {
|
|
191
|
+
let mut sender = test_sender();
|
|
192
|
+
let size = sender.max_datagram_size;
|
|
193
|
+
|
|
194
|
+
// Send initcwnd full MSS packets to become no longer app limited
|
|
195
|
+
for _ in 0..sender.initial_congestion_window_packets {
|
|
196
|
+
sender.send_packet(size);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
let cwnd_prev = sender.congestion_window;
|
|
200
|
+
|
|
201
|
+
sender.ack_n_packets(1, size);
|
|
202
|
+
|
|
203
|
+
// Check if cwnd increased by packet size (slow start).
|
|
204
|
+
assert_eq!(sender.congestion_window, cwnd_prev + size);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
#[test]
|
|
208
|
+
fn reno_slow_start_multi_acks() {
|
|
209
|
+
let mut sender = test_sender();
|
|
210
|
+
let size = sender.max_datagram_size;
|
|
211
|
+
|
|
212
|
+
// Send initcwnd full MSS packets to become no longer app limited
|
|
213
|
+
for _ in 0..sender.initial_congestion_window_packets {
|
|
214
|
+
sender.send_packet(size);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
let cwnd_prev = sender.congestion_window;
|
|
218
|
+
|
|
219
|
+
sender.ack_n_packets(3, size);
|
|
220
|
+
|
|
221
|
+
// Acked 3 packets.
|
|
222
|
+
assert_eq!(sender.congestion_window, cwnd_prev + size * 3);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#[test]
|
|
226
|
+
fn reno_congestion_event() {
|
|
227
|
+
let mut sender = test_sender();
|
|
228
|
+
let size = sender.max_datagram_size;
|
|
229
|
+
|
|
230
|
+
let prev_cwnd = sender.congestion_window;
|
|
231
|
+
|
|
232
|
+
sender.send_packet(size);
|
|
233
|
+
sender.lose_n_packets(1, size, None);
|
|
234
|
+
|
|
235
|
+
// In Reno, after congestion event, cwnd will be cut in half.
|
|
236
|
+
assert_eq!(prev_cwnd / 2, sender.congestion_window);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
#[test]
|
|
240
|
+
fn reno_congestion_avoidance() {
|
|
241
|
+
let mut sender = test_sender();
|
|
242
|
+
let size = sender.max_datagram_size;
|
|
243
|
+
|
|
244
|
+
// Send initcwnd full MSS packets to become no longer app limited
|
|
245
|
+
for _ in 0..14 {
|
|
246
|
+
sender.send_packet(size);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
let rtt = Duration::from_millis(100);
|
|
250
|
+
let prev_cwnd = sender.congestion_window;
|
|
251
|
+
|
|
252
|
+
sender.advance_time(rtt);
|
|
253
|
+
sender.lose_n_packets(1, size, None);
|
|
254
|
+
|
|
255
|
+
// After congestion event, cwnd will be reduced.
|
|
256
|
+
let cur_cwnd = (prev_cwnd as f64 * LOSS_REDUCTION_FACTOR) as usize;
|
|
257
|
+
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
258
|
+
|
|
259
|
+
sender.update_rtt(rtt);
|
|
260
|
+
sender.advance_time(2 * rtt);
|
|
261
|
+
|
|
262
|
+
sender.ack_n_packets(13, size);
|
|
263
|
+
// Acked packets were sent before the loss event, window does not
|
|
264
|
+
// increase.
|
|
265
|
+
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
266
|
+
|
|
267
|
+
for _ in 0..7 {
|
|
268
|
+
sender.send_packet(size);
|
|
269
|
+
}
|
|
270
|
+
sender.advance_time(rtt);
|
|
271
|
+
sender.ack_n_packets(2, size);
|
|
272
|
+
// Not enough ACKed, window does not increase.
|
|
273
|
+
assert_eq!(sender.congestion_window, cur_cwnd);
|
|
274
|
+
|
|
275
|
+
sender.ack_n_packets(1, size);
|
|
276
|
+
// Expect cwnd increased by MSS
|
|
277
|
+
assert_eq!(sender.congestion_window, cur_cwnd + size);
|
|
278
|
+
|
|
279
|
+
for _ in 0..7 {
|
|
280
|
+
sender.send_packet(size);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Expect a second window increase after a cwnd's worth of ACKs.
|
|
284
|
+
sender.ack_n_packets(5, size);
|
|
285
|
+
// Not yet, one more ACK needed.
|
|
286
|
+
assert_eq!(sender.congestion_window, cur_cwnd + size);
|
|
287
|
+
sender.ack_n_packets(1, size);
|
|
288
|
+
// Expect cwnd increased by MSS
|
|
289
|
+
assert_eq!(sender.congestion_window, cur_cwnd + 2 * size);
|
|
290
|
+
}
|
|
291
|
+
}
|