ooni-probe-cli/nettests/ndt.go

83 lines
2.1 KiB
Go
Raw Normal View History

2019-12-02 16:57:55 +01:00
package nettests
2018-02-13 16:16:23 +01:00
import (
"github.com/pkg/errors"
2018-02-13 16:16:23 +01:00
)
// NDT test implementation. We use v7 of NDT since 2020-03-12.
2018-02-13 16:16:23 +01:00
type NDT struct {
}
// Run starts the test
2019-12-02 16:57:55 +01:00
func (n NDT) Run(ctl *Controller) error {
builder, err := ctl.Ctx.Session.NewExperimentBuilder("ndt7")
if err != nil {
return err
}
return ctl.Run(builder, []string{""})
2018-02-13 16:16:23 +01:00
}
2018-09-10 12:41:28 +02:00
// NDTTestKeys for the test
type NDTTestKeys struct {
Upload float64 `json:"upload"`
Download float64 `json:"download"`
Ping float64 `json:"ping"`
MaxRTT float64 `json:"max_rtt"`
AvgRTT float64 `json:"avg_rtt"`
MinRTT float64 `json:"min_rtt"`
MSS float64 `json:"mss"`
RetransmitRate float64 `json:"retransmit_rate"`
IsAnomaly bool `json:"-"`
2018-02-13 16:16:23 +01:00
}
2018-09-10 12:41:28 +02:00
// GetTestKeys generates a summary for a test run
func (n NDT) GetTestKeys(tk map[string]interface{}) (interface{}, error) {
var err error
testKeys := NDTTestKeys{IsAnomaly: false}
summary, ok := tk["summary"].(map[string]interface{})
if !ok {
return testKeys, errors.New("summary key is invalid")
}
// XXX there is likely a better pattern for this
testKeys.Upload, ok = summary["upload"].(float64)
if !ok {
err = errors.Wrap(err, "upload key invalid")
}
testKeys.Download, ok = summary["download"].(float64)
if !ok {
err = errors.Wrap(err, "download key invalid")
}
testKeys.Ping, ok = summary["ping"].(float64)
if !ok {
err = errors.Wrap(err, "ping key invalid")
}
testKeys.MaxRTT, ok = summary["max_rtt"].(float64)
if !ok {
err = errors.Wrap(err, "max_rtt key invalid")
}
testKeys.AvgRTT, ok = summary["avg_rtt"].(float64)
if !ok {
err = errors.Wrap(err, "avg_rtt key invalid")
}
testKeys.MinRTT, ok = summary["min_rtt"].(float64)
if !ok {
err = errors.Wrap(err, "min_rtt key invalid")
}
testKeys.MSS, ok = summary["mss"].(float64)
if !ok {
err = errors.Wrap(err, "mss key invalid")
}
testKeys.RetransmitRate, ok = summary["retransmit_rate"].(float64)
if !ok {
err = errors.Wrap(err, "retransmit_rate key invalid")
2018-02-13 16:16:23 +01:00
}
return testKeys, err
2018-02-13 16:16:23 +01:00
}
// LogSummary writes the summary to the standard output
func (n NDT) LogSummary(s string) error {
return nil
}