Debian Codegraph @

contrib/libngtcp2/ngtcp2/lib/ngtcp2_bbr.h

raw symbols SCIP
1 /*
2 * ngtcp2
3 *
4 * Copyright (c) 2021 ngtcp2 contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be
15 * included in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25 #ifndef NGTCP2_BBR_H
26 #define NGTCP2_BBR_H
27
28 #ifdef HAVE_CONFIG_H
29 # include <config.h>
30 #endif /* defined(HAVE_CONFIG_H) */
31
32 #include <ngtcp2/ngtcp2.h>
33
34 #include "ngtcp2_cc.h"
35 #include "ngtcp2_window_filter.h"
36
37 typedef struct ngtcp2_rst ngtcp2_rst;
38 typedef struct ngtcp2_pcg32 ngtcp2_pcg32;
39
40 typedef enum ngtcp2_bbr_state {
41 NGTCP2_BBR_STATE_STARTUP,
42 NGTCP2_BBR_STATE_DRAIN,
43 NGTCP2_BBR_STATE_PROBE_BW_DOWN,
44 NGTCP2_BBR_STATE_PROBE_BW_CRUISE,
45 NGTCP2_BBR_STATE_PROBE_BW_REFILL,
46 NGTCP2_BBR_STATE_PROBE_BW_UP,
47 NGTCP2_BBR_STATE_PROBE_RTT,
48 } ngtcp2_bbr_state;
49
50 typedef enum ngtcp2_bbr_ack_phase {
51 NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STARTING,
52 NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STOPPING,
53 NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_FEEDBACK,
54 NGTCP2_BBR_ACK_PHASE_ACKS_REFILLING,
55 } ngtcp2_bbr_ack_phase;
56
57 /*
58 * ngtcp2_cc_bbr is BBR v2 congestion controller, described in
59 * https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01
60 */
61 typedef struct ngtcp2_cc_bbr {
62 ngtcp2_cc cc;
63
64 uint64_t initial_cwnd;
65 ngtcp2_rst *rst;
66 ngtcp2_pcg32 *pcg;
67
68 /* max_bw_filter for tracking the maximum recent delivery rate
69 samples for estimating max_bw. */
70 ngtcp2_window_filter max_bw_filter;
71
72 ngtcp2_window_filter extra_acked_filter;
73
74 ngtcp2_duration min_rtt;
75 ngtcp2_tstamp min_rtt_stamp;
76 ngtcp2_tstamp probe_rtt_done_stamp;
77 int probe_rtt_round_done;
78 int idle_restart;
79 uint64_t prior_cwnd;
80 ngtcp2_tstamp extra_acked_interval_start;
81 uint64_t extra_acked_delivered;
82
83 /* Congestion signals */
84 int loss_in_round;
85 uint64_t bw_latest;
86 uint64_t inflight_latest;
87
88 /* Lower bounds */
89 uint64_t bw_shortterm;
90 uint64_t inflight_shortterm;
91
92 /* Round counting */
93 uint64_t next_round_delivered;
94 uint64_t round_count;
95 int round_start;
96
97 /* Full pipe */
98 uint64_t full_bw;
99 size_t full_bw_count;
100 int full_bw_reached;
101 int full_bw_now;
102
103 /* Pacing rate */
104 uint64_t pacing_gain_h;
105
106 ngtcp2_bbr_state state;
107 uint64_t cwnd_gain_h;
108
109 /* Backup for spurious losses */
110 uint64_t undo_bw_shortterm;
111 uint64_t undo_inflight_shortterm;
112 uint64_t undo_inflight_longterm;
113
114 uint64_t loss_round_delivered;
115 uint64_t rounds_since_bw_probe;
116 uint64_t max_bw;
117 uint64_t bw;
118 uint64_t cycle_count;
119 uint64_t extra_acked;
120 uint64_t bytes_lost_in_round;
121 size_t loss_events_in_round;
122 uint64_t offload_budget;
123 uint64_t probe_up_cnt;
124 ngtcp2_tstamp cycle_stamp;
125 ngtcp2_bbr_ack_phase ack_phase;
126 ngtcp2_duration bw_probe_wait;
127 size_t bw_probe_up_rounds;
128 uint64_t bw_probe_up_acks;
129 uint64_t inflight_longterm;
130 ngtcp2_duration probe_rtt_min_delay;
131 ngtcp2_tstamp probe_rtt_min_stamp;
132 uint64_t round_count_at_recovery;
133 uint64_t max_inflight;
134 uint64_t bdp;
135 int loss_round_start;
136 int bw_probe_samples;
137 int probe_rtt_expired;
138 int in_loss_recovery;
139 } ngtcp2_cc_bbr;
140
141 void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
142 ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
143 ngtcp2_tstamp initial_ts, ngtcp2_pcg32 *pcg);
144
145 #endif /* !defined(NGTCP2_BBR_H) */