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_BBR2_H 26 #define NGTCP2_BBR2_H 27 28 #ifdef HAVE_CONFIG_H 29 # include <config.h> 30 #endif /* 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 39 typedef enum ngtcp2_bbr2_state { 40 NGTCP2_BBR2_STATE_STARTUP, 41 NGTCP2_BBR2_STATE_DRAIN, 42 NGTCP2_BBR2_STATE_PROBE_BW_DOWN, 43 NGTCP2_BBR2_STATE_PROBE_BW_CRUISE, 44 NGTCP2_BBR2_STATE_PROBE_BW_REFILL, 45 NGTCP2_BBR2_STATE_PROBE_BW_UP, 46 NGTCP2_BBR2_STATE_PROBE_RTT, 47 } ngtcp2_bbr2_state; 48 49 typedef enum ngtcp2_bbr2_ack_phase { 50 NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STARTING, 51 NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_STOPPING, 52 NGTCP2_BBR2_ACK_PHASE_ACKS_PROBE_FEEDBACK, 53 NGTCP2_BBR2_ACK_PHASE_ACKS_REFILLING, 54 } ngtcp2_bbr2_ack_phase; 55 56 /* 57 * ngtcp2_bbr2_cc is BBR v2 congestion controller, described in 58 * https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01 59 */ 60 typedef struct ngtcp2_bbr2_cc { 61 ngtcp2_cc_base ccb; 62 63 uint64_t initial_cwnd; 64 ngtcp2_rst *rst; 65 ngtcp2_rand rand; 66 ngtcp2_rand_ctx rand_ctx; 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 uint64_t prior_cwnd; 79 int idle_restart; 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_lo; 90 uint64_t inflight_lo; 91 92 /* Round counting */ 93 uint64_t next_round_delivered; 94 int round_start; 95 uint64_t round_count; 96 97 /* Full pipe */ 98 int filled_pipe; 99 uint64_t full_bw; 100 size_t full_bw_count; 101 102 /* Pacing rate */ 103 double pacing_gain; 104 105 ngtcp2_bbr2_state state; 106 double cwnd_gain; 107 108 int loss_round_start; 109 uint64_t loss_round_delivered; 110 uint64_t rounds_since_bw_probe; 111 uint64_t max_bw; 112 uint64_t bw; 113 uint64_t cycle_count; 114 uint64_t extra_acked; 115 uint64_t bytes_lost_in_round; 116 size_t loss_events_in_round; 117 uint64_t offload_budget; 118 uint64_t probe_up_cnt; 119 ngtcp2_tstamp cycle_stamp; 120 ngtcp2_bbr2_ack_phase ack_phase; 121 ngtcp2_duration bw_probe_wait; 122 int bw_probe_samples; 123 size_t bw_probe_up_rounds; 124 uint64_t bw_probe_up_acks; 125 uint64_t inflight_hi; 126 uint64_t bw_hi; 127 int probe_rtt_expired; 128 ngtcp2_duration probe_rtt_min_delay; 129 ngtcp2_tstamp probe_rtt_min_stamp; 130 int in_loss_recovery; 131 int packet_conservation; 132 uint64_t max_inflight; 133 ngtcp2_tstamp congestion_recovery_start_ts; 134 uint64_t congestion_recovery_next_round_delivered; 135 136 uint64_t prior_inflight_lo; 137 uint64_t prior_inflight_hi; 138 uint64_t prior_bw_lo; 139 } ngtcp2_bbr2_cc; 140 141 int ngtcp2_cc_bbr2_cc_init(ngtcp2_cc *cc, ngtcp2_log *log, 142 ngtcp2_conn_stat *cstat, ngtcp2_rst *rst, 143 ngtcp2_tstamp initial_ts, ngtcp2_rand rand, 144 const ngtcp2_rand_ctx *rand_ctx, 145 const ngtcp2_mem *mem); 146 147 void ngtcp2_cc_bbr2_cc_free(ngtcp2_cc *cc, const ngtcp2_mem *mem); 148 149 #endif /* NGTCP2_BBR2_H */ 150