diff options
author | Chris Stockton <cstockton@godaddy.com> | 2017-05-31 08:37:09 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-05-31 08:37:09 +0900 |
commit | b529f81ed7d8428200a3f5dcf99a57db9f9f769e (patch) | |
tree | 03f9916f6e26307f8226a158e72d1c8b71ec35d4 /table/destination_test.go | |
parent | b4831ce8e91e6f27e3b241efd0c3fdfd8feca43a (diff) |
table: reduce allocs in NewDestination
In NewDestination we add additional path to AddrToRadixkey to check
the concrete type of nlri.
Diffstat (limited to 'table/destination_test.go')
-rw-r--r-- | table/destination_test.go | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/table/destination_test.go b/table/destination_test.go index 49c63e32..e1f13410 100644 --- a/table/destination_test.go +++ b/table/destination_test.go @@ -17,11 +17,13 @@ package table import ( //"fmt" - "github.com/osrg/gobgp/packet/bgp" - "github.com/stretchr/testify/assert" + "fmt" "net" "testing" "time" + + "github.com/osrg/gobgp/packet/bgp" + "github.com/stretchr/testify/assert" ) func TestDestinationNewIPv4(t *testing.T) { @@ -402,6 +404,28 @@ func TestRadixkey(t *testing.T) { assert.Equal(t, CidrToRadixkey("::ffff:0.0.0.0/96")+"000010100000001100100000", CidrToRadixkey("::ffff:10.3.32.0/120")) } +func TestIpToRadixkey(t *testing.T) { + for i := byte(0); i < 255; i += 3 { + for y := byte(1); y < 128; y *= 2 { + ip := net.IPv4(i, i+2, i+3, i-y) + for n := uint8(16); n <= 32; n += 2 { + exp := CidrToRadixkey(fmt.Sprintf("%v/%d", ip.To4(), n)) + got := IpToRadixkey(ip.To4(), n) + if exp != got { + t.Fatalf(`exp %v; got %v`, exp, got) + } + } + for n := uint8(116); n <= 128; n += 2 { + exp := CidrToRadixkey(fmt.Sprintf("::ffff:%v/%d", ip.To16(), n)) + got := IpToRadixkey(ip.To16(), n) + if exp != got { + t.Fatalf(`exp %v; got %v`, exp, got) + } + } + } + } +} + func TestMultipath(t *testing.T) { UseMultiplePaths.Enabled = true origin := bgp.NewPathAttributeOrigin(0) |