summaryrefslogtreecommitdiff
path: root/rpm/parameters.go
blob: 1d7e0655472340b6ddd6b0e9624045bc4acc0e33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * This file is part of Go Responsiveness.
 *
 * Go Responsiveness is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation,
 * either version 2 of the License, or (at your option) any later version.
 * Go Responsiveness is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 * PARTICULAR PURPOSE. See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>.
 */

package rpm

import (
	"fmt"
	"time"

	"github.com/network-quality/goresponsiveness/utilities"
)

type SpecParameters struct {
	TestTimeout      time.Duration // Total test time.
	MovingAvgDist    int
	EvalInterval     time.Duration // How often to reevaluate network conditions.
	TrimmedMeanPct   uint
	StdDevTolerance  float64
	MaxParallelConns int
	ProbeInterval    time.Duration
	ProbeCapacityPct float64
	Percentile       uint
}

func SpecParametersFromArguments(timeout int, mad int, id int, tmp uint, sdt float64, mnp int, mps int, ptc float64, p int) (*SpecParameters, error) {
	if timeout <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative timeout for the test")
	}
	if mad <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative moving-average distance for the test")
	}
	if id <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative reevaluation interval for the test")
	}
	if tmp < 0 {
		return nil, fmt.Errorf("cannot specify a negative trimming percentage for the test")
	}
	if sdt < 0 {
		return nil, fmt.Errorf("cannot specify a negative standard-deviation tolerance for the test")
	}
	if mnp <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative maximum number of parallel connections for the test")
	}
	if mps <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative probing interval for the test")
	}
	if ptc <= 0 {
		return nil, fmt.Errorf("cannot specify a 0 or negative probe capacity for the test")
	}
	if p < 1 || p >= 100 {
		return nil, fmt.Errorf("percentile for statistical calculations (%v) is invalid", p)
	}
	testTimeout := time.Second * time.Duration(timeout)
	evalInterval := time.Second * time.Duration(id)
	probeInterval := utilities.PerSecondToInterval(int64(mps))

	params := SpecParameters{
		TestTimeout: testTimeout, MovingAvgDist: mad,
		EvalInterval: evalInterval, TrimmedMeanPct: tmp, StdDevTolerance: sdt,
		MaxParallelConns: mnp, ProbeInterval: probeInterval, ProbeCapacityPct: ptc, Percentile: uint(p),
	}
	return &params, nil
}

func (parameters *SpecParameters) ToString() string {
	return fmt.Sprintf(
		`Timeout:                                     %v,
Moving-Average Distance:                     %v,
Interval Duration:                           %v,
Trimmed-Mean Percentage:                     %v,
Standard-Deviation Tolerance:                %v,
Maximum number of parallel connections:      %v,
Probe Interval:                              %v (derived from given maximum-probes-per-second parameter),
Maximum Percentage Of Throughput For Probes: %v`,
		parameters.TestTimeout, parameters.MovingAvgDist, parameters.EvalInterval, parameters.TrimmedMeanPct,
		parameters.StdDevTolerance, parameters.MaxParallelConns, parameters.ProbeInterval, parameters.ProbeCapacityPct,
	)
}