Skip to content
Open
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
34 changes: 33 additions & 1 deletion neqo-transport/src/connection/tests/ecn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use test_fixture::{
};

use crate::{
ConnectionEvent, ConnectionId, ConnectionParameters, Output, StreamType,
Connection, ConnectionEvent, ConnectionId, ConnectionParameters, Output, StreamType,
connection::tests::{
DEFAULT_RTT, assert_path_challenge_min_len, connect_force_idle,
connect_force_idle_with_modifier, connect_rtt_idle, default_client, default_server,
Expand Down Expand Up @@ -291,6 +291,38 @@ fn disables_on_remark() {
assert_ecn_disabled(client_pkt.tos());
}

/// A server validates the ECN counts on a path its peer migrated to against those from the old
/// path.
#[test]
fn server_detects_bleaching_after_peer_migration() {
let now = now();
let mut client = default_client();
let mut server = default_server();
connect_force_idle(&mut client, &mut server);
let capable = |c: &Connection| c.stats().ecn_path_validation[ecn::ValidationOutcome::Capable];

for _ in 0..ecn::TEST_COUNT {
let ack = send_and_receive(&mut server, &mut client, now);
server.process_input(ack.unwrap(), now);
}
assert_eq!(capable(&server), 1);

client
.migrate(Some(DEFAULT_ADDR_V4), Some(DEFAULT_ADDR_V4), true, now)
.unwrap();
server.process_input(send_something(&mut client, now), now);

for _ in 0..=ecn::TEST_COUNT {
if let Some(ack) = send_with_modifier_and_receive(&mut server, &mut client, now, bleach) {
server.process_input(ack, now);
}
assert_eq!(capable(&server), 1);
}
let bleaching = server.stats().ecn_path_validation
[ecn::ValidationOutcome::NotCapable(ecn::ValidationError::Bleaching)];
assert_eq!(bleaching, 1);
}

/// This function performs a handshake over a path that modifies packets via `orig_path_modifier`.
/// It then sends `burst` packets on that path, and then migrates to a new path that
/// modifies packets via `new_path_modifier`. It sends `burst` packets on the new path.
Expand Down
19 changes: 13 additions & 6 deletions neqo-transport/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,7 @@ impl Paths {
stats: &mut Stats,
) -> bool {
debug_assert!(!self.is_temporary(path));
let baseline = self.primary().map_or_else(
|| ecn::Info::default().baseline(),
|p| p.borrow().ecn_info.baseline(),
);
path.borrow_mut().set_ecn_baseline(baseline);
path.borrow_mut().start_ecn(stats);
self.start_ecn_on_new_path(path, stats);
if force || path.borrow().is_valid() {
path.borrow_mut().set_valid(now);
drop(self.select_primary(path, now));
Expand Down Expand Up @@ -332,6 +327,7 @@ impl Paths {
return;
}

self.start_ecn_on_new_path(path, stats);
if let Some(old_path) = self.select_primary(path, now) {
// Need to probe the old path if the peer migrates.
old_path.borrow_mut().probe(stats);
Expand Down Expand Up @@ -498,6 +494,17 @@ impl Paths {
}
}

/// Start ECN validation on `path`, using the ECN counts of the primary path as baseline.
fn start_ecn_on_new_path(&self, path: &PathRef, stats: &mut Stats) {
let baseline = self
.primary()
.map(|p| p.borrow().ecn_info.baseline())
.unwrap_or_default();
let mut path = path.borrow_mut();
path.set_ecn_baseline(baseline);
path.start_ecn(stats);
}

/// Get an estimate of the RTT on the primary path.
#[cfg(test)]
pub fn rtt(&self) -> Duration {
Expand Down
Loading