Get NDT test to run via gooni

This commit is contained in:
Arturo Filastò 2018-02-13 17:16:23 +02:00
parent 7cf5bd2718
commit d3d3ce9d78
9 changed files with 122 additions and 25 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
vendor/
/ooni
*.njson

4
Gopkg.lock generated
View File

@ -86,7 +86,7 @@
branch = "master"
name = "github.com/measurement-kit/go-measurement-kit"
packages = ["."]
revision = "93d8ecd6537d99a83845a9e6928dfd27b665ad6a"
revision = "bc9d9a377259df26dd4d86c9dcc0953c92dde23b"
[[projects]]
branch = "master"
@ -174,6 +174,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "348ea586d927a4a6ce2aef27d7734ba88a12917b9b074ae2d41b229731c9bc33"
inputs-digest = "5405ce55dbd69df4847de599c4e30d7540f208db389b67f2c9789ef6c17351d0"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -5,6 +5,7 @@ import (
"github.com/apex/log"
"github.com/openobservatory/gooni/internal/cli/root"
"github.com/openobservatory/gooni/internal/util"
"github.com/openobservatory/gooni/nettests/groups"
)
func init() {
@ -21,6 +22,8 @@ func init() {
}
log.Infof("%s", config)
log.Infof("%s", ooni)
groups.Run(*nettestGroup, ooni)
return nil
})
}

View File

@ -7,7 +7,7 @@ import (
"github.com/openobservatory/gooni/internal/cli/root"
)
const Version = "0.0.1"
const Version = "3.0.0-dev.0"
func init() {
cmd := root.Command("version", "Show version.")

View File

@ -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"
)
@ -15,7 +18,9 @@ var NettestGroups = map[string]nettests.NettestGroup{
},
"performance": nettests.NettestGroup{
Label: "Performance",
Nettests: []nettests.Nettest{},
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
}

View File

@ -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.

View File

@ -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
}

View File

@ -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

14
ooni.go
View File

@ -33,8 +33,8 @@ func Onboarding(c *Config) error {
// Context for OONI Probe
type Context struct {
config *Config
db *sqlx.DB
Config *Config
DB *sqlx.DB
}
// Init the OONI manager
@ -42,8 +42,8 @@ func (c *Context) Init() error {
if err := legacy.MaybeMigrateHome(); err != nil {
return errors.Wrap(err, "migrating home")
}
if c.config.InformedConsent == false {
if err := Onboarding(c.config); err != nil {
if c.Config.InformedConsent == false {
if err := Onboarding(c.Config); err != nil {
return errors.Wrap(err, "onboarding")
}
}
@ -53,8 +53,8 @@ func (c *Context) Init() error {
// New Context instance.
func New(c *Config, d *sqlx.DB) *Context {
return &Context{
config: c,
db: d,
Config: c,
DB: d,
}
}
@ -81,7 +81,7 @@ type Config struct {
Notifications config.Notifications `json:"notifications"`
AutomatedTesting config.AutomatedTesting `json:"automated_testing"`
NettestGroups config.NettestGroups `json:"test_settings"`
Advanced config.Sharing `json:"advanced"`
Advanced config.Advanced `json:"advanced"`
mutex sync.Mutex
path string