outlet/rib: don't create collisions during tests

I don't know why this was done. I suppose there was a test around that,
but we don't have it anymore. This made the benchmark tests "bad".
This commit is contained in:
Vincent Bernat
2025-08-16 16:04:42 +02:00
parent 9dd97e452e
commit 1684beefca
4 changed files with 12 additions and 35 deletions

View File

@@ -1,8 +0,0 @@
// SPDX-FileCopyrightText: 2022 Free Mobile
// SPDX-License-Identifier: AGPL-3.0-only
//go:build release
package bmp
const rtaHashMask = 0xffffffffffffffff

View File

@@ -109,7 +109,7 @@ func (rta routeAttributes) Hash() uint64 {
// 16-byte).
state.Add((*byte)(unsafe.Pointer(&rta.largeCommunities[0])), len(rta.largeCommunities)*int(unsafe.Sizeof(rta.largeCommunities[0])))
}
return state.Sum() & rtaHashMask
return state.Sum()
}
// Equal tells if two route attributes are equal.

View File

@@ -5,7 +5,6 @@ package bmp
import (
"fmt"
"hash/maphash"
"math/rand"
"net/netip"
"testing"
@@ -166,29 +165,19 @@ func TestRTAEqual(t *testing.T) {
false,
},
}
outer:
for try := 3; try >= 0; try-- {
// We may have to try a few times because of
// collisions due to reduced hash efficiency during
// tests.
for _, tc := range cases {
equal := tc.rta1.Equal(tc.rta2)
for _, tc := range cases {
equal := tc.rta1.Equal(tc.rta2)
if equal && !tc.equal {
t.Errorf("%s%+v == %+v", tc.pos, tc.rta1, tc.rta2)
} else if !equal && tc.equal {
t.Errorf("%s%+v != %+v", tc.pos, tc.rta1, tc.rta2)
} else {
equal := tc.rta1.Hash() == tc.rta2.Hash()
if equal && !tc.equal {
t.Errorf("%s%+v == %+v", tc.pos, tc.rta1, tc.rta2)
t.Errorf("%s%+v.hash == %+v.hash", tc.pos, tc.rta1, tc.rta2)
} else if !equal && tc.equal {
t.Errorf("%s%+v != %+v", tc.pos, tc.rta1, tc.rta2)
} else {
equal := tc.rta1.Hash() == tc.rta2.Hash()
if equal && !tc.equal {
if try > 0 {
// We may have a collision, change the seed and retry
rtaHashSeed = maphash.MakeSeed()
continue outer
}
t.Errorf("%s%+v.hash == %+v.hash", tc.pos, tc.rta1, tc.rta2)
} else if !equal && tc.equal {
t.Errorf("%s%+v.hash != %+v.hash", tc.pos, tc.rta1, tc.rta2)
}
t.Errorf("%s%+v.hash != %+v.hash", tc.pos, tc.rta1, tc.rta2)
}
}
}

View File

@@ -139,10 +139,6 @@ func (p *Provider) LocalAddr() net.Addr {
return p.address
}
// Reduce hash mask to generate collisions during tests (this should
// be optimized out by the compiler)
const rtaHashMask = 0xff
// MustParseRD parse a route distinguisher and panic on error.
func MustParseRD(input string) RD {
var output RD