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
408
    fn build_fixed_params() -> FixedWindowParams {
25
408
        FixedWindowParamsBuilder::default()
26
408
            .circ_window_start(1000)
27
408
            .circ_window_min(100)
28
408
            .circ_window_max(1000)
29
408
            .build()
30
408
            .expect("Unable to build fixed window params")
31
408
    }
32

            
33
86
    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
86
        let params = VegasParamsBuilder::default()
37
86
            .cell_in_queue_params((186, 248, 310, 186, 600).into())
38
86
            .ss_cwnd_max(5000)
39
86
            .cwnd_full_gap(4)
40
86
            .cwnd_full_min_pct(Percentage::new(25))
41
86
            .cwnd_full_per_cwnd(1)
42
86
            .build()
43
86
            .expect("Unable to build Vegas params");
44
86
        CongestionControlParamsBuilder::default()
45
86
            .rtt_params(build_rtt_params())
46
86
            .cwnd_params(build_cwnd_params())
47
86
            .alg(Algorithm::Vegas(params))
48
86
            .fixed_window_params(build_fixed_params())
49
86
            .build()
50
86
            .expect("Unable to build CC params")
51
86
    }
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
418
    pub(crate) fn build_rtt_params() -> RoundTripEstimatorParams {
66
418
        RoundTripEstimatorParamsBuilder::default()
67
418
            .ewma_cwnd_pct(Percentage::new(50))
68
418
            .ewma_max(10)
69
418
            .ewma_ss_max(2)
70
418
            .rtt_reset_pct(Percentage::new(100))
71
418
            .build()
72
418
            .expect("Unable to build RTT parameters")
73
418
    }
74

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