Skip to content

Commit 0465c71

Browse files
committed
removed duplicate event on congestion controller, removed constants from BBR3 struct, fixed data type for cycle_count
1 parent ae39099 commit 0465c71

File tree

5 files changed

+25
-51
lines changed

5 files changed

+25
-51
lines changed

quinn-proto/src/congestion.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,12 @@ pub trait Controller: Send + Sync {
3333
now: Instant,
3434
sent: Instant,
3535
bytes: u64,
36+
pn: u64,
3637
app_limited: bool,
3738
rtt: &RttEstimator,
3839
) {
3940
}
4041

41-
/// One packet was just acked
42-
#[allow(unused_variables)]
43-
fn on_packet_acked(
44-
&mut self,
45-
now: Instant,
46-
sent: Instant,
47-
bytes: u16,
48-
packet_number: u64,
49-
rtt: &RttEstimator,
50-
) {
51-
}
52-
5342
/// Packets are acked in batches, all with the same `now` argument. This indicates one of those batches has completed.
5443
#[allow(unused_variables)]
5544
fn on_end_acks(

quinn-proto/src/congestion/bbr3/mod.rs

Lines changed: 21 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ pub struct Bbr3 {
271271
is_cwnd_limited: bool,
272272
/// equivalent to BBR.cycle_count: The virtual time used by the BBR.max_bw filter window. Note that BBR.cycle_count only needs to be tracked with a single bit,
273273
/// since the BBR.max_bw_filter only needs to track samples from two time slots: the previous ProbeBW cycle and the current ProbeBW cycle.
274-
cycle_count: u64,
274+
cycle_count: bool,
275275
/// equivalent to C.cwnd: The transport sender's congestion window. When transmitting data, the sending connection ensures that C.inflight does not exceed C.cwnd.
276276
cwnd: u64,
277277
/// equivalent to C.pacing_rate: The current pacing rate for a BBR flow, which controls inter-packet spacing.
@@ -319,14 +319,6 @@ pub struct Bbr3 {
319319
next_round_delivered: u64,
320320
/// equivalent to BBR.idle_restart: A boolean that is true if and only if a connection is restarting after being idle.
321321
idle_restart: bool,
322-
/// equivalent to BBR.LossThresh: A constant specifying the maximum tolerated per-round-trip packet loss rate when probing for bandwidth (the default is 2%).
323-
loss_thresh: f64,
324-
/// equivalent to BBR.Beta: A constant specifying the default multiplicative decrease to make upon each round trip during which the connection detects packet loss (the value is 0.7).
325-
beta: f64,
326-
/// equivalent to BBR.Headroom: A constant specifying the multiplicative factor to apply to BBR.inflight_longterm when calculating
327-
/// a volume of free headroom to try to leave unused in the path
328-
/// (e.g. free space in the bottleneck buffer or free time slots in the bottleneck link) that can be used by cross traffic (the value is 0.15).
329-
headroom: f64,
330322
/// equivalent to BBR.MinPipeCwnd: The minimal C.cwnd value BBR targets, to allow pipelining with endpoints that follow an "ACK every other packet" delayed-ACK policy: 4 * C.SMSS.
331323
min_pipe_cwnd: u64,
332324
/// equivalent to BBR.max_bw: The windowed maximum recent bandwidth sample, obtained using the BBR delivery rate sampling algorithm in
@@ -384,8 +376,6 @@ pub struct Bbr3 {
384376
full_bw_count: u64,
385377
/// equivalent to BBR.min_rtt_stamp: The wall clock time at which the current BBR.min_rtt sample was obtained.
386378
min_rtt_stamp: Option<Instant>,
387-
/// equivalent to BBR.MinRTTFilterLen: A constant specifying the length of the BBR.min_rtt min filter window, BBR.MinRTTFilterLen is 10 secs.
388-
min_rtt_filter_len: u64,
389379
/// equivalent to BBR.ProbeRTTDuration: A constant specifying the minimum duration for which ProbeRTT state holds C.inflight to BBR.MinPipeCwnd or fewer packets: 200 ms.
390380
probe_rtt_duration: Duration,
391381
/// equivalent to BBR.ProbeRTTInterval: A constant specifying the minimum time interval between ProbeRTT states: 5 secs.
@@ -474,14 +464,14 @@ impl Bbr3 {
474464
let probe_rtt_cwnd_gain = config.probe_rtt_cwnd_gain.unwrap_or(PROBE_RTT_CWND_GAIN);
475465
// the calculation for initial pacing rate described here <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.6.2-5>
476466
let nominal_bandwidth = initial_cwnd as f64 / 0.001;
477-
let pacing_rate = STARTUP_PACING_GAIN * nominal_bandwidth;
467+
let pacing_rate = startup_pacing_gain * nominal_bandwidth;
478468
Self {
479469
smss,
480470
initial_cwnd,
481471
delivered: 0,
482472
inflight: 0,
483473
is_cwnd_limited: false,
484-
cycle_count: 0,
474+
cycle_count: false,
485475
cwnd: initial_cwnd,
486476
pacing_rate,
487477
send_quantum: 2 * smss, // we start high, but it will be adjusted in set_send_quantum <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.6.3>
@@ -501,9 +491,6 @@ impl Bbr3 {
501491
round_start: true,
502492
next_round_delivered: 0,
503493
idle_restart: false,
504-
loss_thresh: LOSS_THRESH,
505-
beta: BETA,
506-
headroom: HEADROOM,
507494
min_pipe_cwnd: 4 * smss, // 4 * C.SMSS as defined in <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-2.7-4>
508495
max_bw: 0.0,
509496
bw_shortterm: 0.0,
@@ -526,7 +513,6 @@ impl Bbr3 {
526513
full_bw: 0.0,
527514
full_bw_count: 0,
528515
min_rtt_stamp: None,
529-
min_rtt_filter_len: MIN_RTT_FILTER_LEN,
530516
probe_rtt_cwnd_gain,
531517
probe_rtt_duration: Duration::from_millis(PROBE_RTT_DURATION_MS),
532518
probe_rtt_interval: Duration::from_secs(PROBE_RTT_INTERVAL_SEC),
@@ -586,7 +572,7 @@ impl Bbr3 {
586572
let inflight_prev = rate_sample.tx_in_flight.saturating_sub(lost_bytes);
587573
let lost_prev = rate_sample.lost.saturating_sub(lost_bytes);
588574
let compared_loss = inflight_prev.saturating_sub(lost_prev);
589-
let lost_prefix = (self.loss_thresh * compared_loss as f64) / (1.0 - self.loss_thresh);
575+
let lost_prefix = (LOSS_THRESH * compared_loss as f64) / (1.0 - LOSS_THRESH);
590576
let inflight_at_loss = inflight_prev + lost_prefix as u64;
591577
return inflight_at_loss;
592578
}
@@ -633,7 +619,7 @@ impl Bbr3 {
633619
if !rate_sample.is_app_limited {
634620
self.inflight_longterm = max(
635621
rate_sample.tx_in_flight,
636-
(self.target_inflight() as f64 * self.beta) as u64,
622+
(self.target_inflight() as f64 * BETA) as u64,
637623
);
638624
}
639625
}
@@ -646,7 +632,7 @@ impl Bbr3 {
646632
/// equivalent to IsInflightTooHigh <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.5.10.2-1>
647633
fn is_inflight_too_high(&self) -> bool {
648634
if let Some(rate_sample) = self.rs {
649-
return rate_sample.lost as f64 > rate_sample.tx_in_flight as f64 * self.loss_thresh;
635+
return rate_sample.lost as f64 > rate_sample.tx_in_flight as f64 * LOSS_THRESH;
650636
}
651637
false
652638
}
@@ -826,10 +812,7 @@ impl Bbr3 {
826812
if self.inflight_longterm == u64::MAX {
827813
return u64::MAX;
828814
}
829-
let total_headroom = max(
830-
self.smss,
831-
(self.headroom * self.inflight_longterm as f64) as u64,
832-
);
815+
let total_headroom = max(self.smss, (HEADROOM * self.inflight_longterm as f64) as u64);
833816
if let Some(inflight_with_headroom) = self.inflight_longterm.checked_sub(total_headroom) {
834817
max(inflight_with_headroom, self.min_pipe_cwnd)
835818
} else {
@@ -875,7 +858,7 @@ impl Bbr3 {
875858

876859
/// equivalent to BBRAdvanceMaxBwFilter <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.5.6>
877860
fn advance_max_bw_filter(&mut self) {
878-
self.cycle_count += 1;
861+
self.cycle_count = !self.cycle_count;
879862
}
880863

881864
/// equivalent to BBRAdaptLongTermModel <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.3.3.6-8>
@@ -946,13 +929,13 @@ impl Bbr3 {
946929
/// equivalent to BBRLossLowerBounds <https://www.ietf.org/archive/id/draft-ietf-ccwg-bbr-04.html#section-5.5.10.3-8>
947930
fn loss_lower_bounds(&mut self) {
948931
// gives max of both f64
949-
self.bw_shortterm = [self.bw_latest, self.beta * self.bw_shortterm]
932+
self.bw_shortterm = [self.bw_latest, BETA * self.bw_shortterm]
950933
.iter()
951934
.copied()
952935
.fold(f64::NAN, f64::max);
953936
self.inflight_shortterm = max(
954937
self.inflight_latest,
955-
(self.beta * self.inflight_shortterm as f64) as u64,
938+
(BETA * self.inflight_shortterm as f64) as u64,
956939
);
957940
}
958941

@@ -1085,8 +1068,10 @@ impl Bbr3 {
10851068
if rate_sample.delivery_rate > 0.0
10861069
&& (rate_sample.delivery_rate >= self.max_bw || !rate_sample.is_app_limited)
10871070
{
1088-
self.max_bw_filter
1089-
.update_max(self.cycle_count, rate_sample.delivery_rate.round() as u64);
1071+
self.max_bw_filter.update_max(
1072+
self.cycle_count as u64,
1073+
rate_sample.delivery_rate.round() as u64,
1074+
);
10901075

10911076
self.max_bw = self.max_bw_filter.get_max() as f64;
10921077
}
@@ -1200,7 +1185,7 @@ impl Bbr3 {
12001185
if let Some(min_rtt_stamp) = self.min_rtt_stamp {
12011186
min_rtt_expired = now
12021187
> min_rtt_stamp
1203-
.checked_add(Duration::from_secs(self.min_rtt_filter_len))
1188+
.checked_add(Duration::from_secs(MIN_RTT_FILTER_LEN))
12041189
.unwrap_or(min_rtt_stamp);
12051190
} else {
12061191
min_rtt_expired = true;
@@ -1395,19 +1380,19 @@ impl Controller for Bbr3 {
13951380
self.handle_restart_from_idle(now);
13961381
}
13971382

1398-
fn on_packet_acked(
1383+
fn on_ack(
13991384
&mut self,
14001385
now: Instant,
14011386
sent: Instant,
1402-
bytes: u16,
1387+
bytes: u64,
14031388
packet_number: u64,
1389+
_app_limited: bool,
14041390
rtt: &RttEstimator,
14051391
) {
1406-
let bytes64 = bytes as u64;
14071392
if let Some(mut rate_sample) = self.rs {
1408-
rate_sample.newly_acked += bytes64;
1393+
rate_sample.newly_acked += bytes;
14091394
self.rs = Some(rate_sample);
1410-
self.delivered += bytes64;
1395+
self.delivered += bytes;
14111396
self.delivered_time = Some(now);
14121397
}
14131398
let p_index_result = self
@@ -1447,7 +1432,7 @@ impl Controller for Bbr3 {
14471432
tx_in_flight: p.tx_in_flight,
14481433
send_elapsed: p.send_time - p.first_send_time,
14491434
ack_elapsed: self.delivered_time.unwrap_or(now) - p.delivered_time,
1450-
newly_acked: bytes64,
1435+
newly_acked: bytes,
14511436
newly_lost: 0,
14521437
lost: 0,
14531438
last_end_seq: packet_number,

quinn-proto/src/congestion/cubic.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl Controller for Cubic {
107107
now: Instant,
108108
sent: Instant,
109109
bytes: u64,
110+
_pn: u64,
110111
app_limited: bool,
111112
rtt: &RttEstimator,
112113
) {

quinn-proto/src/congestion/new_reno.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ impl Controller for NewReno {
4646
_now: Instant,
4747
sent: Instant,
4848
bytes: u64,
49+
_pn: u64,
4950
app_limited: bool,
5051
_rtt: &RttEstimator,
5152
) {

quinn-proto/src/connection/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,13 +1645,11 @@ impl Connection {
16451645
now,
16461646
info.time_sent,
16471647
info.size.into(),
1648+
pn,
16481649
self.app_limited,
16491650
&self.path.rtt,
16501651
);
16511652
}
1652-
self.path
1653-
.congestion
1654-
.on_packet_acked(now, info.time_sent, info.size, pn, &self.path.rtt);
16551653

16561654
// Update state for confirmed delivery of frames
16571655
if let Some(retransmits) = info.retransmits.get() {

0 commit comments

Comments
 (0)