forked from mozilla/neqo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.rs
More file actions
126 lines (101 loc) · 3.08 KB
/
mod.rs
File metadata and controls
126 lines (101 loc) · 3.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Congestion control
use std::{
fmt::{Debug, Display},
time::{Duration, Instant},
};
use neqo_common::qlog::Qlog;
use crate::{Pmtud, recovery::sent, rtt::RttEstimate, stats::CongestionControlStats};
mod classic_cc;
mod classic_slow_start;
mod cubic;
mod hystart;
mod new_reno;
mod search;
pub use classic_cc::{CWND_INITIAL_PKTS, ClassicCongestionController, PERSISTENT_CONG_THRESH};
pub use classic_slow_start::ClassicSlowStart;
pub use cubic::Cubic;
pub use hystart::{HyStart, HyStartCssBaseline};
pub use new_reno::NewReno;
#[cfg(test)]
pub use search::Outcome;
pub use search::Search;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum CongestionTrigger {
Loss,
Ecn,
}
pub trait CongestionController: Display + Debug {
fn set_qlog(&mut self, qlog: Qlog);
#[must_use]
fn cwnd(&self) -> usize;
#[must_use]
fn bytes_in_flight(&self) -> usize;
#[must_use]
fn cwnd_avail(&self) -> usize;
#[must_use]
fn cwnd_min(&self) -> usize;
#[cfg(test)]
#[must_use]
fn cwnd_initial(&self) -> usize;
#[must_use]
fn pmtud(&self) -> &Pmtud;
#[must_use]
fn pmtud_mut(&mut self) -> &mut Pmtud;
fn on_packets_acked(
&mut self,
acked_pkts: &[sent::Packet],
rtt_est: &RttEstimate,
now: Instant,
cc_stats: &mut CongestionControlStats,
);
/// Returns true if the congestion window was reduced.
fn on_packets_lost(
&mut self,
first_rtt_sample_time: Option<Instant>,
prev_largest_acked_sent: Option<Instant>,
pto: Duration,
lost_packets: &[sent::Packet],
now: Instant,
cc_stats: &mut CongestionControlStats,
) -> bool;
/// Returns true if the congestion window was reduced.
fn on_ecn_ce_received(
&mut self,
largest_acked_pkt: &sent::Packet,
now: Instant,
cc_stats: &mut CongestionControlStats,
) -> bool;
#[must_use]
fn recovery_packet(&self) -> bool;
fn discard(&mut self, pkt: &sent::Packet, now: Instant);
fn on_packet_sent(&mut self, pkt: &sent::Packet, now: Instant);
fn discard_in_flight(&mut self, now: Instant);
}
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, strum::EnumString, strum::VariantNames)]
#[strum(ascii_case_insensitive)]
pub enum CongestionControl {
#[strum(serialize = "newreno", serialize = "reno")]
NewReno,
#[strum(serialize = "cubic")]
#[default]
Cubic,
}
#[derive(Debug, Copy, Clone, Default, PartialEq, Eq, strum::EnumString, strum::VariantNames)]
#[strum(ascii_case_insensitive)]
pub enum SlowStart {
#[strum(serialize = "classic")]
#[default]
Classic,
#[strum(serialize = "hystart")]
HyStart,
#[strum(serialize = "search")]
Search,
}
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests;