Skip to content

Commit

Permalink
Update path MTU configuration
Browse files Browse the repository at this point in the history
- fix the selected MTU for the sending path
- change default path MTU for interop tests
  • Loading branch information
iyangsj committed Jan 11, 2024
1 parent 615af23 commit 6fabded
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 19 deletions.
4 changes: 2 additions & 2 deletions include/tquic.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ void quic_config_set_recv_udp_payload_size(struct quic_config_t *config, uint16_

/**
* Set the maximum outgoing UDP payload size.
* This is depended on both the configured max payload size and the max_udp_payload_size
* transport parameter advertised by the remote peer.
* The default and minimum value is `1200`.
* The configuration should be changed with caution. The connection may
* not work properly if an inappropriate value is set.
*/
void quic_config_set_send_udp_payload_size(struct quic_config_t *config, uintptr_t v);

Expand Down
6 changes: 6 additions & 0 deletions interop/run_endpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ if [ "$ROLE" == "client" ]; then
zerortt)
CLIENT_ARGS="$CLIENT_ARGS --session-file=session.bin --enable-early-data"
;;
transfer)
CLIENT_ARGS="$CLIENT_ARGS --send-udp-payload-size 1400"
;;
http3)
CLIENT_ALPN="--alpn h3"
;;
Expand Down Expand Up @@ -108,6 +111,9 @@ elif [ "$ROLE" == "server" ]; then
multiconnect)
SERVER_ARGS="$SERVER_ARGS --initial-rtt 100"
;;
transfer)
SERVER_ARGS="$SERVER_ARGS --send-udp-payload-size 1400"
;;
*)
;;
esac
Expand Down
19 changes: 10 additions & 9 deletions src/connection/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,7 @@ impl Connection {
let max_datagram_size = peer_params.max_udp_payload_size as usize;
active_path
.recovery
.update_max_datagram_size(max_datagram_size);
.update_max_datagram_size(max_datagram_size, true);

self.cids.set_scid_limit(peer_params.active_conn_id_limit);

Expand Down Expand Up @@ -1303,16 +1303,18 @@ impl Connection {
}
}

/// Get the maximum possible size of outgoing QUIC packet.
/// This is depended on both the configured max datagram size and the max_udp_payload_size
/// transport parameter advertised by the remote peer.
pub(crate) fn max_datagram_size(&self) -> usize {
if !self.is_established() {
/// Get the maximum datagram size of the given path.
pub(crate) fn max_datagram_size(&self, pid: usize) -> usize {
// The peer's `max_udp_payload_size` transport parameter limits the
// size of UDP payloads that it is willing to receive. Therefore,
// prior to receiving that parameter, we only use the default value.
if !self.flags.contains(AppliedPeerTransportParams) {
return crate::MIN_CLIENT_INITIAL_LEN;
}

// Use the configured or validated max_datagram_size
self.paths
.get_active()
.get(pid)
.ok()
.map_or(crate::MIN_CLIENT_INITIAL_LEN, |path| {
path.recovery.max_datagram_size
Expand Down Expand Up @@ -1356,8 +1358,7 @@ impl Connection {
let pid = self.select_send_path()?;

// TODO: limit bytes sent before address validation
// TODO: limit bytes sent by path mtu.
let mut left = cmp::min(out.len(), self.max_datagram_size());
let mut left = cmp::min(out.len(), self.max_datagram_size(pid));
let out = &mut out[..left];
let mut done = 0;

Expand Down
14 changes: 12 additions & 2 deletions src/connection/recovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,18 @@ impl Recovery {
self.bytes_in_flight = self.bytes_in_flight.saturating_sub(unacked_bytes);
}

pub(super) fn update_max_datagram_size(&mut self, new_max_datagram_size: usize) {
let max_datagram_size = cmp::min(self.max_datagram_size, new_max_datagram_size);
/// Update maximum datagram size
///
/// If `is_upper` is true, `max_datagram_size` is the upper limit of maximum datagram size.
/// If `is_upper` is false, `max_datagram_size` is the new maximum datagram size.
pub(super) fn update_max_datagram_size(
&mut self,
mut max_datagram_size: usize,
is_upper: bool,
) {
if is_upper {
max_datagram_size = cmp::min(self.max_datagram_size, max_datagram_size);
}

// TODO: notify CC and pacer

Expand Down
7 changes: 4 additions & 3 deletions src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ pub extern "C" fn quic_config_set_recv_udp_payload_size(config: &mut Config, v:
config.set_recv_udp_payload_size(v);
}

/// Set the maximum outgoing UDP payload size.
/// This is depended on both the configured max payload size and the max_udp_payload_size
/// transport parameter advertised by the remote peer.
/// Set the initial maximum outgoing UDP payload size.
/// The default and minimum value is `1200`.
///
/// The configuration should be changed with caution. The connection may
/// not work properly if an inappropriate value is set.
#[no_mangle]
pub extern "C" fn quic_config_set_send_udp_payload_size(config: &mut Config, v: usize) {
config.set_send_udp_payload_size(v);
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,11 @@ impl Config {
self.local_transport_params.max_udp_payload_size = v as u64;
}

/// Set the maximum outgoing UDP payload size.
/// This is depended on both the configured max payload size and the max_udp_payload_size
/// transport parameter advertised by the remote peer.
/// Set the initial maximum outgoing UDP payload size.
/// The default and minimum value is `1200`.
///
/// The configuration should be changed with caution. The connection may
/// not work properly if an inappropriate value is set.
pub fn set_send_udp_payload_size(&mut self, v: usize) {
self.recovery.max_datagram_size = cmp::max(v, DEFAULT_SEND_UDP_PAYLOAD_SIZE);
}
Expand Down

0 comments on commit 6fabded

Please sign in to comment.