summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table
diff options
context:
space:
mode:
authorMagesh GV <mageshgv@gmail.com>2019-09-30 10:36:54 -0700
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-02 20:45:44 +0900
commit6f3cb401644fcba0353ac06de261dd40100daa84 (patch)
tree0602d523c17bccf5ebf5ee15eb8c5c07bd19d39a /internal/pkg/table
parent93beafeec5ec667602afe506f2692db81344d5a7 (diff)
Update adjrib for LLGR and preserve aslooped attr
Fixes LLGR community cleared on softreset. Fixes AS Path looped routes added back to rib on Graceful Restart.
Diffstat (limited to 'internal/pkg/table')
-rw-r--r--internal/pkg/table/adj.go30
-rw-r--r--internal/pkg/table/adj_test.go47
-rw-r--r--internal/pkg/table/path.go9
3 files changed, 83 insertions, 3 deletions
diff --git a/internal/pkg/table/adj.go b/internal/pkg/table/adj.go
index 4b9d7c5f..d63537f8 100644
--- a/internal/pkg/table/adj.go
+++ b/internal/pkg/table/adj.go
@@ -173,11 +173,39 @@ func (adj *AdjRib) StaleAll(rfList []bgp.RouteFamily) []*Path {
for i, p := range d.knownPathList {
n := p.Clone(false)
n.MarkStale(true)
+ n.SetAsLooped(p.IsAsLooped())
d.knownPathList[i] = n
- pathList = append(pathList, n)
+ if !n.IsAsLooped() {
+ pathList = append(pathList, n)
+ }
+ }
+ return false
+ })
+ return pathList
+}
+
+func (adj *AdjRib) MarkLLGRStaleOrDrop(rfList []bgp.RouteFamily) []*Path {
+ pathList := make([]*Path, 0, adj.Count(rfList))
+ adj.walk(rfList, func(d *Destination) bool {
+ for i, p := range d.knownPathList {
+ if p.HasNoLLGR() {
+ n := p.Clone(true)
+ n.SetDropped(true)
+ pathList = append(pathList, n)
+ } else {
+ n := p.Clone(false)
+ n.SetAsLooped(p.IsAsLooped())
+ n.SetCommunities([]uint32{uint32(bgp.COMMUNITY_LLGR_STALE)}, false)
+ if p.IsAsLooped() {
+ d.knownPathList[i] = n
+ } else {
+ pathList = append(pathList, n)
+ }
+ }
}
return false
})
+ adj.Update(pathList)
return pathList
}
diff --git a/internal/pkg/table/adj_test.go b/internal/pkg/table/adj_test.go
index 8513bc97..9e48538f 100644
--- a/internal/pkg/table/adj_test.go
+++ b/internal/pkg/table/adj_test.go
@@ -69,14 +69,19 @@ func TestStale(t *testing.T) {
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)
+ p2.SetAsLooped(true)
+
family := p1.GetRouteFamily()
families := []bgp.RouteFamily{family}
adj := NewAdjRib(families)
adj.Update([]*Path{p1, p2})
assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 2)
+ assert.Equal(t, adj.Accepted([]bgp.RouteFamily{family}), 1)
- adj.StaleAll(families)
+ stalePathList := adj.StaleAll(families)
+ // As looped path should not be returned
+ assert.Equal(t, 1, len(stalePathList))
for _, p := range adj.PathList([]bgp.RouteFamily{family}, false) {
assert.True(t, p.IsStale())
@@ -86,7 +91,45 @@ func TestStale(t *testing.T) {
p3 := NewPath(pi, nlri3, false, attrs, time.Now(), false)
adj.Update([]*Path{p1, p3})
- adj.DropStale(families)
+ droppedPathList := adj.DropStale(families)
+ assert.Equal(t, 2, len(droppedPathList))
assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 1)
assert.Equal(t, 1, len(adj.table[family].destinations))
}
+
+func TestLLGRStale(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)
+ p2.SetAsLooped(true) // Not accepted
+
+ nlri3 := bgp.NewIPAddrPrefix(24, "20.20.30.0")
+ p3 := NewPath(pi, nlri3, false, attrs, time.Now(), false)
+ p3.SetAsLooped(true)
+ // Not accepted and then dropped on MarkLLGRStaleOrDrop
+ p3.SetCommunities([]uint32{uint32(bgp.COMMUNITY_NO_LLGR)}, false)
+
+ nlri4 := bgp.NewIPAddrPrefix(24, "20.20.40.0")
+ p4 := NewPath(pi, nlri4, false, attrs, time.Now(), false)
+ // dropped on MarkLLGRStaleOrDrop
+ p4.SetCommunities([]uint32{uint32(bgp.COMMUNITY_NO_LLGR)}, false)
+
+ family := p1.GetRouteFamily()
+ families := []bgp.RouteFamily{family}
+
+ adj := NewAdjRib(families)
+ adj.Update([]*Path{p1, p2, p3, p4})
+ assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 4)
+ assert.Equal(t, adj.Accepted([]bgp.RouteFamily{family}), 2)
+
+ pathList := adj.MarkLLGRStaleOrDrop(families)
+ assert.Equal(t, 3, len(pathList)) // Does not return aslooped path that is retained in adjrib
+ assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 2)
+ assert.Equal(t, adj.Accepted([]bgp.RouteFamily{family}), 1)
+ assert.Equal(t, 2, len(adj.table[family].destinations))
+}
diff --git a/internal/pkg/table/path.go b/internal/pkg/table/path.go
index 32616d2e..9f68fde3 100644
--- a/internal/pkg/table/path.go
+++ b/internal/pkg/table/path.go
@@ -398,6 +398,15 @@ func (path *Path) SetDropped(y bool) {
path.dropped = y
}
+func (path *Path) HasNoLLGR() bool {
+ for _, c := range path.GetCommunities() {
+ if c == uint32(bgp.COMMUNITY_NO_LLGR) {
+ return true
+ }
+ }
+ return false
+}
+
func (path *Path) IsLLGRStale() bool {
for _, c := range path.GetCommunities() {
if c == uint32(bgp.COMMUNITY_LLGR_STALE) {