Skip to content

Commit 45740b9

Browse files
committed
nits
1 parent cb4daa2 commit 45740b9

3 files changed

Lines changed: 60 additions & 58 deletions

File tree

neqo-transport/src/cc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub use cubic::Cubic;
2828
pub use hystart::{HyStart, HyStartCssBaseline};
2929
pub use new_reno::NewReno;
3030
#[cfg(test)]
31-
pub use search::Result;
31+
pub use search::Outcome;
3232
pub use search::Search;
3333

3434
#[derive(Clone, Copy, PartialEq, Eq, Debug)]

neqo-transport/src/cc/search.rs

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use crate::{cc::classic_cc::SlowStart, packet, rtt::RttEstimate, stats::Congesti
1818

1919
/// The outcome of a single SEARCH evaluation.
2020
#[derive(Debug, PartialEq, Eq)]
21-
pub enum Result {
21+
pub enum Outcome {
2222
/// Evaluation ran and slow start should be exited with the provided cwnd.
2323
Exit(usize),
2424
/// Evaluation ran and slow start should be continued.
@@ -228,6 +228,53 @@ impl Search {
228228
sent / Self::SCALE as u64
229229
}
230230

231+
/// Evaluates whether SEARCH should exit slow start.
232+
///
233+
/// Returns [`Outcome::Exit`] with the current cwnd if the normalized delivery-rate
234+
/// difference exceeds [`Self::THRESH`], or a non-exit variant explaining why not.
235+
fn evaluate(&self, rtt: Duration, curr_idx: usize, curr_cwnd: usize) -> Outcome {
236+
// Compute how many bins fit in the last RTT. Integer division implicitly floors that value,
237+
// so `prev_idx` might be too recent by a fraction of a bin. Said fraction is scaled to
238+
// `0..[Self::SCALE]` for interpolation in `compute_sent`.
239+
let (prev_idx, fraction) = self.calc_prev_idx(rtt, curr_idx);
240+
qdebug!("SEARCH: evaluate: prev_idx {prev_idx} curr_idx {curr_idx} fraction {fraction}");
241+
242+
if prev_idx <= Self::W {
243+
qdebug!("SEARCH: evaluate: not enough data for SEARCH evaluation (warming up)");
244+
return Outcome::WarmingUp;
245+
}
246+
if curr_idx - prev_idx >= Self::EXTRA_BINS {
247+
qdebug!("SEARCH: evaluate: not enough data for SEARCH evaluation (RTT inflated)");
248+
return Outcome::RttInflated;
249+
}
250+
251+
let curr_delv = self.compute_delv(curr_idx - Self::W, curr_idx);
252+
let prev_sent = self.compute_sent(prev_idx - Self::W, prev_idx, fraction);
253+
qdebug!("SEARCH: evaluate: curr_delv {curr_delv} prev_sent {prev_sent}");
254+
255+
if prev_sent == 0 {
256+
qdebug!("SEARCH: evaluate: prev_sent is zero, can't evaluate");
257+
return Outcome::ZeroSent;
258+
}
259+
260+
let diff = prev_sent.saturating_sub(curr_delv);
261+
let norm_diff =
262+
usize::try_from(diff * Self::SCALE as u64 / prev_sent).unwrap_or(usize::MAX);
263+
264+
if norm_diff < Self::THRESH {
265+
qdebug!(
266+
"SEARCH: evaluate: norm_diff {norm_diff} < THRESH {} --> continue",
267+
Self::THRESH
268+
);
269+
return Outcome::Continue;
270+
}
271+
qdebug!(
272+
"SEARCH: evaluate: norm_diff {norm_diff} >= THRESH {} --> exit",
273+
Self::THRESH
274+
);
275+
Outcome::Exit(curr_cwnd)
276+
}
277+
231278
#[cfg(test)]
232279
pub const fn curr_idx(&self) -> Option<usize> {
233280
self.curr_idx
@@ -273,56 +320,9 @@ impl Search {
273320

274321
/// Re-exports the internal `evaluate` function for use in tests.
275322
#[cfg(test)]
276-
pub fn evaluate_test(&self, rtt: Duration, curr_idx: usize, curr_cwnd: usize) -> Result {
323+
pub fn evaluate_test(&self, rtt: Duration, curr_idx: usize, curr_cwnd: usize) -> Outcome {
277324
self.evaluate(rtt, curr_idx, curr_cwnd)
278325
}
279-
280-
/// Evaluates whether SEARCH should exit slow start.
281-
///
282-
/// Returns [`Result::Exit`] with the current cwnd if the normalized delivery-rate
283-
/// difference exceeds [`Self::THRESH`], or a non-exit variant explaining why not.
284-
fn evaluate(&self, rtt: Duration, curr_idx: usize, curr_cwnd: usize) -> Result {
285-
// Compute how many bins fit in the last RTT. Integer division implicitly floors that value,
286-
// so `prev_idx` might be too recent by a fraction of a bin. Said fraction is scaled to
287-
// `0..[Self::SCALE]` for interpolation in `compute_sent`.
288-
let (prev_idx, fraction) = self.calc_prev_idx(rtt, curr_idx);
289-
qdebug!("SEARCH: evaluate: prev_idx {prev_idx} curr_idx {curr_idx} fraction {fraction}");
290-
291-
if prev_idx <= Self::W {
292-
qdebug!("SEARCH: evaluate: not enough data for SEARCH evaluation (warming up)");
293-
return Result::WarmingUp;
294-
}
295-
if curr_idx - prev_idx >= Self::EXTRA_BINS {
296-
qdebug!("SEARCH: evaluate: not enough data for SEARCH evaluation (RTT inflated)");
297-
return Result::RttInflated;
298-
}
299-
300-
let curr_delv = self.compute_delv(curr_idx - Self::W, curr_idx);
301-
let prev_sent = self.compute_sent(prev_idx - Self::W, prev_idx, fraction);
302-
qdebug!("SEARCH: evaluate: curr_delv {curr_delv} prev_sent {prev_sent}");
303-
304-
if prev_sent == 0 {
305-
qdebug!("SEARCH: evaluate: prev_sent is zero, can't evaluate");
306-
return Result::ZeroSent;
307-
}
308-
309-
let diff = prev_sent.saturating_sub(curr_delv);
310-
let norm_diff =
311-
usize::try_from(diff * Self::SCALE as u64 / prev_sent).unwrap_or(usize::MAX);
312-
313-
if norm_diff < Self::THRESH {
314-
qdebug!(
315-
"SEARCH: evaluate: norm_diff {norm_diff} < THRESH {} --> continue",
316-
Self::THRESH
317-
);
318-
return Result::Continue;
319-
}
320-
qdebug!(
321-
"SEARCH: evaluate: norm_diff {norm_diff} >= THRESH {} --> exit",
322-
Self::THRESH
323-
);
324-
Result::Exit(curr_cwnd)
325-
}
326326
}
327327

328328
impl SlowStart for Search {
@@ -365,7 +365,7 @@ impl SlowStart for Search {
365365
//
366366
// <https://datatracker.ietf.org/doc/html/draft-chung-ccwg-search-09#section-3.2-17>
367367
match self.evaluate(rtt, curr_idx, curr_cwnd) {
368-
Result::Exit(cwnd) => Some(cwnd),
368+
Outcome::Exit(cwnd) => Some(cwnd),
369369
_ => None,
370370
}
371371
}

neqo-transport/src/cc/tests/search.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use test_fixture::now;
1212

1313
use crate::{
1414
MIN_INITIAL_PACKET_SIZE,
15-
cc::{CongestionControlStats, Result, Search, classic_cc::SlowStart as _, tests::INITIAL_CWND},
15+
cc::{
16+
CongestionControlStats, Outcome, Search, classic_cc::SlowStart as _, tests::INITIAL_CWND,
17+
},
1618
rtt::RttEstimate,
1719
};
1820

@@ -345,7 +347,7 @@ fn sent_and_acked_byte_computation() {
345347
// `sent_bytes` and `delv_bytes` should be `10 * 1000 = 10_000`.
346348
assert!(
347349
sent_bytes == delv_bytes && delv_bytes == 10_000,
348-
"Should have `sent_bytes == delv_bytes == 10_000 and got `sent_bytes = {sent_bytes}` and `delv_bytes = {delv_bytes}`"
350+
"Should have `sent_bytes == delv_bytes == 10_000` and got `sent_bytes = {sent_bytes}` and `delv_bytes = {delv_bytes}`"
349351
);
350352
}
351353

@@ -450,7 +452,7 @@ fn inflated_rtt_is_guarded() {
450452
let high_rtt = Duration::from_millis(600);
451453
assert_eq!(
452454
search.evaluate_test(high_rtt, curr_idx, INITIAL_CWND),
453-
Result::RttInflated,
455+
Outcome::RttInflated,
454456
);
455457
}
456458

@@ -479,7 +481,7 @@ fn no_sent_bytes() {
479481
let curr_idx = search.curr_idx().unwrap();
480482
assert_eq!(
481483
search.evaluate_test(INITIAL_RTT, curr_idx, INITIAL_CWND),
482-
Result::ZeroSent,
484+
Outcome::ZeroSent,
483485
);
484486
}
485487

@@ -509,7 +511,7 @@ fn warming_up() {
509511
let curr_idx = search.curr_idx().unwrap();
510512
assert_eq!(
511513
search.evaluate_test(INITIAL_RTT, curr_idx, INITIAL_CWND),
512-
Result::WarmingUp,
514+
Outcome::WarmingUp,
513515
);
514516

515517
// One more bin crosses the boundary: prev_idx = 13 - 2 = 11 > W(10).
@@ -528,7 +530,7 @@ fn warming_up() {
528530
// Now the SEARCH checks should run.
529531
assert_eq!(
530532
search.evaluate_test(INITIAL_RTT, curr_idx, INITIAL_CWND),
531-
Result::Continue,
533+
Outcome::Continue,
532534
);
533535
}
534536

@@ -572,7 +574,7 @@ fn continue_when_delivery_rate_steady() {
572574
let curr_idx = search.curr_idx().unwrap();
573575
assert_eq!(
574576
search.evaluate_test(INITIAL_RTT, curr_idx, INITIAL_CWND),
575-
Result::Continue,
577+
Outcome::Continue,
576578
);
577579
}
578580
}

0 commit comments

Comments
 (0)