From 635128d3e56475dfea9a06ab07feca8acf71c16a Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 12 Jan 2021 14:25:27 +0900 Subject: table: fix longer-prefixes lookup probably regression due to the introduction of critbitgo. Signed-off-by: FUJITA Tomonori --- internal/pkg/table/table_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'internal/pkg/table/table_test.go') diff --git a/internal/pkg/table/table_test.go b/internal/pkg/table/table_test.go index e0f1f3cf..f72e62b9 100644 --- a/internal/pkg/table/table_test.go +++ b/internal/pkg/table/table_test.go @@ -24,6 +24,23 @@ import ( "github.com/stretchr/testify/assert" ) +func TestLookupLonger(t *testing.T) { + tbl := NewTable(bgp.RF_IPv4_UC) + + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(23, "11.0.0.0"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(24, "11.0.0.0"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(32, "11.0.0.4"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(32, "11.0.0.129"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(28, "11.0.0.144"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(29, "11.0.0.144"), 0)) + tbl.setDestination(NewDestination(bgp.NewIPAddrPrefix(32, "11.0.0.145"), 0)) + + r, _ := tbl.GetLongerPrefixDestinations("11.0.0.128/25") + assert.Equal(t, len(r), 4) + r, _ = tbl.GetLongerPrefixDestinations("11.0.0.0/24") + assert.Equal(t, len(r), 6) +} + func TestTableDeleteDest(t *testing.T) { peerT := TableCreatePeer() pathT := TableCreatePath(peerT) @@ -146,6 +163,7 @@ func updateMsgT2() *bgp.BGPMessage { nlri := []*bgp.IPAddrPrefix{bgp.NewIPAddrPrefix(24, "20.20.20.0")} return bgp.NewBGPUpdateMessage(nil, pathAttributes, nlri) } + func updateMsgT3() *bgp.BGPMessage { origin := bgp.NewPathAttributeOrigin(0) aspathParam := []bgp.AsPathParamInterface{bgp.NewAsPathParam(2, []uint16{65100})} -- cgit v1.2.3