1
//! Test helpers.
2

            
3
use super::{CongestionWindow, rtt::RoundtripTimeEstimator};
4

            
5
// Make a new RTT estimator.
6
10
pub(crate) fn new_rtt_estimator() -> RoundtripTimeEstimator {
7
10
    RoundtripTimeEstimator::new(&params::build_rtt_params())
8
10
}
9

            
10
// Make a new congestion window.
11
28
pub(crate) fn new_cwnd() -> CongestionWindow {
12
28
    CongestionWindow::new(params::build_cwnd_params())
13
28
}
14

            
15
pub(crate) mod params {
16
    use tor_units::Percentage;
17

            
18
    use crate::ccparams::{
19
        Algorithm, CongestionControlParams, CongestionControlParamsBuilder, CongestionWindowParams,
20
        CongestionWindowParamsBuilder, FixedWindowParams, FixedWindowParamsBuilder,
21
        RoundTripEstimatorParams, RoundTripEstimatorParamsBuilder, VegasParamsBuilder,
22
    };
23

            
24
404
    fn build_fixed_params() -> FixedWindowParams {
25
404
        FixedWindowParamsBuilder::default()
26
404
            .circ_window_start(1000)
27
404
            .circ_window_min(100)
28
404
            .circ_window_max(1000)
29
404
            .build()
30
404
            .expect("Unable to build fixed window params")
31
404
    }
32

            
33
82
    pub(crate) fn build_cc_vegas_params() -> CongestionControlParams {
34
        // Following values are the default from the proposal. They likely differ from what the
35
        // consensus uses today.
36
82
        let params = VegasParamsBuilder::default()
37
82
            .cell_in_queue_params((186, 248, 310, 186, 600).into())
38
82
            .ss_cwnd_max(5000)
39
82
            .cwnd_full_gap(4)
40
82
            .cwnd_full_min_pct(Percentage::new(25))
41
82
            .cwnd_full_per_cwnd(1)
42
82
            .build()
43
82
            .expect("Unable to build Vegas params");
44
82
        CongestionControlParamsBuilder::default()
45
82
            .rtt_params(build_rtt_params())
46
82
            .cwnd_params(build_cwnd_params())
47
82
            .alg(Algorithm::Vegas(params))
48
82
            .fixed_window_params(build_fixed_params())
49
82
            .build()
50
82
            .expect("Unable to build CC params")
51
82
    }
52

            
53
322
    pub(crate) fn build_cc_fixed_params() -> CongestionControlParams {
54
322
        let params = build_fixed_params();
55
322
        CongestionControlParamsBuilder::default()
56
322
            .rtt_params(build_rtt_params())
57
322
            .cwnd_params(build_cwnd_params())
58
322
            .alg(Algorithm::FixedWindow(params))
59
322
            .fixed_window_params(params)
60
322
            .build()
61
322
            .expect("Unable to build CC params")
62
322
    }
63

            
64
    // Build the round trip estimator parameters. with good enough values for tests.
65
414
    pub(crate) fn build_rtt_params() -> RoundTripEstimatorParams {
66
414
        RoundTripEstimatorParamsBuilder::default()
67
414
            .ewma_cwnd_pct(Percentage::new(50))
68
414
            .ewma_max(10)
69
414
            .ewma_ss_max(2)
70
414
            .rtt_reset_pct(Percentage::new(100))
71
414
            .build()
72
414
            .expect("Unable to build RTT parameters")
73
414
    }
74

            
75
    // Build the congestion window parameters. with good enough values for tests.
76
432
    pub(crate) fn build_cwnd_params() -> CongestionWindowParams {
77
        // Values taken from the prop324.
78
432
        CongestionWindowParamsBuilder::default()
79
432
            .cwnd_init(124)
80
432
            .cwnd_inc_pct_ss(Percentage::new(100))
81
432
            .cwnd_inc(1)
82
432
            .cwnd_inc_rate(31)
83
432
            .cwnd_min(124)
84
432
            .cwnd_max(u32::MAX)
85
432
            .sendme_inc(31)
86
432
            .build()
87
432
            .expect("Unable to build congestion window parameters")
88
432
    }
89
}