Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify congestion control file organization #93

Merged
merged 11 commits into from
Dec 12, 2023
2 changes: 1 addition & 1 deletion cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN"]
"PacketSendContext" = "quic_packet_send_context_t"
"TlsConfigSelectMethods" = "quic_tls_config_select_methods_t"
"TlsConfigSelectorContext" = "quic_tls_config_select_context_t"
"CongestionControlAlgorithm" = "quic_congestion_control_algorithm"
"Http3Connection" = "http3_conn_t"
"Http3Config" = "http3_config_t"
"Http3Context" = "http3_context_t"
Expand All @@ -50,7 +51,6 @@ exclude = ["MAX_CID_LEN", "MIN_CLIENT_INITIAL_LEN"]
"iovec" = "struct iovec"
"sockaddr" = "struct sockaddr"
"sockaddr_storage" = "struct sockaddr_storage"
"CongestionControlAlgorithm" = "quic_congestion_control_algorithm"

[enum]
rename_variants = "QualifiedScreamingSnakeCase"
Expand Down
File renamed without changes.
File renamed without changes.
63 changes: 49 additions & 14 deletions src/congestion_control/congestion_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub trait CongestionController {
fn on_sent(&mut self, now: Instant, packet: &mut SentPacket, bytes_in_flight: u64);

/// Callback for ack packets preprocessing.
fn begin_ack(&mut self, now: Instant, bytes_in_flight: u64) {}
fn begin_ack(&mut self, now: Instant, bytes_in_flight: u64);

/// Callback for processing each ack packet.
fn on_ack(
Expand All @@ -125,11 +125,10 @@ pub trait CongestionController {
app_limited: bool,
rtt: &RttEstimator,
bytes_in_flight: u64,
) {
}
);

/// Callback for Updating states after all ack packets are processed.
fn end_ack(&mut self) {}
fn end_ack(&mut self);

/// Congestion event.
fn on_congestion_event(
Expand All @@ -139,12 +138,11 @@ pub trait CongestionController {
is_persistent_congestion: bool,
lost_bytes: u64,
bytes_in_flight: u64,
) {
}
);

/// Check if in slow start.
fn in_slow_start(&self) -> bool {
false
true
}

/// Check if in recovery mode.
Expand Down Expand Up @@ -215,6 +213,11 @@ pub fn build_congestion_controller(conf: &RecoveryConfig) -> Box<dyn CongestionC

#[cfg(test)]
mod tests {
use super::*;
use crate::Config;
use crate::Result;
use std::time;

#[test]
fn congestion_control_name() {
use super::*;
Expand All @@ -239,17 +242,49 @@ mod tests {
assert_eq!(CongestionControlAlgorithm::from_str(name), algor);
}
}
}

#[path = "copa/copa.rs"]
mod copa;
#[test]
fn congestion_control_build_congestion_controller() -> Result<()> {
let mut config = Config::new()?;

let cc = build_congestion_controller(&config.recovery);
assert_eq!(cc.name(), "CUBIC");
assert_eq!(cc.in_slow_start(), true);
assert_eq!(cc.in_recovery(Instant::now()), false);
assert_eq!(
cc.initial_window(),
config.recovery.initial_congestion_window * config.recovery.max_datagram_size as u64
);
assert_eq!(
cc.minimal_window(),
config.recovery.min_congestion_window * config.recovery.max_datagram_size as u64
);
assert_eq!(
cc.congestion_window(),
cc.minimal_window().max(cc.initial_window())
);
assert!(cc.pacing_rate().is_some());
assert_eq!(format!("{:?}", cc), "congestion controller.");

config.set_congestion_control_algorithm(CongestionControlAlgorithm::Bbr);
let cc = build_congestion_controller(&config.recovery);
assert_eq!(cc.name(), "BBR");

config.set_congestion_control_algorithm(CongestionControlAlgorithm::Bbr3);
let cc = build_congestion_controller(&config.recovery);
assert_eq!(cc.name(), "BBRv3");

config.set_congestion_control_algorithm(CongestionControlAlgorithm::Copa);
let cc = build_congestion_controller(&config.recovery);
assert_eq!(cc.name(), "COPA");

Ok(())
}
}

#[path = "bbr/bbr.rs"]
mod bbr;

#[path = "bbr3/bbr3.rs"]
mod bbr3;

mod copa;
mod cubic;
mod delivery_rate;
mod hystart_plus_plus;
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/congestion_control/cubic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ impl CongestionController for Cubic {
}
}

fn begin_ack(&mut self, now: Instant, bytes_in_flight: u64) {
// Do nothing.
}

fn on_ack(
&mut self,
packet: &mut SentPacket,
Expand Down
Loading