diff options
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) |