summaryrefslogtreecommitdiff
path: root/rpm/parameters.go
diff options
context:
space:
mode:
authorWill Hawkins <[email protected]>2023-05-23 17:58:14 -0400
committerWill Hawkins <[email protected]>2023-06-21 09:12:22 -0400
commitec2ccf69d8b08abb03fa3bdb3e7e95ae1862d619 (patch)
tree6b636bdbda82db40da89a2bde213c684542850dc /rpm/parameters.go
parent5558f0347baaf6db066314f0eaf82d7fb552b2f7 (diff)
Major Update/Refactor to Support IETF 02
Beginning of a release candidate for support for IETF 02 tag of the responsiveness spec.
Diffstat (limited to 'rpm/parameters.go')
-rw-r--r--rpm/parameters.go85
1 files changed, 85 insertions, 0 deletions
diff --git a/rpm/parameters.go b/rpm/parameters.go
new file mode 100644
index 0000000..aff8639
--- /dev/null
+++ b/rpm/parameters.go
@@ -0,0 +1,85 @@
+/*
+ * 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
+}
+
+func SpecParametersFromArguments(timeout int, mad int, id int, tmp uint, sdt float64, mnp int, mps int, ptc float64) (*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")
+ }
+ 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,
+ }
+ 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,
+ )
+}