use self::rtt::INITIAL_RTT;
use super::*;
use std::time::Instant;
pub fn bbr_init(r: &mut Congestion) {
let bbr = &mut r.bbr_state;
bbr.rtprop = INITIAL_RTT;
bbr.rtprop_stamp = Instant::now();
bbr.next_round_delivered = r.delivery_rate.delivered();
r.send_quantum = r.max_datagram_size;
bbr_init_round_counting(r);
bbr_init_full_pipe(r);
bbr_init_pacing_rate(r);
bbr_enter_startup(r);
}
fn bbr_init_round_counting(r: &mut Congestion) {
let bbr = &mut r.bbr_state;
bbr.next_round_delivered = 0;
bbr.round_start = false;
bbr.round_count = 0;
}
fn bbr_init_pacing_rate(r: &mut Congestion) {
let bbr = &mut r.bbr_state;
let srtt = INITIAL_RTT.as_secs_f64();
let nominal_bandwidth = r.congestion_window as f64 / srtt;
bbr.pacing_rate = (bbr.pacing_gain * nominal_bandwidth) as u64;
}
pub fn bbr_enter_startup(r: &mut Congestion) {
let bbr = &mut r.bbr_state;
bbr.state = BBRStateMachine::Startup;
bbr.pacing_gain = BBR_HIGH_GAIN;
bbr.cwnd_gain = BBR_HIGH_GAIN;
}
fn bbr_init_full_pipe(r: &mut Congestion) {
let bbr = &mut r.bbr_state;
bbr.filled_pipe = false;
bbr.full_bw = 0;
bbr.full_bw_count = 0;
}