mirror of
https://github.com/slackhq/nebula.git
synced 2026-05-15 20:37:36 +02:00
More stable e2e test harness, better for benchmarking (#1702)
Some checks failed
gofmt / Run gofmt (push) Failing after 2s
smoke-extra / Run extra smoke tests (push) Failing after 2s
smoke / Run multi node smoke test (push) Failing after 3s
Build and test / Build all and test on ubuntu-linux (push) Failing after 2s
Build and test / Build and test on linux with boringcrypto (push) Failing after 2s
Build and test / Build and test on linux with pkcs11 (push) Failing after 3s
Build and test / Build and test on macos-latest (push) Has been cancelled
Build and test / Build and test on windows-latest (push) Has been cancelled
Some checks failed
gofmt / Run gofmt (push) Failing after 2s
smoke-extra / Run extra smoke tests (push) Failing after 2s
smoke / Run multi node smoke test (push) Failing after 3s
Build and test / Build all and test on ubuntu-linux (push) Failing after 2s
Build and test / Build and test on linux with boringcrypto (push) Failing after 2s
Build and test / Build and test on linux with pkcs11 (push) Failing after 3s
Build and test / Build and test on macos-latest (push) Has been cancelled
Build and test / Build and test on windows-latest (push) Has been cancelled
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/gaissmai/bart"
|
||||
"github.com/slackhq/nebula/config"
|
||||
"github.com/slackhq/nebula/routing"
|
||||
"github.com/slackhq/nebula/udp"
|
||||
)
|
||||
|
||||
type TestTun struct {
|
||||
@@ -54,9 +55,12 @@ func newTunFromFd(_ *config.C, _ *slog.Logger, _ int, _ []netip.Prefix) (*TestTu
|
||||
return nil, fmt.Errorf("newTunFromFd not supported")
|
||||
}
|
||||
|
||||
// Send will place a byte array onto the receive queue for nebula to consume
|
||||
// Send will place a byte array onto the receive queue for nebula to consume.
|
||||
// These are unencrypted ip layer frames destined for another nebula node.
|
||||
// packets should exit the udp side, capture them with udpConn.Get
|
||||
// packets should exit the udp side, capture them with udpConn.Get.
|
||||
//
|
||||
// Send copies the input via the freelist, so the caller is free to mutate
|
||||
// or reuse it after the call returns.
|
||||
func (t *TestTun) Send(packet []byte) {
|
||||
if t.closed.Load() {
|
||||
return
|
||||
@@ -65,7 +69,9 @@ func (t *TestTun) Send(packet []byte) {
|
||||
if t.l.Enabled(context.Background(), slog.LevelDebug) {
|
||||
t.l.Debug("Tun receiving injected packet", "dataLen", len(packet))
|
||||
}
|
||||
t.rxPackets <- packet
|
||||
buf := acquireTunBuf(len(packet))
|
||||
copy(buf, packet)
|
||||
t.rxPackets <- buf
|
||||
}
|
||||
|
||||
// Get will pull an unencrypted ip layer frame from the transmit queue
|
||||
@@ -110,12 +116,44 @@ func (t *TestTun) Write(b []byte) (n int, err error) {
|
||||
return 0, io.ErrClosedPipe
|
||||
}
|
||||
|
||||
packet := make([]byte, len(b), len(b))
|
||||
packet := acquireTunBuf(len(b))
|
||||
copy(packet, b)
|
||||
t.TxPackets <- packet
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
// ReleaseTunBuf returns a slice from TxPackets to the harness freelist, don't use the bytes after the call.
|
||||
// Channel-backed instead of sync.Pool because putting a []byte in a sync.Pool escapes the slice header to heap.
|
||||
func ReleaseTunBuf(b []byte) {
|
||||
if b == nil {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case tunBufFreelist <- b:
|
||||
default:
|
||||
// Freelist full; drop the buffer for the GC.
|
||||
}
|
||||
}
|
||||
|
||||
// tunBufFreelist retains the backing arrays for TestTun.Write so steady-state allocation drops to zero once the
|
||||
// freelist has saturated for the current MTU.
|
||||
var tunBufFreelist = make(chan []byte, 64)
|
||||
|
||||
func acquireTunBuf(n int) []byte {
|
||||
var b []byte
|
||||
select {
|
||||
case b = <-tunBufFreelist:
|
||||
default:
|
||||
b = make([]byte, 0, udp.MTU)
|
||||
}
|
||||
if cap(b) < n {
|
||||
b = make([]byte, n)
|
||||
} else {
|
||||
b = b[:n]
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (t *TestTun) Close() error {
|
||||
if t.closed.CompareAndSwap(false, true) {
|
||||
close(t.rxPackets)
|
||||
@@ -129,8 +167,14 @@ func (t *TestTun) Read(b []byte) (int, error) {
|
||||
if !ok {
|
||||
return 0, os.ErrClosed
|
||||
}
|
||||
n := len(p)
|
||||
copy(b, p)
|
||||
return len(p), nil
|
||||
// Send always pushes a freelist-acquired slice, return it once we've copied the bytes into the caller's buffer.
|
||||
select {
|
||||
case tunBufFreelist <- p:
|
||||
default:
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (t *TestTun) SupportsMultiqueue() bool {
|
||||
|
||||
Reference in New Issue
Block a user