Skip to content

Commit

Permalink
Add congestion_control_algor option for tquic_client/tquic_server
Browse files Browse the repository at this point in the history
  • Loading branch information
iyangsj committed Dec 11, 2023
1 parent 9a2b843 commit 0259e22
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/src/bin/tquic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ use tquic::h3::connection::Http3Connection;
use tquic::h3::Header;
use tquic::h3::Http3Config;
use tquic::Config;
use tquic::CongestionControlAlgorithm;
use tquic::Connection;
use tquic::Endpoint;
use tquic::MultipathAlgorithm;
Expand Down Expand Up @@ -145,6 +146,10 @@ pub struct ClientOpt {
#[clap(long)]
pub disable_stateless_reset: bool,

/// Congestion control algorithm.
#[clap(long, default_value = "CUBIC")]
pub congestion_control_algor: CongestionControlAlgorithm,

/// Enable multipath transport.
#[clap(long)]
pub enable_multipath: bool,
Expand Down Expand Up @@ -385,6 +390,7 @@ impl Worker {
config.set_send_batch_size(option.send_batch_size);
config.set_recv_udp_payload_size(option.recv_udp_payload_size);
config.set_send_udp_payload_size(option.send_udp_payload_size);
config.set_congestion_control_algorithm(option.congestion_control_algor);
config.set_multipath(option.enable_multipath);
config.set_multipath_algor(option.multipath_algor);
let tls_config =
Expand Down
6 changes: 6 additions & 0 deletions apps/src/bin/tquic_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use tquic::h3::Header;
use tquic::h3::Http3Config;
use tquic::h3::NameValue;
use tquic::Config;
use tquic::CongestionControlAlgorithm;
use tquic::Connection;
use tquic::Endpoint;
use tquic::Error;
Expand Down Expand Up @@ -94,6 +95,10 @@ pub struct ServerOpt {
#[clap(long)]
pub disable_stateless_reset: bool,

/// Congestion control algorithm.
#[clap(long, default_value = "CUBIC")]
pub congestion_control_algor: CongestionControlAlgorithm,

/// Enable multipath transport.
#[clap(long)]
pub enable_multipath: bool,
Expand Down Expand Up @@ -163,6 +168,7 @@ impl Server {
config.set_max_handshake_timeout(option.handshake_timeout);
config.set_max_idle_timeout(option.idle_timeout);
config.set_initial_rtt(option.initial_rtt);
config.set_congestion_control_algorithm(option.congestion_control_algor);
config.set_send_batch_size(option.send_batch_size);
config.set_multipath(option.enable_multipath);
config.set_multipath_algor(option.multipath_algor);
Expand Down
49 changes: 49 additions & 0 deletions src/congestion_control/congestion_control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

#![allow(unused_variables)]

use core::str::FromStr;
use std::any::Any;
use std::fmt;
use std::time::Instant;

use crate::connection::rtt::RttEstimator;
use crate::connection::space::SentPacket;
use crate::Error;
use crate::RecoveryConfig;
use crate::Result;
pub use bbr::Bbr;
pub use bbr::BbrConfig;
pub use bbr3::Bbr3;
Expand Down Expand Up @@ -60,6 +63,24 @@ pub enum CongestionControlAlgorithm {
Copa,
}

impl FromStr for CongestionControlAlgorithm {
type Err = Error;

fn from_str(algor: &str) -> Result<CongestionControlAlgorithm> {
if algor.eq_ignore_ascii_case("cubic") {
Ok(CongestionControlAlgorithm::Cubic)
} else if algor.eq_ignore_ascii_case("bbr") {
Ok(CongestionControlAlgorithm::Bbr)
} else if algor.eq_ignore_ascii_case("bbr3") {
Ok(CongestionControlAlgorithm::Bbr3)
} else if algor.eq_ignore_ascii_case("copa") {
Ok(CongestionControlAlgorithm::Copa)
} else {
Err(Error::InvalidConfig("unknown".into()))
}
}
}

/// Congestion control statistics.
#[derive(Debug, Default, Clone)]
pub struct CongestionStats {
Expand Down Expand Up @@ -192,6 +213,34 @@ pub fn build_congestion_controller(conf: &RecoveryConfig) -> Box<dyn CongestionC
}
}

#[cfg(test)]
mod tests {
#[test]
fn congestion_control_name() {
use super::*;

let cases = [
("cubic", Ok(CongestionControlAlgorithm::Cubic)),
("Cubic", Ok(CongestionControlAlgorithm::Cubic)),
("CUBIC", Ok(CongestionControlAlgorithm::Cubic)),
("bbr", Ok(CongestionControlAlgorithm::Bbr)),
("Bbr", Ok(CongestionControlAlgorithm::Bbr)),
("BBR", Ok(CongestionControlAlgorithm::Bbr)),
("bbr3", Ok(CongestionControlAlgorithm::Bbr3)),
("Bbr3", Ok(CongestionControlAlgorithm::Bbr3)),
("BBR3", Ok(CongestionControlAlgorithm::Bbr3)),
("copa", Ok(CongestionControlAlgorithm::Copa)),
("Copa", Ok(CongestionControlAlgorithm::Copa)),
("COPA", Ok(CongestionControlAlgorithm::Copa)),
("cubci", Err(Error::InvalidConfig("unknown".into()))),
];

for (name, algor) in cases {
assert_eq!(CongestionControlAlgorithm::from_str(name), algor);
}
}
}

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

Expand Down

0 comments on commit 0259e22

Please sign in to comment.