mirror of
https://git.zx2c4.com/wireguard-go
synced 2024-11-15 01:05:15 +01:00
Trie random test
Test trie against naive implementation of prefix routing.
This commit is contained in:
parent
a377bcaed7
commit
dbc3ee3e9d
@ -12,7 +12,13 @@ const (
|
|||||||
NumberOfTests = 10000
|
NumberOfTests = 10000
|
||||||
)
|
)
|
||||||
|
|
||||||
type SlowRouter []*Trie
|
type SlowNode struct {
|
||||||
|
peer *Peer
|
||||||
|
cidr uint
|
||||||
|
bits []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type SlowRouter []*SlowNode
|
||||||
|
|
||||||
func (r SlowRouter) Len() int {
|
func (r SlowRouter) Len() int {
|
||||||
return len(r)
|
return len(r)
|
||||||
@ -34,7 +40,7 @@ func (r SlowRouter) Insert(addr []byte, cidr uint, peer *Peer) SlowRouter {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r = append(r, &Trie{
|
r = append(r, &SlowNode{
|
||||||
cidr: cidr,
|
cidr: cidr,
|
||||||
bits: addr,
|
bits: addr,
|
||||||
peer: peer,
|
peer: peer,
|
||||||
@ -81,7 +87,7 @@ func TestTrieRandomIPv4(t *testing.T) {
|
|||||||
peer1 := slow.Lookup(addr[:])
|
peer1 := slow.Lookup(addr[:])
|
||||||
peer2 := trie.Lookup(addr[:])
|
peer2 := trie.Lookup(addr[:])
|
||||||
if peer1 != peer2 {
|
if peer1 != peer2 {
|
||||||
t.Error("Trie did not match niave implementation, for:", addr)
|
t.Error("Trie did not match naive implementation, for:", addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +120,7 @@ func TestTrieRandomIPv6(t *testing.T) {
|
|||||||
peer1 := slow.Lookup(addr[:])
|
peer1 := slow.Lookup(addr[:])
|
||||||
peer2 := trie.Lookup(addr[:])
|
peer2 := trie.Lookup(addr[:])
|
||||||
if peer1 != peer2 {
|
if peer1 != peer2 {
|
||||||
t.Error("Trie did not match niave implementation, for:", addr)
|
t.Error("Trie did not match naive implementation, for:", addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user