From 5a4833234de4ca98ccaa9955f2a2688fb6ad9f56 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Fri, 13 Sep 2019 21:13:48 +0900 Subject: table: add more tests for adj Signed-off-by: FUJITA Tomonori --- internal/pkg/table/adj_test.go | 44 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) (limited to 'internal/pkg/table') diff --git a/internal/pkg/table/adj_test.go b/internal/pkg/table/adj_test.go index d4c892cf..8513bc97 100644 --- a/internal/pkg/table/adj_test.go +++ b/internal/pkg/table/adj_test.go @@ -24,7 +24,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestStaleAll(t *testing.T) { +func TestAddPath(t *testing.T) { pi := &PeerInfo{} attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeOrigin(0)} @@ -37,6 +37,41 @@ func TestStaleAll(t *testing.T) { family := p1.GetRouteFamily() families := []bgp.RouteFamily{family} + adj := NewAdjRib(families) + adj.Update([]*Path{p1, p2}) + assert.Equal(t, len(adj.table[family].destinations), 1) + assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 2) + + p3 := NewPath(pi, nlri2, false, attrs, time.Now(), false) + adj.Update([]*Path{p3}) + + var found *Path + for _, d := range adj.table[family].destinations { + for _, p := range d.knownPathList { + if p.GetNlri().PathIdentifier() == nlri2.PathIdentifier() { + found = p + break + } + } + } + assert.Equal(t, found, p3) + adj.Update([]*Path{p3.Clone(true)}) + assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 1) + adj.Update([]*Path{p1.Clone(true)}) + assert.Equal(t, 0, len(adj.table[family].destinations)) +} + +func TestStale(t *testing.T) { + pi := &PeerInfo{} + attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeOrigin(0)} + + nlri1 := bgp.NewIPAddrPrefix(24, "20.20.10.0") + p1 := NewPath(pi, nlri1, false, attrs, time.Now(), false) + nlri2 := bgp.NewIPAddrPrefix(24, "20.20.20.0") + p2 := NewPath(pi, nlri2, false, attrs, time.Now(), false) + family := p1.GetRouteFamily() + families := []bgp.RouteFamily{family} + adj := NewAdjRib(families) adj.Update([]*Path{p1, p2}) assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 2) @@ -47,6 +82,11 @@ func TestStaleAll(t *testing.T) { assert.True(t, p.IsStale()) } + nlri3 := bgp.NewIPAddrPrefix(24, "20.20.30.0") + p3 := NewPath(pi, nlri3, false, attrs, time.Now(), false) + adj.Update([]*Path{p1, p3}) + adj.DropStale(families) - assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 0) + assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 1) + assert.Equal(t, 1, len(adj.table[family].destinations)) } -- cgit v1.2.3