diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-09-13 21:13:48 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-09-17 21:11:05 +0900 |
commit | 5a4833234de4ca98ccaa9955f2a2688fb6ad9f56 (patch) | |
tree | 5c76b6c9882ea3a7042a804c8cf91fe80d17a28d | |
parent | 589fdea311c69ad92f9ded519a0f8c99320a47dc (diff) |
table: add more tests for adj
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
-rw-r--r-- | internal/pkg/table/adj_test.go | 44 |
1 files changed, 42 insertions, 2 deletions
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)} @@ -39,6 +39,41 @@ func TestStaleAll(t *testing.T) { 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) adj.StaleAll(families) @@ -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)) } |