Skip to content

Commit

Permalink
Update TCP buffer size config (#1648)
Browse files Browse the repository at this point in the history
* Rename TCP buffer size parameters, duplicate config for TLS and TCP

* Update tcp buffer size tests

* Update DEFAULT_CONFIG, add more examples

* Update DEFAULT_CONFIG
  • Loading branch information
oteffahi authored Dec 10, 2024
1 parent 74c7732 commit b5ca078
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 40 deletions.
27 changes: 21 additions & 6 deletions DEFAULT_CONFIG.json5
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
///
/// It is also possible to specify a priority range and/or a reliability setting to be used on the link.
/// For example `tcp/localhost?prio=6-7;rel=0` assigns priorities "data_low" and "background" to the established link.
///
/// For TCP and TLS links, it is possible to specify the TCP buffer sizes:
/// E.g. tcp/192.168.0.1:7447#so_sndbuf=65000;so_rcvbuf=65000
connect: {
/// timeout waiting for all endpoints connected (0: no retry, -1: infinite timeout)
/// Accepts a single value (e.g. timeout_ms: 0)
Expand Down Expand Up @@ -68,6 +71,9 @@
///
/// It is also possible to specify a priority range and/or a reliability setting to be used on the link.
/// For example `tcp/localhost?prio=6-7;rel=0` assigns priorities "data_low" and "background" to the established link.
///
/// For TCP and TLS links, it is possible to specify the TCP buffer sizes:
/// E.g. tcp/192.168.0.1:7447#so_sndbuf=65000;so_rcvbuf=65000
listen: {
/// timeout waiting for all listen endpoints (0: no retry, -1: infinite timeout)
/// Accepts a single value (e.g. timeout_ms: 0)
Expand Down Expand Up @@ -494,13 +500,22 @@
// If set to true, links that require certificates (tls/quic) will automatically disconnect when the time of expiration of the remote certificate chain is reached
// note that mTLS (client authentication) is required for a listener to disconnect a client on expiration
close_link_on_expiration: false,
/// Optional configuration for TCP system buffers sizes for TLS links
///
/// Configure TCP read buffer size (bytes)
// so_rcvbuf: 123456,
/// Configure TCP write buffer size (bytes)
// so_sndbuf: 123456,
},
/// Optional configuration for TCP system buffers sizes. Applies to TCP and TLS links.
///
/// Configure TCP read buffer size (bytes)
// tcp_rx_buffer: 123456,
/// Configure TCP write buffer size (bytes)
// tcp_tx_buffer: 123456,
// // Configure optional TCP link specific parameters
// tcp: {
// /// Optional configuration for TCP system buffers sizes for TCP links
// ///
// /// Configure TCP read buffer size (bytes)
// // so_rcvbuf: 123456,
// /// Configure TCP write buffer size (bytes)
// // so_sndbuf: 123456,
// }
},
/// Shared memory configuration.
/// NOTE: shared memory can be used only if zenoh is compiled with "shared-memory" feature, otherwise
Expand Down
15 changes: 11 additions & 4 deletions commons/zenoh-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,10 @@ validated_struct::validator! {
connect_certificate: Option<String>,
verify_name_on_connect: Option<bool>,
close_link_on_expiration: Option<bool>,
/// Configure TCP write buffer size
pub so_sndbuf: Option<u32>,
/// Configure TCP read buffer size
pub so_rcvbuf: Option<u32>,
// Skip serializing field because they contain secrets
#[serde(skip_serializing)]
root_ca_certificate_base64: Option<SecretValue>,
Expand All @@ -511,14 +515,17 @@ validated_struct::validator! {
#[serde(skip_serializing)]
connect_certificate_base64 : Option<SecretValue>,
},
pub tcp: #[derive(Default)]
TcpConf {
/// Configure TCP write buffer size
pub so_sndbuf: Option<u32>,
/// Configure TCP read buffer size
pub so_rcvbuf: Option<u32>,
},
pub unixpipe: #[derive(Default)]
UnixPipeConf {
file_access_mask: Option<u32>
},
/// Configure TCP read buffer size
pub tcp_rx_buffer: Option<u32>,
/// Configure TCP write buffer size
pub tcp_tx_buffer: Option<u32>,
},
pub shared_memory:
ShmConf {
Expand Down
4 changes: 2 additions & 2 deletions io/zenoh-link-commons/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ use zenoh_result::ZResult;
/*************************************/

pub const BIND_INTERFACE: &str = "iface";
pub const TCP_TX_BUFFER_SIZE: &str = "tcp_tx_buffer";
pub const TCP_RX_BUFFER_SIZE: &str = "tcp_rx_buffer";
pub const TCP_SO_SND_BUF: &str = "so_sndbuf";
pub const TCP_SO_RCV_BUF: &str = "so_rcvbuf";

#[derive(Clone, Debug, Serialize, Hash, PartialEq, Eq)]
pub struct Link {
Expand Down
17 changes: 8 additions & 9 deletions io/zenoh-links/zenoh-link-tcp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
//
use zenoh_config::Config as ZenohConfig;
use zenoh_link_commons::{
tcp::TcpSocketConfig, ConfigurationInspector, BIND_INTERFACE, TCP_RX_BUFFER_SIZE,
TCP_TX_BUFFER_SIZE,
tcp::TcpSocketConfig, ConfigurationInspector, BIND_INTERFACE, TCP_SO_RCV_BUF, TCP_SO_SND_BUF,
};
use zenoh_protocol::core::{parameters, Config};
use zenoh_result::{zerror, ZResult};
Expand All @@ -25,17 +24,17 @@ pub struct TcpConfigurator;
impl ConfigurationInspector<ZenohConfig> for TcpConfigurator {
fn inspect_config(&self, config: &ZenohConfig) -> ZResult<String> {
let mut ps: Vec<(&str, &str)> = vec![];
let c = config.transport().link();
let c = config.transport().link().tcp();

let rx_buffer_size;
if let Some(size) = c.tcp_rx_buffer {
if let Some(size) = c.so_rcvbuf() {
rx_buffer_size = size.to_string();
ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size));
ps.push((TCP_SO_RCV_BUF, &rx_buffer_size));
}
let tx_buffer_size;
if let Some(size) = c.tcp_tx_buffer {
if let Some(size) = c.so_sndbuf() {
tx_buffer_size = size.to_string();
ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size));
ps.push((TCP_SO_SND_BUF, &tx_buffer_size));
}

Ok(parameters::from_iter(ps.drain(..)))
Expand All @@ -56,13 +55,13 @@ impl<'a> TcpLinkConfig<'a> {
bind_iface: config.get(BIND_INTERFACE),
};

if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_RCV_BUF) {
tcp_config.rx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?,
);
};
if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_SND_BUF) {
tcp_config.tx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?,
Expand Down
19 changes: 9 additions & 10 deletions io/zenoh-links/zenoh-link-tls/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ use webpki::anchor_from_trusted_cert;
use zenoh_config::Config as ZenohConfig;
use zenoh_link_commons::{
tcp::TcpSocketConfig, tls::WebPkiVerifierAnyServerName, ConfigurationInspector, BIND_INTERFACE,
TCP_RX_BUFFER_SIZE, TCP_TX_BUFFER_SIZE,
TCP_SO_RCV_BUF, TCP_SO_SND_BUF,
};
use zenoh_protocol::core::{
endpoint::{Address, Config},
Expand Down Expand Up @@ -153,17 +153,16 @@ impl ConfigurationInspector<ZenohConfig> for TlsConfigurator {
false => ps.push((TLS_CLOSE_LINK_ON_EXPIRATION, "false")),
}

let link_c = config.transport().link();
let rx_buffer_size;
if let Some(size) = link_c.tcp_rx_buffer {
if let Some(size) = c.so_rcvbuf() {
rx_buffer_size = size.to_string();
ps.push((TCP_RX_BUFFER_SIZE, &rx_buffer_size));
ps.push((TCP_SO_RCV_BUF, &rx_buffer_size));
}

let tx_buffer_size;
if let Some(size) = link_c.tcp_tx_buffer {
if let Some(size) = c.so_sndbuf() {
tx_buffer_size = size.to_string();
ps.push((TCP_TX_BUFFER_SIZE, &tx_buffer_size));
ps.push((TCP_SO_SND_BUF, &tx_buffer_size));
}

Ok(parameters::from_iter(ps.drain(..)))
Expand Down Expand Up @@ -259,14 +258,14 @@ impl<'a> TlsServerConfig<'a> {
);

let mut tcp_rx_buffer_size = None;
if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_RCV_BUF) {
tcp_rx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?,
);
};
let mut tcp_tx_buffer_size = None;
if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_SND_BUF) {
tcp_tx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?,
Expand Down Expand Up @@ -426,14 +425,14 @@ impl<'a> TlsClientConfig<'a> {
};

let mut tcp_rx_buffer_size = None;
if let Some(size) = config.get(TCP_RX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_RCV_BUF) {
tcp_rx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP read buffer size argument: {}", size))?,
);
};
let mut tcp_tx_buffer_size = None;
if let Some(size) = config.get(TCP_TX_BUFFER_SIZE) {
if let Some(size) = config.get(TCP_SO_SND_BUF) {
tcp_tx_buffer_size = Some(
size.parse()
.map_err(|_| zerror!("Unknown TCP write buffer size argument: {}", size))?,
Expand Down
18 changes: 9 additions & 9 deletions zenoh/tests/tcp_buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ fn buffer_size_config() {
let mut config = Config::default();
config
.insert_json5(
"transport/link",
"transport/link/tcp",
r#"
{
tcp_tx_buffer: 65000,
tcp_rx_buffer: 65000,
so_sndbuf: 65000,
so_rcvbuf: 65000,
}
"#,
)
Expand All @@ -42,7 +42,7 @@ fn buffer_size_endpoint() {
config
.insert_json5(
"listen/endpoints",
r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#,
r#"["tcp/[::]:0#so_sndbuf=65000;so_rcvbuf=65000"]"#,
)
.unwrap();

Expand All @@ -54,11 +54,11 @@ fn buffer_size_endpoint_overwrite() {
let mut config = Config::default();
config
.insert_json5(
"transport/link",
"transport/link/tcp",
r#"
{
tcp_tx_buffer: 0,
tcp_rx_buffer: 0,
so_sndbuf: 0,
so_rcvbuf: 0,
}
"#,
)
Expand All @@ -67,7 +67,7 @@ fn buffer_size_endpoint_overwrite() {
config
.insert_json5(
"listen/endpoints",
r#"["tcp/[::]:0#tcp_tx_buffer=65000;tcp_rx_buffer=65000"]"#,
r#"["tcp/[::]:0#so_sndbuf=65000;so_rcvbuf=65000"]"#,
)
.unwrap();

Expand All @@ -92,7 +92,7 @@ fn listen_zero_buffers() {
config
.insert_json5(
"listen/endpoints",
r#"["tcp/[::]:0#tcp_tx_buffer=0;tcp_rx_buffer=0"]"#,
r#"["tcp/[::]:0#so_sndbuf=0;so_rcvbuf=0"]"#,
)
.unwrap();
zenoh::open(config).wait().unwrap();
Expand Down

0 comments on commit b5ca078

Please sign in to comment.