fable wants to DIY a hash

This commit is contained in:
JackDoan
2026-08-04 09:56:39 -05:00
parent d8d5ce344d
commit e1d96b932a
4 changed files with 115 additions and 44 deletions
+45
View File
@@ -110,3 +110,48 @@ func BenchmarkDispatchSeedHeavy(b *testing.B) {
}
runDispatchBench(b, pkts, len(pkts))
}
// TestFlowKeyDigestDistinct pins digest quality: distinct flows must produce distinct keys across
// a large sample, and the v4/v6 domains must not alias. Collisions are tolerated by construction
// (headersMatch gates every merge), so this is a quality canary, not a correctness requirement.
func TestFlowKeyDigestDistinct(t *testing.T) {
seen := make(map[flowKey]struct{}, 1<<17)
v4 := make([]byte, 40)
v4[0] = 0x45
v4[3] = 40 // total length
add := func(fk flowKey) {
if _, dup := seen[fk]; dup {
t.Fatal("flow digest collision in small sample")
}
seen[fk] = struct{}{}
}
var fk flowKey
for a := range 256 {
for b := range 128 {
v4[15] = byte(a) // src low byte
v4[19] = byte(b) // dst low byte
v4[21] = byte(a)
v4[23] = byte(b)
trimmed, ok := fk.parseIPv4Prologue(v4)
if !ok {
t.Fatal("v4 prologue rejected synthetic packet")
}
_ = trimmed
add(fk.withPorts(uint32(a)<<16 | uint32(b)))
}
}
v6 := make([]byte, 60)
v6[0] = 0x60
for a := range 256 {
for b := range 128 {
v6[23] = byte(a)
v6[39] = byte(b)
trimmed, ok := fk.parseIPv6Prologue(v6)
if !ok {
t.Fatal("v6 prologue rejected synthetic packet")
}
_ = trimmed
add(fk.withPorts(uint32(a)<<16 | uint32(b)))
}
}
}