diff --git a/main.go b/main.go index 09cf1c7..cbc9ddb 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "net" "os" "os/signal" - "strings" "sync" "sync/atomic" "syscall" @@ -18,12 +17,11 @@ import ( const wireOverhead = 24 type endpoint struct { - name string - tag string - idx int - mac [6]byte - mtu int - speed float64 + name string + tag string + idx int + mac [6]byte + mtu int } func (e endpoint) macString() string { @@ -185,14 +183,7 @@ func lookupEndpoint(name string) (endpoint, error) { } var mac [6]byte copy(mac[:], ifi.HardwareAddr) - // The rate columns are graded against this, so a guessed speed would silently - // 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 + return endpoint{name: name, idx: ifi.Index, mac: mac, mtu: ifi.MTU}, nil } func (d *direction) snapshot() sample { @@ -517,6 +508,10 @@ const ( batchSize = 64 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} @@ -617,33 +612,16 @@ func run(aName, bName string, nsPerM float64) error { for _, e := range []endpoint{a, b} { linkRows = append(linkRows, []string{ 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", []string{"TAG", "INTERFACE", "MAC", "SPEED", "MTU"}, []bool{false, false, false, true, true}, linkRows)) + fmt.Println() // One row carries both directions, so line rate is both links at once. - target := a.speed * 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() + target := linkSpeed * float64(len(dirs)) var doneTx, doneRx atomic.Bool var wg sync.WaitGroup diff --git a/sock.go b/sock.go index 1acaf72..4e91a9c 100644 --- a/sock.go +++ b/sock.go @@ -22,14 +22,6 @@ func setBufForce(fd, forceOpt, opt, size int) error { 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 ( sndbufBytes = 8 << 20 rcvbufBytes = 64 << 20 diff --git a/system.go b/system.go index da5488e..035d499 100644 --- a/system.go +++ b/system.go @@ -585,6 +585,9 @@ func withIoctlSocket(fn func(fd int) []checkResult) []checkResult { 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 { return withIoctlSocket(func(fd int) []checkResult { out := []checkResult{checkGovernor(wantGovernor)}