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

feat(s2n-quic-qns): add ability to set congestion controller in interop/perf #1917

Merged
merged 3 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions quic/s2n-quic-qns/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,50 @@ pub mod perf;

pub use interop::Interop;
pub use perf::Perf;

use crate::{
congestion_control::{CongestionControl, CongestionController::*},
tls,
tls::TlsProviders::*,
Result,
};
use s2n_quic::{
client,
client::ClientProviders,
provider::congestion_controller::{Bbr, Cubic},
};

/// Build and start a client with the given TLS configuration and Congestion Controller
pub fn build(
builder: client::Builder<impl ClientProviders>,
alpns: &[String],
tls_client: &tls::Client,
congestion_control: &CongestionControl,
) -> Result<s2n_quic::Client> {
macro_rules! build {
($build_tls:ident, $cc:ident $(, $alpns:ident)?) => {
{
let tls = tls_client.$build_tls($($alpns)?)?;

builder
.with_tls(tls)?
.with_congestion_controller($cc::default())?
.start()
.unwrap()
}
}
}

Ok(
match (tls_client.tls, congestion_control.congestion_controller) {
#[cfg(unix)]
(S2N, Cubic) => build!(build_s2n_tls, Cubic, alpns),
#[cfg(unix)]
(S2N, Bbr) => build!(build_s2n_tls, Bbr, alpns),
(Rustls, Cubic) => build!(build_rustls, Cubic, alpns),
(Rustls, Bbr) => build!(build_rustls, Bbr, alpns),
(Null, Cubic) => build!(build_null, Cubic),
(Null, Bbr) => build!(build_null, Bbr),
WesleyRosenblum marked this conversation as resolved.
Show resolved Hide resolved
},
)
}
13 changes: 10 additions & 3 deletions quic/s2n-quic-qns/src/client/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{
client,
client::{h09, h3},
interop::Testcase,
task, tls, Result,
Expand Down Expand Up @@ -54,6 +55,9 @@ pub struct Interop {

#[structopt(flatten)]
runtime: crate::runtime::Runtime,

#[structopt(flatten)]
congestion_controller: crate::congestion_control::CongestionControl,
}

impl Interop {
Expand Down Expand Up @@ -157,9 +161,12 @@ impl Interop {
.with_limits(limits)?
.with_event(event::tracing::Subscriber::default())?;

let client = self.tls.build(client, &self.application_protocols)?;

Ok(client)
client::build(
client,
&self.application_protocols,
&self.tls,
&self.congestion_controller,
)
}

async fn endpoints(&self) -> Result<HashMap<Host<&str>, Connect>> {
Expand Down
18 changes: 12 additions & 6 deletions quic/s2n-quic-qns/src/client/perf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use crate::{perf, task, tls, Result};
use s2n_quic::{client, provider::event, Client, Connection};
use crate::{client, perf, task, tls, Result};
use s2n_quic::{client::Connect, provider::event, Client, Connection};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
Expand Down Expand Up @@ -53,6 +53,9 @@ pub struct Perf {

#[structopt(flatten)]
runtime: crate::runtime::Runtime,

#[structopt(flatten)]
congestion_controller: crate::congestion_control::CongestionControl,
}

impl Perf {
Expand All @@ -69,7 +72,7 @@ impl Perf {
let send = self.send;
let receive = self.receive;

let mut connect = client::Connect::new((self.ip, self.port));
let mut connect = Connect::new((self.ip, self.port));
if let Some(server_name) = self.server_name.as_deref() {
connect = connect.with_server_name(server_name);
} else {
Expand Down Expand Up @@ -153,8 +156,11 @@ impl Perf {
.with_io(io)?
.with_event(subscriber)?;

let client = self.tls.build(client, &self.application_protocols)?;

Ok(client)
client::build(
client,
&self.application_protocols,
&self.tls,
&self.congestion_controller,
)
}
}
34 changes: 34 additions & 0 deletions quic/s2n-quic-qns/src/congestion_control.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use core::str::FromStr;
use std::io;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct CongestionControl {
/// The congestion controller to use
#[structopt(long = "cc", default_value = "bbr", possible_values = &["cubic","bbr"])]
pub congestion_controller: CongestionController,
}

#[derive(Copy, Clone, Debug)]
pub enum CongestionController {
Cubic,
Bbr,
}

impl FromStr for CongestionController {
type Err = crate::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"cubic" => Ok(Self::Cubic),
"bbr" => Ok(Self::Bbr),
_ => Err(io::Error::new(
io::ErrorKind::InvalidInput,
format!("Unsupported congestion controller: {s}"),
)
.into()),
}
}
}
1 change: 1 addition & 0 deletions quic/s2n-quic-qns/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub type Error = Box<dyn 'static + std::error::Error + Send + Sync>;
pub type Result<T, E = Error> = core::result::Result<T, E>;

mod client;
mod congestion_control;
mod file;
mod interop;
mod io;
Expand Down
47 changes: 47 additions & 0 deletions quic/s2n-quic-qns/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,50 @@ mod unstable;

pub use interop::Interop;
pub use perf::Perf;

use crate::{
congestion_control::{CongestionControl, CongestionController::*},
tls,
tls::TlsProviders::*,
Result,
};
use s2n_quic::{
provider::congestion_controller::{Bbr, Cubic},
server,
server::ServerProviders,
};

/// Build and start a server with the given TLS configuration and Congestion Controller
pub fn build(
builder: server::Builder<impl ServerProviders>,
alpns: &[String],
tls_server: &tls::Server,
congestion_control: &CongestionControl,
) -> Result<s2n_quic::Server> {
macro_rules! build {
($build_tls:ident, $cc:ident $(, $alpns:ident)?) => {
{
let tls = tls_server.$build_tls($($alpns)?)?;

builder
.with_tls(tls)?
.with_congestion_controller($cc::default())?
.start()
.unwrap()
}
}
}

Ok(
match (tls_server.tls, congestion_control.congestion_controller) {
#[cfg(unix)]
(S2N, Cubic) => build!(build_s2n_tls, Cubic, alpns),
#[cfg(unix)]
(S2N, Bbr) => build!(build_s2n_tls, Bbr, alpns),
(Rustls, Cubic) => build!(build_rustls, Cubic, alpns),
(Rustls, Bbr) => build!(build_rustls, Bbr, alpns),
(Null, Cubic) => build!(build_null, Cubic),
(Null, Bbr) => build!(build_null, Bbr),
},
)
}
11 changes: 10 additions & 1 deletion quic/s2n-quic-qns/src/server/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use crate::{
interop::Testcase,
server,
server::{h09, h3},
tls, Result,
};
Expand Down Expand Up @@ -42,6 +43,9 @@ pub struct Interop {

#[structopt(flatten)]
runtime: crate::runtime::Runtime,

#[structopt(flatten)]
congestion_controller: crate::congestion_control::CongestionControl,
}

impl Interop {
Expand Down Expand Up @@ -100,7 +104,12 @@ impl Interop {
EventSubscriber(1),
s2n_quic::provider::event::tracing::Subscriber::default(),
))?;
let server = self.tls.build(server, &self.application_protocols)?;
let server = server::build(
server,
&self.application_protocols,
&self.tls,
&self.congestion_controller,
)?;

eprintln!("Server listening on port {}", self.io.port);

Expand Down
12 changes: 10 additions & 2 deletions quic/s2n-quic-qns/src/server/perf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use crate::{perf, tls, Result};
use crate::{perf, server, tls, Result};
use futures::future::try_join_all;
use s2n_quic::{
provider::event,
Expand Down Expand Up @@ -36,6 +36,9 @@ pub struct Perf {

#[structopt(flatten)]
runtime: crate::runtime::Runtime,

#[structopt(flatten)]
congestion_controller: crate::congestion_control::CongestionControl,
}

impl Perf {
Expand Down Expand Up @@ -189,7 +192,12 @@ impl Perf {
.with_io(io)?
.with_event(subscriber)?;

let server = self.tls.build(server, &self.application_protocols)?;
let server = server::build(
server,
&self.application_protocols,
&self.tls,
&self.congestion_controller,
)?;

eprintln!("Server listening on port {}", self.io.port);

Expand Down
Loading