quiche/recovery/congestion/bbr2/init.rs
1// Copyright (C) 2022, 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
27use super::*;
28
29use std::time::Instant;
30
31// BBR2 Functions at Initialization.
32//
33
34// 4.2.1. Initialization
35pub fn bbr2_init(r: &mut Congestion) {
36 let now = Instant::now();
37
38 let bbr = &mut r.bbr2_state;
39 bbr.min_rtt = r.initial_rtt;
40 bbr.min_rtt_stamp = now;
41 bbr.probe_rtt_done_stamp = None;
42 bbr.probe_rtt_round_done = false;
43 bbr.prior_cwnd = 0;
44 bbr.idle_restart = false;
45 bbr.extra_acked_interval_start = now;
46 bbr.extra_acked_delivered = 0;
47 bbr.bw_lo = u64::MAX;
48 bbr.bw_hi = u64::MAX;
49 bbr.inflight_lo = usize::MAX;
50 bbr.inflight_hi = usize::MAX;
51 bbr.probe_up_cnt = usize::MAX;
52
53 r.send_quantum = r.max_datagram_size;
54
55 per_loss::bbr2_reset_congestion_signals(r);
56 per_loss::bbr2_reset_lower_bounds(r);
57 bbr2_init_round_counting(r);
58 bbr2_init_full_pipe(r);
59 pacing::bbr2_init_pacing_rate(r);
60 bbr2_enter_startup(r);
61}
62
63// 4.5.1. BBR.round_count: Tracking Packet-Timed Round Trips
64fn bbr2_init_round_counting(r: &mut Congestion) {
65 let bbr = &mut r.bbr2_state;
66
67 bbr.next_round_delivered = 0;
68 bbr.round_start = false;
69 bbr.round_count = 0;
70}
71
72// 4.3.1.1. Startup Dynamics
73pub fn bbr2_enter_startup(r: &mut Congestion) {
74 let bbr = &mut r.bbr2_state;
75
76 bbr.state = BBR2StateMachine::Startup;
77 bbr.pacing_gain = STARTUP_PACING_GAIN;
78 bbr.cwnd_gain = STARTUP_CWND_GAIN;
79}
80
81// 4.3.1.2. Exiting Startup Based on Bandwidth Plateau
82fn bbr2_init_full_pipe(r: &mut Congestion) {
83 let bbr = &mut r.bbr2_state;
84
85 bbr.filled_pipe = false;
86 bbr.full_bw = 0;
87 bbr.full_bw_count = 0;
88}