Skip to content

Commit

Permalink
Make sure we can build ndt-server on macOS
Browse files Browse the repository at this point in the history
We don't support macOS officially. However it's useful to build on
a system that is different from the containers where we deploy.

As mentioned in #100, I am convinced that Travis is different enough
from the containers where we deploy to look like macOS.
  • Loading branch information
bassosimone committed Apr 11, 2019
1 parent 63240a9 commit 890c971
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 63 deletions.
6 changes: 4 additions & 2 deletions bbr/bbr_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ package bbr

import (
"os"

"github.com/m-lab/ndt-server/ndt7/model"
)

func enableBBR(*os.File) error {
return ErrNoSupport
}

func getMaxBandwidthAndMinRTT(*os.File) (float64, float64, error) {
return 0.0, 0.0, ErrNoSupport
func getMaxBandwidthAndMinRTT(*os.File) (model.BBRInfo, error) {
return model.BBRInfo{}, ErrNoSupport
}
61 changes: 0 additions & 61 deletions legacy/web100/web100.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
// it only needs to measure once.
package web100

import (
"context"
"errors"
"log"
"os"
"time"

"golang.org/x/sys/unix"
)

// Metrics holds web100 data. According to the legacy NDT protocol, each of
// these metrics is required. That does not mean each is required to be
// non-zero, but it does mean that the field should be present in any response.
Expand All @@ -34,54 +24,3 @@ type Metrics struct {
// Useful metrics that are not part of the required set.
BytesPerSecond float64
}

func summarize(snaps []*unix.TCPInfo) (*Metrics, error) {
if len(snaps) == 0 {
return nil, errors.New("zero-length list of data collected")
}
minrtt := uint32(0)
for _, snap := range snaps {
if snap.Rtt < minrtt || minrtt == 0 {
minrtt = snap.Rtt
}
}
info := &Metrics{MinRTT: minrtt / 1000} // Convert microseconds to milliseconds.
log.Println("Summarized data:", info)
return info, nil
}

// MeasureViaPolling collects all required data by polling. It is required for
// non-BBR connections because MinRTT is one of our critical metrics.
func MeasureViaPolling(ctx context.Context, fp *os.File, c chan *Metrics) {
defer close(c)
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
snaps := make([]*unix.TCPInfo, 0, 100)
// Poll until the context is canceled.
for {
// Get the tcp_cc metrics
info, err := unix.GetsockoptTCPInfo(int(fp.Fd()), unix.IPPROTO_TCP, unix.TCP_INFO)
if err == nil {
snaps = append(snaps, info)
} else {
log.Println("Getsockopt error:", err)
}
select {
case <-ticker.C:
continue
case <-ctx.Done():
info, err := summarize(snaps)
if err == nil {
c <- info
}
return
}
}
}

// TODO: Implement BBR support for legacy clients.
/*
func MeasureBBR(ctx context.Context, fp *os.File) (Metrics, error) {
return Metrics{}, errors.New("MeasureBBR is unimplemented")
}
*/
62 changes: 62 additions & 0 deletions legacy/web100/web100_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package web100

import (
"context"
"errors"
"log"
"os"
"time"

"golang.org/x/sys/unix"
)

func summarize(snaps []*unix.TCPInfo) (*Metrics, error) {
if len(snaps) == 0 {
return nil, errors.New("zero-length list of data collected")
}
minrtt := uint32(0)
for _, snap := range snaps {
if snap.Rtt < minrtt || minrtt == 0 {
minrtt = snap.Rtt
}
}
info := &Metrics{MinRTT: minrtt / 1000} // Convert microseconds to milliseconds.
log.Println("Summarized data:", info)
return info, nil
}

// MeasureViaPolling collects all required data by polling. It is required for
// non-BBR connections because MinRTT is one of our critical metrics.
func MeasureViaPolling(ctx context.Context, fp *os.File, c chan *Metrics) {
defer close(c)
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
snaps := make([]*unix.TCPInfo, 0, 100)
// Poll until the context is canceled.
for {
// Get the tcp_cc metrics
info, err := unix.GetsockoptTCPInfo(int(fp.Fd()), unix.IPPROTO_TCP, unix.TCP_INFO)
if err == nil {
snaps = append(snaps, info)
} else {
log.Println("Getsockopt error:", err)
}
select {
case <-ticker.C:
continue
case <-ctx.Done():
info, err := summarize(snaps)
if err == nil {
c <- info
}
return
}
}
}

// TODO: Implement BBR support for legacy clients.
/*
func MeasureBBR(ctx context.Context, fp *os.File) (Metrics, error) {
return Metrics{}, errors.New("MeasureBBR is unimplemented")
}
*/
14 changes: 14 additions & 0 deletions legacy/web100/web100_stub.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// +build !linux

package web100

import (
"context"
"os"
)

// MeasureViaPolling collects all required data by polling. It is required for
// non-BBR connections because MinRTT is one of our critical metrics.
func MeasureViaPolling(ctx context.Context, fp *os.File, c chan *Metrics) {
// Just a stub.
}

0 comments on commit 890c971

Please sign in to comment.