Take the line rate as a constant so nothing has to be plugged in, and drop the config box
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -18,12 +17,11 @@ import (
|
|||||||
const wireOverhead = 24
|
const wireOverhead = 24
|
||||||
|
|
||||||
type endpoint struct {
|
type endpoint struct {
|
||||||
name string
|
name string
|
||||||
tag string
|
tag string
|
||||||
idx int
|
idx int
|
||||||
mac [6]byte
|
mac [6]byte
|
||||||
mtu int
|
mtu int
|
||||||
speed float64
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e endpoint) macString() string {
|
func (e endpoint) macString() string {
|
||||||
@@ -185,14 +183,7 @@ func lookupEndpoint(name string) (endpoint, error) {
|
|||||||
}
|
}
|
||||||
var mac [6]byte
|
var mac [6]byte
|
||||||
copy(mac[:], ifi.HardwareAddr)
|
copy(mac[:], ifi.HardwareAddr)
|
||||||
// The rate columns are graded against this, so a guessed speed would silently
|
return endpoint{name: name, idx: ifi.Index, mac: mac, mtu: ifi.MTU}, nil
|
||||||
// grade every reading against the wrong target.
|
|
||||||
v, ok := readUint("/sys/class/net/" + name + "/speed")
|
|
||||||
if !ok || v == 0 {
|
|
||||||
return endpoint{}, fmt.Errorf("%s: cannot read link speed", name)
|
|
||||||
}
|
|
||||||
return endpoint{name: name, idx: ifi.Index, mac: mac, mtu: ifi.MTU,
|
|
||||||
speed: float64(v) / 1000}, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *direction) snapshot() sample {
|
func (d *direction) snapshot() sample {
|
||||||
@@ -517,6 +508,10 @@ const (
|
|||||||
batchSize = 64
|
batchSize = 64
|
||||||
|
|
||||||
probeEther uint16 = etherBase + numStreams
|
probeEther uint16 = etherBase + numStreams
|
||||||
|
|
||||||
|
// A constant rather than the negotiated speed, since this has to come up
|
||||||
|
// with no cable in the port and nothing to negotiate.
|
||||||
|
linkSpeed = 10.0
|
||||||
)
|
)
|
||||||
|
|
||||||
var frameSizes = []int{64, 128, 256, 512, 1024, 1280, 1514}
|
var frameSizes = []int{64, 128, 256, 512, 1024, 1280, 1514}
|
||||||
@@ -617,33 +612,16 @@ func run(aName, bName string, nsPerM float64) error {
|
|||||||
for _, e := range []endpoint{a, b} {
|
for _, e := range []endpoint{a, b} {
|
||||||
linkRows = append(linkRows, []string{
|
linkRows = append(linkRows, []string{
|
||||||
paint(e.tag, cCyan), e.name, e.macString(),
|
paint(e.tag, cCyan), e.name, e.macString(),
|
||||||
fmt.Sprintf("%.0f Gb/s", e.speed), fmt.Sprintf("%d", e.mtu),
|
fmt.Sprintf("%.0f Gb/s", linkSpeed), fmt.Sprintf("%d", e.mtu),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fmt.Println(renderBox("LINKS",
|
fmt.Println(renderBox("LINKS",
|
||||||
[]string{"TAG", "INTERFACE", "MAC", "SPEED", "MTU"},
|
[]string{"TAG", "INTERFACE", "MAC", "SPEED", "MTU"},
|
||||||
[]bool{false, false, false, true, true}, linkRows))
|
[]bool{false, false, false, true, true}, linkRows))
|
||||||
|
fmt.Println()
|
||||||
|
|
||||||
// One row carries both directions, so line rate is both links at once.
|
// One row carries both directions, so line rate is both links at once.
|
||||||
target := a.speed * float64(len(dirs))
|
target := linkSpeed * float64(len(dirs))
|
||||||
sizeStrs := make([]string, len(frameSizes))
|
|
||||||
for i, s := range frameSizes {
|
|
||||||
sizeStrs[i] = fmt.Sprintf("%d", s)
|
|
||||||
}
|
|
||||||
fmt.Println(renderBox("CONFIG",
|
|
||||||
[]string{"SETTING", "VALUE"},
|
|
||||||
[]bool{false, false}, [][]string{
|
|
||||||
{"frame sizes", strings.Join(sizeStrs, " ")},
|
|
||||||
{"streams", fmt.Sprintf("%d per direction, ethertypes 0x%04x-0x%04x",
|
|
||||||
numStreams, ethertypes[0], ethertypes[len(ethertypes)-1])},
|
|
||||||
{"probe", fmt.Sprintf("ethertype 0x%04x every %s", probeEther, probeInterval)},
|
|
||||||
{"batch", fmt.Sprintf("%d frames per syscall", batchSize)},
|
|
||||||
{"calibration", fmt.Sprintf("%g ns/m, zero taken from the shortest delay seen so far", nsPerM)},
|
|
||||||
{"buffers", fmt.Sprintf("sndbuf %sB, rcvbuf %sB",
|
|
||||||
scaleCount(uint64(sockBufSize(dirs[0].txFDs[0], unix.SO_SNDBUF))),
|
|
||||||
scaleCount(uint64(sockBufSize(dirs[0].rxFDs[0], unix.SO_RCVBUF))))},
|
|
||||||
}))
|
|
||||||
fmt.Println()
|
|
||||||
|
|
||||||
var doneTx, doneRx atomic.Bool
|
var doneTx, doneRx atomic.Bool
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
|
|||||||
@@ -22,14 +22,6 @@ func setBufForce(fd, forceOpt, opt, size int) error {
|
|||||||
return unix.SetsockoptInt(fd, unix.SOL_SOCKET, opt, size)
|
return unix.SetsockoptInt(fd, unix.SOL_SOCKET, opt, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func sockBufSize(fd, opt int) int {
|
|
||||||
v, err := unix.GetsockoptInt(fd, unix.SOL_SOCKET, opt)
|
|
||||||
if err != nil {
|
|
||||||
panic(fmt.Sprintf("reading socket buffer size: %v", err))
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sndbufBytes = 8 << 20
|
sndbufBytes = 8 << 20
|
||||||
rcvbufBytes = 64 << 20
|
rcvbufBytes = 64 << 20
|
||||||
|
|||||||
@@ -585,6 +585,9 @@ func withIoctlSocket(fn func(fd int) []checkResult) []checkResult {
|
|||||||
return fn(fd)
|
return fn(fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Nothing here waits for a carrier: the two ports are the two ends of the cable
|
||||||
|
// under test, so with no cable there will never be one, and a dead wire is a
|
||||||
|
// result to report rather than a reason to refuse to start.
|
||||||
func configureSystem(ifnames []string, ethertypes []uint16) []checkResult {
|
func configureSystem(ifnames []string, ethertypes []uint16) []checkResult {
|
||||||
return withIoctlSocket(func(fd int) []checkResult {
|
return withIoctlSocket(func(fd int) []checkResult {
|
||||||
out := []checkResult{checkGovernor(wantGovernor)}
|
out := []checkResult{checkGovernor(wantGovernor)}
|
||||||
|
|||||||
Reference in New Issue
Block a user