Skip to main content

rtci_sctp/association/
stats.rs

1/// Association statistics
2#[derive(Default, Debug, Copy, Clone)]
3pub struct AssociationStats {
4    n_datas: u64,
5    n_sacks: u64,
6    n_t3timeouts: u64,
7    n_ack_timeouts: u64,
8    n_fast_retrans: u64,
9    n_retransmissions: u64,
10    n_partially_reliable_retransmissions: u64,
11    n_abandoned_messages: u64,
12    n_forward_tsns: u64,
13    n_fast_retrans_abandoned: u64,
14    t3_wait_ms: u64,
15    n_sack_losses: u64,
16    n_reneged: u64,
17}
18
19impl AssociationStats {
20    /// Counts one DATA chunk received.
21    pub fn inc_datas(&mut self) {
22        self.n_datas += 1;
23    }
24
25    /// The number of DATA chunks received.
26    pub fn get_num_datas(&mut self) -> u64 {
27        self.n_datas
28    }
29
30    /// Counts one SACK chunk received.
31    pub fn inc_sacks(&mut self) {
32        self.n_sacks += 1;
33    }
34
35    /// The number of SACK chunks received.
36    pub fn get_num_sacks(&mut self) -> u64 {
37        self.n_sacks
38    }
39
40    /// Counts one T3-rtx retransmission timeout.
41    pub fn inc_t3timeouts(&mut self) {
42        self.n_t3timeouts += 1;
43    }
44
45    /// The number of T3-rtx retransmission timeouts, a signal of loss or a stalled path.
46    pub fn get_num_t3timeouts(&mut self) -> u64 {
47        self.n_t3timeouts
48    }
49
50    /// Counts one delayed-acknowledgement timeout.
51    pub fn inc_ack_timeouts(&mut self) {
52        self.n_ack_timeouts += 1;
53    }
54
55    /// The number of delayed-acknowledgement timeouts.
56    pub fn get_num_ack_timeouts(&mut self) -> u64 {
57        self.n_ack_timeouts
58    }
59
60    /// Counts one fast retransmission.
61    pub fn inc_fast_retrans(&mut self) {
62        self.n_fast_retrans += 1;
63    }
64
65    /// The number of fast retransmissions, triggered by SACK gap reports rather than a timeout.
66    pub fn get_num_fast_retrans(&mut self) -> u64 {
67        self.n_fast_retrans
68    }
69
70    /// Counts one DATA chunk sent again (by T3-rtx, Fast Retransmit or with a repeated COOKIE
71    /// ACK).
72    pub fn inc_retransmissions(&mut self) {
73        self.n_retransmissions += 1;
74    }
75
76    /// The number of DATA chunks sent again, whatever made them go again.
77    pub fn get_num_retransmissions(&mut self) -> u64 {
78        self.n_retransmissions
79    }
80
81    /// Counts one DATA chunk of a partially reliable message (RFC 3758: a lifetime or a
82    /// retransmission limit, RFC 7496) sent again.
83    pub fn inc_partially_reliable_retransmissions(&mut self) {
84        self.n_partially_reliable_retransmissions += 1;
85    }
86
87    /// Of [`Self::get_num_retransmissions`], the DATA chunks of partially reliable messages
88    /// (RFC 3758, RFC 7496: sent with a lifetime or a retransmission limit) sent again; the rest
89    /// are reliable messages (on a WebRTC association, the DCEP messages, RFC 8832 section 5,
90    /// beside the reliable channels). With a limit of zero retransmissions (RFC 8831 section
91    /// 6.6, `maxRetransmits` 0) and the peer's support for partial reliability, a message's
92    /// chunks are never counted here. Without that support (RFC 3758 3.3) partially reliable
93    /// messages are retransmitted as reliable ones, and counted here.
94    pub fn get_num_partially_reliable_retransmissions(&mut self) -> u64 {
95        self.n_partially_reliable_retransmissions
96    }
97
98    /// Counts one message abandoned (RFC 3758 3.5 A2): sent in part or whole and never to be
99    /// sent again, or dropped before it was sent.
100    pub fn inc_abandoned_messages(&mut self) {
101        self.n_abandoned_messages += 1;
102    }
103
104    /// The number of messages abandoned under their partial reliability policy.
105    pub fn get_num_abandoned_messages(&mut self) -> u64 {
106        self.n_abandoned_messages
107    }
108
109    /// Counts one FORWARD TSN (or I-FORWARD TSN) chunk sent.
110    pub fn inc_forward_tsns(&mut self) {
111        self.n_forward_tsns += 1;
112    }
113
114    /// The number of FORWARD TSN (or I-FORWARD TSN) chunks sent (RFC 3758 3.5 C3, A5).
115    pub fn get_num_forward_tsns(&mut self) -> u64 {
116        self.n_forward_tsns
117    }
118
119    /// Counts one chunk that Fast Retransmit would have sent again and abandoned instead: its
120    /// message's retransmission budget was spent (RFC 3758 3.5 A2, RFC 7496).
121    pub fn inc_fast_retrans_abandoned(&mut self) {
122        self.n_fast_retrans_abandoned += 1;
123    }
124
125    /// The number of losses Fast Retransmit found in partially reliable messages whose budget
126    /// was spent, so that they were abandoned (and skipped by FORWARD TSN) without waiting for
127    /// T3-rtx.
128    pub fn get_num_fast_retrans_abandoned(&mut self) -> u64 {
129        self.n_fast_retrans_abandoned
130    }
131
132    /// Adds the RTO, in milliseconds, that a T3-rtx expiry waited out.
133    pub fn add_t3_wait(&mut self, rto_ms: u64) {
134        self.t3_wait_ms = self.t3_wait_ms.saturating_add(rto_ms);
135    }
136
137    /// The sum of the RTOs the T3-rtx expiries waited out (each the RTO in force when the
138    /// timer expired, before the back-off of RFC 9260 6.3.3 E2): how much of a transfer's time
139    /// the retransmission timer accounts for.
140    pub fn get_t3_wait(&mut self) -> std::time::Duration {
141        std::time::Duration::from_millis(self.t3_wait_ms)
142    }
143
144    /// Counts one SACK loss found from a Duplicate TSN report (RFC 9260 6.2).
145    pub fn inc_sack_losses(&mut self) {
146        self.n_sack_losses += 1;
147    }
148
149    /// The SACKs found lost (RFC 9260 6.2: the sender "MAY use the duplicate TSN information
150    /// to determine if SACK chunk loss is occurring"): DATA this side sent again on a
151    /// retransmission timeout that the peer then reported as a duplicate, which it had
152    /// received before, so the SACK that acknowledged it did not arrive in time.
153    pub fn get_num_sack_losses(&mut self) -> u64 {
154        self.n_sack_losses
155    }
156
157    /// Counts one DATA chunk this receiver dropped from those it held above its cumulative TSN.
158    pub fn inc_reneged(&mut self) {
159        self.n_reneged += 1;
160    }
161
162    /// The DATA chunks this receiver reneged on (RFC 9260 6.2.1): held above its cumulative TSN,
163    /// which a SACK reports in a Gap Ack Block, and dropped, so the peer has to send them again.
164    /// Only
165    /// `TransportConfig::with_zero_window_renege` does so (RFC 9260 6.2: a chunk filling a
166    /// gap through a closed window takes the place of the largest TSN held for reordering).
167    pub fn get_num_reneged(&mut self) -> u64 {
168        self.n_reneged
169    }
170
171    /// Zeroes every counter.
172    pub fn reset(&mut self) {
173        self.n_datas = 0;
174        self.n_sacks = 0;
175        self.n_t3timeouts = 0;
176        self.n_ack_timeouts = 0;
177        self.n_fast_retrans = 0;
178        self.n_retransmissions = 0;
179        self.n_partially_reliable_retransmissions = 0;
180        self.n_abandoned_messages = 0;
181        self.n_forward_tsns = 0;
182        self.n_fast_retrans_abandoned = 0;
183        self.t3_wait_ms = 0;
184        self.n_sack_losses = 0;
185        self.n_reneged = 0;
186    }
187}