mod bbr;
mod bbr2;
pub mod pacer;
mod recovery;
use std::fmt::Debug;
use std::str::FromStr;
use std::time::Instant;
pub use self::recovery::GRecovery;
use crate::recovery::bandwidth::Bandwidth;
use crate::recovery::rtt::RttStats;
use crate::recovery::RecoveryStats;
#[derive(Debug)]
pub struct Lost {
pub(super) packet_number: u64,
pub(super) bytes_lost: usize,
}
#[derive(Debug)]
pub struct Acked {
pub(super) pkt_num: u64,
pub(super) time_sent: Instant,
}
pub(super) trait CongestionControl: Debug {
#[cfg(feature = "qlog")]
fn state_str(&self) -> &'static str;
fn get_congestion_window(&self) -> usize;
fn get_congestion_window_in_packets(&self) -> usize;
fn can_send(&self, bytes_in_flight: usize) -> bool;
fn on_packet_sent(
&mut self, sent_time: Instant, bytes_in_flight: usize,
packet_number: u64, bytes: usize, is_retransmissible: bool,
);
fn on_packet_neutered(&mut self, _packet_number: u64) {}
#[allow(clippy::too_many_arguments)]
fn on_congestion_event(
&mut self, rtt_updated: bool, prior_in_flight: usize,
bytes_in_flight: usize, event_time: Instant, acked_packets: &[Acked],
lost_packets: &[Lost], least_unacked: u64, rtt_stats: &RttStats,
recovery_stats: &mut RecoveryStats,
);
fn on_retransmission_timeout(&mut self, packets_retransmitted: bool);
#[allow(dead_code)]
fn on_connection_migration(&mut self);
fn limit_cwnd(&mut self, _max_cwnd: usize) {}
fn is_in_recovery(&self) -> bool;
#[allow(dead_code)]
fn is_cwnd_limited(&self, bytes_in_flight: usize) -> bool;
fn pacing_rate(
&self, bytes_in_flight: usize, rtt_stats: &RttStats,
) -> Bandwidth;
fn bandwidth_estimate(&self, rtt_stats: &RttStats) -> Bandwidth;
fn max_bandwidth(&self) -> Bandwidth;
fn update_mss(&mut self, new_mss: usize);
fn on_app_limited(&mut self, _bytes_in_flight: usize) {}
#[cfg(feature = "qlog")]
fn ssthresh(&self) -> Option<u64> {
None
}
}
#[derive(Debug, Default, Copy, Clone, PartialEq)]
#[repr(C)]
#[doc(hidden)]
pub struct BbrParams {
pub startup_cwnd_gain: Option<f32>,
pub startup_pacing_gain: Option<f32>,
pub full_bw_threshold: Option<f32>,
pub startup_full_bw_rounds: Option<usize>,
pub startup_full_loss_count: Option<usize>,
pub drain_cwnd_gain: Option<f32>,
pub drain_pacing_gain: Option<f32>,
pub enable_reno_coexistence: Option<bool>,
pub enable_overestimate_avoidance: Option<bool>,
pub choose_a0_point_fix: Option<bool>,
pub probe_bw_probe_up_pacing_gain: Option<f32>,
pub probe_bw_probe_down_pacing_gain: Option<f32>,
pub probe_bw_cwnd_gain: Option<f32>,
pub probe_bw_up_cwnd_gain: Option<f32>,
pub probe_rtt_pacing_gain: Option<f32>,
pub probe_rtt_cwnd_gain: Option<f32>,
pub max_probe_up_queue_rounds: Option<usize>,
pub loss_threshold: Option<f32>,
pub use_bytes_delivered_for_inflight_hi: Option<bool>,
pub decrease_startup_pacing_at_end_of_round: Option<bool>,
pub bw_lo_reduction_strategy: Option<BbrBwLoReductionStrategy>,
pub ignore_app_limited_for_no_bandwidth_growth: Option<bool>,
pub initial_pacing_rate_bytes_per_second: Option<u64>,
pub scale_pacing_rate_by_mss: Option<bool>,
pub disable_probe_down_early_exit: Option<bool>,
pub time_sent_set_to_now: Option<bool>,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[repr(C)]
#[doc(hidden)]
pub enum BbrBwLoReductionStrategy {
Default = 0,
MinRttReduction = 1,
InflightReduction = 2,
CwndReduction = 3,
}
#[doc(hidden)]
impl FromStr for BbrBwLoReductionStrategy {
type Err = crate::Error;
fn from_str(name: &str) -> Result<Self, Self::Err> {
match name {
"default" => Ok(BbrBwLoReductionStrategy::Default),
"minrtt" => Ok(BbrBwLoReductionStrategy::MinRttReduction),
"inflight" => Ok(BbrBwLoReductionStrategy::InflightReduction),
"cwnd" => Ok(BbrBwLoReductionStrategy::CwndReduction),
_ => Err(crate::Error::CongestionControl),
}
}
}