Skip to content

Commit

Permalink
table: add more tests for adj
Browse files Browse the repository at this point in the history
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
  • Loading branch information
fujita committed Sep 17, 2019
1 parent 589fdea commit 5a48332
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions internal/pkg/table/adj_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}

Expand All @@ -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)
Expand All @@ -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))
}

0 comments on commit 5a48332

Please sign in to comment.