Get NDT test to run via gooni
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
package groups
|
||||
|
||||
import (
|
||||
"github.com/apex/log"
|
||||
ooni "github.com/openobservatory/gooni"
|
||||
"github.com/openobservatory/gooni/nettests"
|
||||
"github.com/openobservatory/gooni/nettests/performance"
|
||||
"github.com/openobservatory/gooni/nettests/websites"
|
||||
)
|
||||
|
||||
@@ -14,8 +17,10 @@ var NettestGroups = map[string]nettests.NettestGroup{
|
||||
},
|
||||
},
|
||||
"performance": nettests.NettestGroup{
|
||||
Label: "Performance",
|
||||
Nettests: []nettests.Nettest{},
|
||||
Label: "Performance",
|
||||
Nettests: []nettests.Nettest{
|
||||
performance.NDT{},
|
||||
},
|
||||
},
|
||||
"middleboxes": nettests.NettestGroup{
|
||||
Label: "Middleboxes",
|
||||
@@ -26,3 +31,15 @@ var NettestGroups = map[string]nettests.NettestGroup{
|
||||
Nettests: []nettests.Nettest{},
|
||||
},
|
||||
}
|
||||
|
||||
// Run runs a specific test group
|
||||
func Run(name string, ctx *ooni.Context) error {
|
||||
group := NettestGroups[name]
|
||||
log.Debugf("Running test group %s", group.Label)
|
||||
|
||||
for _, nt := range group.Nettests {
|
||||
ctl := nettests.NewController(ctx)
|
||||
nt.Run(ctl)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
+28
-9
@@ -1,16 +1,18 @@
|
||||
package nettests
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/measurement-kit/go-measurement-kit"
|
||||
ooni "github.com/openobservatory/gooni"
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/openobservatory/gooni/internal/cli/version"
|
||||
)
|
||||
|
||||
// Nettest interface. Every Nettest should implement this.
|
||||
type Nettest interface {
|
||||
Run(*Controller) error
|
||||
Summary(*database.Measurement) string
|
||||
Summary(map[string]interface{}) interface{}
|
||||
LogSummary(string) error
|
||||
}
|
||||
|
||||
@@ -21,21 +23,38 @@ type NettestGroup struct {
|
||||
Summary func(s string) string
|
||||
}
|
||||
|
||||
// Controller is passed to the run method of every Nettest
|
||||
type Controller struct {
|
||||
ctx *ooni.Context
|
||||
}
|
||||
|
||||
// New Nettest Controller
|
||||
func (c *Controller) New(ctx *ooni.Context) *Controller {
|
||||
// NewController creates a nettest controller
|
||||
func NewController(ctx *ooni.Context) *Controller {
|
||||
return &Controller{
|
||||
ctx,
|
||||
}
|
||||
}
|
||||
|
||||
// Controller is passed to the run method of every Nettest
|
||||
type Controller struct {
|
||||
ctx *ooni.Context
|
||||
}
|
||||
|
||||
// Init should be called once to initialise the nettest
|
||||
func (c *Controller) Init(nt *mk.Nettest) {
|
||||
log.Debugf("Init: %s", nt)
|
||||
nt.Options = mk.NettestOptions{
|
||||
IncludeIP: c.ctx.Config.Sharing.IncludeIP,
|
||||
IncludeASN: c.ctx.Config.Sharing.IncludeASN,
|
||||
IncludeCountry: c.ctx.Config.Advanced.IncludeCountry,
|
||||
DisableCollector: false,
|
||||
SoftwareName: "ooniprobe",
|
||||
SoftwareVersion: version.Version,
|
||||
|
||||
// XXX
|
||||
GeoIPCountryPath: "",
|
||||
GeoASNPath: "",
|
||||
OutputPath: "",
|
||||
CaBundlePath: "",
|
||||
}
|
||||
nt.RegisterEventHandler(func(event interface{}) {
|
||||
fmt.Println("Got event", event)
|
||||
})
|
||||
}
|
||||
|
||||
// OnProgress should be called when a new progress event is available.
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package performance
|
||||
|
||||
import (
|
||||
"github.com/measurement-kit/go-measurement-kit"
|
||||
"github.com/openobservatory/gooni/nettests"
|
||||
)
|
||||
|
||||
// NDT test implementation
|
||||
type NDT struct {
|
||||
}
|
||||
|
||||
// Run starts the test
|
||||
func (n NDT) Run(ctl *nettests.Controller) error {
|
||||
nt := mk.Nettest{Name: "Ndt"}
|
||||
ctl.Init(&nt)
|
||||
return nt.Run()
|
||||
}
|
||||
|
||||
// NDTSummary for the test
|
||||
type NDTSummary struct {
|
||||
Upload int64
|
||||
Download int64
|
||||
Ping int64
|
||||
MaxRTT int64
|
||||
AvgRTT int64
|
||||
MinRTT int64
|
||||
MSS int64
|
||||
OutOfOrder int64
|
||||
PacketLoss float32
|
||||
Timeouts int64
|
||||
}
|
||||
|
||||
// Summary generates a summary for a test run
|
||||
func (n NDT) Summary(tk map[string]interface{}) interface{} {
|
||||
simple := tk["simple"].(map[string]interface{})
|
||||
advanced := tk["advanced"].(map[string]interface{})
|
||||
|
||||
return NDTSummary{
|
||||
Upload: simple["upload"].(int64),
|
||||
Download: simple["download"].(int64),
|
||||
Ping: simple["ping"].(int64),
|
||||
MaxRTT: advanced["max_rtt"].(int64),
|
||||
AvgRTT: advanced["avg_rtt"].(int64),
|
||||
MinRTT: advanced["min_rtt"].(int64),
|
||||
MSS: advanced["mss"].(int64),
|
||||
OutOfOrder: advanced["out_of_order"].(int64),
|
||||
PacketLoss: advanced["packet_loss"].(float32),
|
||||
Timeouts: advanced["timeouts"].(int64),
|
||||
}
|
||||
}
|
||||
|
||||
// LogSummary writes the summary to the standard output
|
||||
func (n NDT) LogSummary(s string) error {
|
||||
return nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package websites
|
||||
|
||||
import (
|
||||
"github.com/openobservatory/gooni/internal/database"
|
||||
"github.com/measurement-kit/go-measurement-kit"
|
||||
"github.com/openobservatory/gooni/nettests"
|
||||
)
|
||||
|
||||
@@ -11,12 +11,14 @@ type WebConnectivity struct {
|
||||
|
||||
// Run starts the test
|
||||
func (n WebConnectivity) Run(ctl *nettests.Controller) error {
|
||||
return nil
|
||||
nt := mk.Nettest{Name: "WebConnectivity"}
|
||||
ctl.Init(&nt)
|
||||
return nt.Run()
|
||||
}
|
||||
|
||||
// Summary generates a summary for a test run
|
||||
func (n WebConnectivity) Summary(m *database.Measurement) string {
|
||||
return ""
|
||||
func (n WebConnectivity) Summary(tk map[string]interface{}) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// LogSummary writes the summary to the standard output
|
||||
|
||||
Reference in New Issue
Block a user