| 1 |
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 2 |
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 3 |
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 4 |
// option. This file may not be copied, modified, or distributed |
| 5 |
// except according to those terms. |
| 6 |
|
| 7 |
use std::{ops::Range, time::Duration}; |
| 8 |
|
| 9 |
use neqo_transport::{CloseReason, ConnectionParameters, Error, State}; |
| 10 |
use test_fixture::{ |
| 11 |
boxed, |
| 12 |
sim::{ |
| 13 |
connection::{ConnectionNode, ReachState, ReceiveData, SendData}, |
| 14 |
network::{Drop, RandomDelay, TailDrop}, |
| 15 |
Simulator, |
| 16 |
}, |
| 17 |
simulate, |
| 18 |
}; |
| 19 |
|
| 20 |
/// The amount of transfer. Much more than this takes a surprising amount of time. |
| 21 |
const TRANSFER_AMOUNT: usize = 1 << 20; // 1M |
| 22 |
const ZERO: Duration = Duration::from_millis(0); |
| 23 |
const DELAY: Duration = Duration::from_millis(50); |
| 24 |
const DELAY_RANGE: Range<Duration> = DELAY..Duration::from_millis(55); |
| 25 |
const JITTER: Duration = Duration::from_millis(10); |
| 26 |
|
| 27 |
const fn weeks(m: u32) -> Duration { |
| 28 |
Duration::from_secs((m as u64) * 60 * 60 * 24 * 7) |
| 29 |
} |
| 30 |
|
| 31 |
simulate!( |
| 32 |
connect_direct, |
| 33 |
[ |
| 34 |
ConnectionNode::new_client( |
| 35 |
ConnectionParameters::default().mlkem(false), |
| 36 |
[], |
| 37 |
boxed![ReachState::new(State::Confirmed)] |
| 38 |
), |
| 39 |
ConnectionNode::new_server( |
| 40 |
ConnectionParameters::default().mlkem(false), |
| 41 |
[], |
| 42 |
boxed![ReachState::new(State::Confirmed)] |
| 43 |
), |
| 44 |
] |
| 45 |
); |
| 46 |
|
| 47 |
simulate!( |
| 48 |
idle_timeout, |
| 49 |
[ |
| 50 |
ConnectionNode::default_client(boxed![ReachState::new(State::Closed( |
| 51 |
CloseReason::Transport(Error::IdleTimeout) |
| 52 |
))]), |
| 53 |
ConnectionNode::default_server(boxed![ReachState::new(State::Closed( |
| 54 |
CloseReason::Transport(Error::IdleTimeout) |
| 55 |
))]), |
| 56 |
] |
| 57 |
); |
| 58 |
|
| 59 |
simulate!( |
| 60 |
idle_timeout_crazy_rtt, |
| 61 |
[ |
| 62 |
ConnectionNode::new_client( |
| 63 |
ConnectionParameters::default() |
| 64 |
.idle_timeout(weeks(1000)) |
| 65 |
.mlkem(false), |
| 66 |
boxed![ReachState::new(State::Confirmed),], |
| 67 |
boxed![ReachState::new(State::Closed(CloseReason::Transport( |
| 68 |
Error::IdleTimeout |
| 69 |
)))] |
| 70 |
), |
| 71 |
RandomDelay::new(weeks(6)..weeks(6)), |
| 72 |
Drop::percentage(10), |
| 73 |
ConnectionNode::new_server( |
| 74 |
ConnectionParameters::default() |
| 75 |
.idle_timeout(weeks(1000)) |
| 76 |
.mlkem(false), |
| 77 |
boxed![ReachState::new(State::Confirmed),], |
| 78 |
boxed![ReachState::new(State::Closed(CloseReason::Transport( |
| 79 |
Error::IdleTimeout |
| 80 |
)))] |
| 81 |
), |
| 82 |
RandomDelay::new(weeks(8)..weeks(8)), |
| 83 |
Drop::percentage(10), |
| 84 |
], |
| 85 |
); |
| 86 |
|
| 87 |
simulate!( |
| 88 |
transfer, |
| 89 |
[ |
| 90 |
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), |
| 91 |
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), |
| 92 |
] |
| 93 |
); |
| 94 |
|
| 95 |
simulate!( |
| 96 |
connect_fixed_rtt, |
| 97 |
[ |
| 98 |
ConnectionNode::new_client( |
| 99 |
ConnectionParameters::default().mlkem(false), |
| 100 |
[], |
| 101 |
boxed![ReachState::new(State::Confirmed)] |
| 102 |
), |
| 103 |
RandomDelay::new(DELAY..DELAY), |
| 104 |
ConnectionNode::new_server( |
| 105 |
ConnectionParameters::default().mlkem(false), |
| 106 |
[], |
| 107 |
boxed![ReachState::new(State::Confirmed)] |
| 108 |
), |
| 109 |
RandomDelay::new(DELAY..DELAY), |
| 110 |
], |
| 111 |
); |
| 112 |
|
| 113 |
simulate!( |
| 114 |
connect_taildrop_jitter, |
| 115 |
[ |
| 116 |
ConnectionNode::new_client( |
| 117 |
ConnectionParameters::default().mlkem(false), |
| 118 |
[], |
| 119 |
boxed![ReachState::new(State::Confirmed)] |
| 120 |
), |
| 121 |
TailDrop::dsl_downlink(), |
| 122 |
RandomDelay::new(ZERO..JITTER), |
| 123 |
ConnectionNode::new_server( |
| 124 |
ConnectionParameters::default().mlkem(false), |
| 125 |
[], |
| 126 |
boxed![ReachState::new(State::Confirmed)] |
| 127 |
), |
| 128 |
TailDrop::dsl_uplink(), |
| 129 |
RandomDelay::new(ZERO..JITTER), |
| 130 |
], |
| 131 |
); |
| 132 |
|
| 133 |
simulate!( |
| 134 |
connect_taildrop, |
| 135 |
[ |
| 136 |
ConnectionNode::new_client( |
| 137 |
ConnectionParameters::default().mlkem(false), |
| 138 |
[], |
| 139 |
boxed![ReachState::new(State::Confirmed)] |
| 140 |
), |
| 141 |
TailDrop::dsl_downlink(), |
| 142 |
ConnectionNode::new_server( |
| 143 |
ConnectionParameters::default().mlkem(false), |
| 144 |
[], |
| 145 |
boxed![ReachState::new(State::Confirmed)] |
| 146 |
), |
| 147 |
TailDrop::dsl_uplink(), |
| 148 |
], |
| 149 |
); |
| 150 |
|
| 151 |
simulate!( |
| 152 |
transfer_delay_drop, |
| 153 |
[ |
| 154 |
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), |
| 155 |
RandomDelay::new(DELAY_RANGE), |
| 156 |
Drop::percentage(1), |
| 157 |
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), |
| 158 |
RandomDelay::new(DELAY_RANGE), |
| 159 |
Drop::percentage(1), |
| 160 |
], |
| 161 |
); |
| 162 |
|
| 163 |
simulate!( |
| 164 |
transfer_taildrop, |
| 165 |
[ |
| 166 |
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), |
| 167 |
TailDrop::dsl_downlink(), |
| 168 |
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), |
| 169 |
TailDrop::dsl_uplink(), |
| 170 |
], |
| 171 |
); |
| 172 |
|
| 173 |
simulate!( |
| 174 |
transfer_taildrop_jitter, |
| 175 |
[ |
| 176 |
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), |
| 177 |
TailDrop::dsl_downlink(), |
| 178 |
RandomDelay::new(ZERO..JITTER), |
| 179 |
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), |
| 180 |
TailDrop::dsl_uplink(), |
| 181 |
RandomDelay::new(ZERO..JITTER), |
| 182 |
], |
| 183 |
); |
| 184 |
|
| 185 |
/// This test is a nasty piece of work. Delays are anything from 0 to 50ms and 1% of |
| 186 |
/// packets get dropped. |
| 187 |
#[test] |
| 188 |
fn transfer_fixed_seed() { |
| 189 |
let mut sim = Simulator::new( |
| 190 |
"transfer_fixed_seed", |
| 191 |
boxed![ |
| 192 |
ConnectionNode::default_client(boxed![SendData::new(TRANSFER_AMOUNT)]), |
| 193 |
RandomDelay::new(ZERO..DELAY), |
| 194 |
Drop::percentage(1), |
| 195 |
ConnectionNode::default_server(boxed![ReceiveData::new(TRANSFER_AMOUNT)]), |
| 196 |
RandomDelay::new(ZERO..DELAY), |
| 197 |
Drop::percentage(1), |
| 198 |
], |
| 199 |
); |
| 200 |
sim.seed_str("117f65d90ee5c1a7fb685f3af502c7730ba5d31866b758d98f5e3c2117cf9b86"); |
| 201 |
sim.run(); |
| 202 |
} |