-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.rs
More file actions
120 lines (101 loc) · 2.77 KB
/
lib.rs
File metadata and controls
120 lines (101 loc) · 2.77 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
pub const DEFAULT_SS_THRESH: u32 = 0x7fff_ffff;
/// Flow key identifying a TCP connection
#[repr(C)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FlowKey {
pub saddr: u32,
pub daddr: u32,
pub sport: u16,
pub dport: u16,
}
#[derive(Debug, Clone)]
pub struct Report {
pub flow_key: FlowKey,
// Flow-level statistics
pub packets_in_flight: u32,
pub bytes_in_flight: u32,
pub bytes_pending: u32,
pub rtt_sample_us: u32,
pub was_timeout: bool,
// ACK-level statistics
pub bytes_acked: u32,
pub packets_acked: u32,
pub bytes_misordered: u32,
pub packets_misordered: u32,
pub ecn_bytes: u32,
pub ecn_packets: u32,
pub lost_pkts_sample: u32,
// Rate statistics
pub rate_incoming: u32,
pub rate_outgoing: u32,
// Kernel context
pub snd_cwnd: u32,
pub snd_ssthresh: u32,
pub pacing_rate: u64,
pub ca_state: u8,
pub now: u64,
}
#[derive(Debug, Clone, Copy)]
pub struct FlowStatistics {
pub packets_in_flight: u32,
pub bytes_in_flight: u32,
pub bytes_pending: u32,
pub rtt_sample_us: u32,
pub was_timeout: bool,
}
#[derive(Debug, Clone, Copy)]
pub struct AckStatistics {
pub bytes_acked: u32,
pub packets_acked: u32,
pub bytes_misordered: u32,
pub packets_misordered: u32,
pub ecn_bytes: u32,
pub ecn_packets: u32,
pub lost_pkts_sample: u32,
pub now: u64,
}
#[derive(Debug, Clone, Copy, Default)]
pub struct CwndUpdate {
pub cwnd_bytes: Option<u32>,
pub pacing_rate: Option<u64>,
pub ssthresh: Option<u32>,
}
impl CwndUpdate {
pub fn new() -> Self {
Self::default()
}
pub fn with_cwnd(mut self, cwnd_bytes: u32) -> Self {
self.cwnd_bytes = Some(cwnd_bytes);
self
}
pub fn with_pacing_rate(mut self, pacing_rate: u64) -> Self {
self.pacing_rate = Some(pacing_rate);
self
}
pub fn with_ssthresh(mut self, ssthresh: u32) -> Self {
self.ssthresh = Some(ssthresh);
self
}
}
pub trait GenericAlgorithm: Send {
fn name(&self) -> &str;
fn create_flow(&self, init_cwnd: u32, mss: u32) -> Box<dyn GenericFlow>;
}
pub trait GenericFlow: Send {
/// Get current congestion window in bytes
fn curr_cwnd(&self) -> u32;
/// Set congestion window in bytes
fn set_cwnd(&mut self, cwnd: u32);
/// Optional: Get current pacing rate in bytes/sec
fn curr_pacing_rate(&self) -> Option<u64> {
None // Default: no pacing rate control
}
/// Increase cwnd on successful ACK without loss
fn increase(&mut self, report: &Report);
/// Reduce cwnd on congestion signal
fn reduction(&mut self, report: &Report);
/// Reset algorithm state (on timeout)
fn reset(&mut self) {
// Default is no-op
}
}