ngtcp2_bbr.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* defined(HAVE_CONFIG_H) */
  30. #include <ngtcp2/ngtcp2.h>
  31. #include "ngtcp2_cc.h"
  32. #include "ngtcp2_window_filter.h"
  33. typedef struct ngtcp2_rst ngtcp2_rst;
  34. typedef enum ngtcp2_bbr_state {
  35. NGTCP2_BBR_STATE_STARTUP,
  36. NGTCP2_BBR_STATE_DRAIN,
  37. NGTCP2_BBR_STATE_PROBE_BW_DOWN,
  38. NGTCP2_BBR_STATE_PROBE_BW_CRUISE,
  39. NGTCP2_BBR_STATE_PROBE_BW_REFILL,
  40. NGTCP2_BBR_STATE_PROBE_BW_UP,
  41. NGTCP2_BBR_STATE_PROBE_RTT,
  42. } ngtcp2_bbr_state;
  43. typedef enum ngtcp2_bbr_ack_phase {
  44. NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STARTING,
  45. NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_STOPPING,
  46. NGTCP2_BBR_ACK_PHASE_ACKS_PROBE_FEEDBACK,
  47. NGTCP2_BBR_ACK_PHASE_ACKS_REFILLING,
  48. } ngtcp2_bbr_ack_phase;
  49. /*
  50. * ngtcp2_cc_bbr is BBR v2 congestion controller, described in
  51. * https://datatracker.ietf.org/doc/html/draft-cardwell-iccrg-bbr-congestion-control-01
  52. */
  53. typedef struct ngtcp2_cc_bbr {
  54. ngtcp2_cc cc;
  55. uint64_t initial_cwnd;
  56. ngtcp2_rst *rst;
  57. ngtcp2_rand rand;
  58. ngtcp2_rand_ctx rand_ctx;
  59. /* max_bw_filter for tracking the maximum recent delivery rate
  60. samples for estimating max_bw. */
  61. ngtcp2_window_filter max_bw_filter;
  62. ngtcp2_window_filter extra_acked_filter;
  63. ngtcp2_duration min_rtt;
  64. ngtcp2_tstamp min_rtt_stamp;
  65. ngtcp2_tstamp probe_rtt_done_stamp;
  66. int probe_rtt_round_done;
  67. uint64_t prior_cwnd;
  68. int idle_restart;
  69. ngtcp2_tstamp extra_acked_interval_start;
  70. uint64_t extra_acked_delivered;
  71. /* Congestion signals */
  72. int loss_in_round;
  73. uint64_t bw_latest;
  74. uint64_t inflight_latest;
  75. /* Lower bounds */
  76. uint64_t bw_lo;
  77. uint64_t inflight_lo;
  78. /* Round counting */
  79. uint64_t next_round_delivered;
  80. int round_start;
  81. uint64_t round_count;
  82. /* Full pipe */
  83. uint64_t full_bw;
  84. size_t full_bw_count;
  85. int full_bw_reached;
  86. int full_bw_now;
  87. /* Pacing rate */
  88. uint64_t pacing_gain_h;
  89. ngtcp2_bbr_state state;
  90. uint64_t cwnd_gain_h;
  91. int loss_round_start;
  92. uint64_t loss_round_delivered;
  93. uint64_t rounds_since_bw_probe;
  94. uint64_t max_bw;
  95. uint64_t bw;
  96. uint64_t cycle_count;
  97. uint64_t extra_acked;
  98. uint64_t bytes_lost_in_round;
  99. size_t loss_events_in_round;
  100. uint64_t offload_budget;
  101. uint64_t probe_up_cnt;
  102. ngtcp2_tstamp cycle_stamp;
  103. ngtcp2_bbr_ack_phase ack_phase;
  104. ngtcp2_duration bw_probe_wait;
  105. int bw_probe_samples;
  106. size_t bw_probe_up_rounds;
  107. uint64_t bw_probe_up_acks;
  108. uint64_t inflight_hi;
  109. int probe_rtt_expired;
  110. ngtcp2_duration probe_rtt_min_delay;
  111. ngtcp2_tstamp probe_rtt_min_stamp;
  112. int in_loss_recovery;
  113. uint64_t round_count_at_recovery;
  114. uint64_t max_inflight;
  115. ngtcp2_tstamp congestion_recovery_start_ts;
  116. } ngtcp2_cc_bbr;
  117. void ngtcp2_cc_bbr_init(ngtcp2_cc_bbr *bbr, ngtcp2_log *log,
  118. ngtcp2_conn_stat *cstat, ngtcp2_rst *rst,
  119. ngtcp2_tstamp initial_ts, ngtcp2_rand rand,
  120. const ngtcp2_rand_ctx *rand_ctx);
  121. #endif /* !defined(NGTCP2_BBR_H) */