ooni-probe-cli/nettests/groups/groups.go

88 lines
2.1 KiB
Go
Raw Normal View History

2018-02-13 10:48:46 +01:00
package groups
import (
"encoding/json"
"github.com/apex/log"
"github.com/openobservatory/gooni/internal/database"
2018-02-13 10:48:46 +01:00
"github.com/openobservatory/gooni/nettests"
2018-02-13 16:16:23 +01:00
"github.com/openobservatory/gooni/nettests/performance"
2018-02-13 10:48:46 +01:00
"github.com/openobservatory/gooni/nettests/websites"
)
// NettestGroup base structure
type NettestGroup struct {
Label string
Nettests []nettests.Nettest
Summary database.ResultSummaryFunc
}
// PerformanceSummary is the result summary for a performance test
type PerformanceSummary struct {
Upload int64
Download int64
Ping float64
Bitrate int64
}
2018-02-13 10:48:46 +01:00
// NettestGroups that can be run by the user
var NettestGroups = map[string]NettestGroup{
"websites": NettestGroup{
2018-02-13 10:48:46 +01:00
Label: "Websites",
Nettests: []nettests.Nettest{
websites.WebConnectivity{},
},
Summary: func(m database.SummaryMap) (string, error) {
return "{}", nil
},
2018-02-13 10:48:46 +01:00
},
"performance": NettestGroup{
2018-02-13 16:16:23 +01:00
Label: "Performance",
Nettests: []nettests.Nettest{
2018-03-14 14:44:37 +01:00
performance.Dash{},
2018-02-13 16:16:23 +01:00
performance.NDT{},
},
Summary: func(m database.SummaryMap) (string, error) {
var (
err error
ndtSummary performance.NDTSummary
dashSummary performance.DashSummary
summary PerformanceSummary
)
err = json.Unmarshal([]byte(m["Dash"]), &dashSummary)
if err != nil {
log.WithError(err).Error("failed to unmarshal Dash summary")
return "", err
}
err = json.Unmarshal([]byte(m["Ndt"]), &ndtSummary)
if err != nil {
2018-03-20 14:31:05 +01:00
log.WithError(err).Error("failed to unmarshal NDT summary")
return "", err
}
summary.Bitrate = dashSummary.Bitrate
summary.Download = ndtSummary.Download
summary.Upload = ndtSummary.Upload
summary.Ping = ndtSummary.AvgRTT
summaryBytes, err := json.Marshal(summary)
if err != nil {
return "", err
}
return string(summaryBytes), nil
},
2018-02-13 10:48:46 +01:00
},
"middleboxes": NettestGroup{
2018-02-13 10:48:46 +01:00
Label: "Middleboxes",
Nettests: []nettests.Nettest{},
Summary: func(m database.SummaryMap) (string, error) {
return "{}", nil
},
2018-02-13 10:48:46 +01:00
},
"im": NettestGroup{
2018-02-13 10:48:46 +01:00
Label: "Instant Messaging",
Nettests: []nettests.Nettest{},
Summary: func(m database.SummaryMap) (string, error) {
return "{}", nil
},
2018-02-13 10:48:46 +01:00
},
}