summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table
diff options
context:
space:
mode:
authormageshgv <mageshgv@gmail.com>2019-10-16 15:18:38 -0700
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-18 07:28:10 +0900
commit29412028a7ab41fd953a0ea5cc87a728b212ab17 (patch)
tree1c4bf290cac55484119820373f331967fc06eb61 /internal/pkg/table
parent0794811562fdad2affbf48200b88e36cad88a578 (diff)
Fix adj-out display with add path enabled
Diffstat (limited to 'internal/pkg/table')
-rw-r--r--internal/pkg/table/adj.go37
-rw-r--r--internal/pkg/table/adj_test.go29
2 files changed, 66 insertions, 0 deletions
diff --git a/internal/pkg/table/adj.go b/internal/pkg/table/adj.go
index d63537f8..9ae1e156 100644
--- a/internal/pkg/table/adj.go
+++ b/internal/pkg/table/adj.go
@@ -89,6 +89,43 @@ func (adj *AdjRib) Update(pathList []*Path) {
}
}
+/* The provided pathList is expected to be the real candidate routes after policy evaluation.
+ For routes that are filtered by policy, there could be a mismatch between display
+ and actual rib sent to the peer (if softreset out was not run).
+ Only used to display adj-out because we do not maintain a separate adj-out table
+*/
+func (adj *AdjRib) UpdateAdjRibOut(pathList []*Path) {
+ for _, path := range pathList {
+ if path == nil || path.IsEOR() {
+ continue
+ }
+ t := adj.table[path.GetRouteFamily()]
+ d := t.getOrCreateDest(path.GetNlri(), 0)
+
+ var old *Path
+ idx := -1
+ for i, p := range d.knownPathList {
+ if p.GetNlri().PathLocalIdentifier() == path.GetNlri().PathLocalIdentifier() {
+ idx = i
+ break
+ }
+ }
+ if idx != -1 {
+ old = d.knownPathList[idx]
+ }
+
+ // No withdraw use case for adj-out
+ if idx != -1 {
+ if old.Equal(path) {
+ path.setTimestamp(old.GetTimestamp())
+ }
+ d.knownPathList[idx] = path
+ } else {
+ d.knownPathList = append(d.knownPathList, path)
+ }
+ }
+}
+
func (adj *AdjRib) walk(families []bgp.RouteFamily, fn func(*Destination) bool) {
for _, f := range families {
if t, ok := adj.table[f]; ok {
diff --git a/internal/pkg/table/adj_test.go b/internal/pkg/table/adj_test.go
index 9e48538f..99aba0ff 100644
--- a/internal/pkg/table/adj_test.go
+++ b/internal/pkg/table/adj_test.go
@@ -61,6 +61,35 @@ func TestAddPath(t *testing.T) {
assert.Equal(t, 0, len(adj.table[family].destinations))
}
+func TestAddPathAdjOut(t *testing.T) {
+ pi := &PeerInfo{}
+ attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeOrigin(0)}
+
+ nlri1 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
+ nlri1.SetPathIdentifier(1)
+ nlri1.SetPathLocalIdentifier(1)
+ p1 := NewPath(pi, nlri1, false, attrs, time.Now(), false)
+ nlri2 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
+ nlri2.SetPathIdentifier(1)
+ nlri2.SetPathLocalIdentifier(2)
+ p2 := NewPath(pi, nlri2, false, attrs, time.Now(), false)
+ nlri3 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
+ nlri3.SetPathIdentifier(2)
+ nlri3.SetPathLocalIdentifier(2)
+ p3 := NewPath(pi, nlri3, false, attrs, time.Now(), false)
+ nlri4 := bgp.NewIPAddrPrefix(24, "20.20.20.0")
+ nlri4.SetPathIdentifier(3)
+ nlri4.SetPathLocalIdentifier(2)
+ p4 := NewPath(pi, nlri4, false, attrs, time.Now(), false)
+ family := p1.GetRouteFamily()
+ families := []bgp.RouteFamily{family}
+
+ adj := NewAdjRib(families)
+ adj.UpdateAdjRibOut([]*Path{p1, p2, p3, p4})
+ assert.Equal(t, len(adj.table[family].destinations), 1)
+ assert.Equal(t, adj.Count([]bgp.RouteFamily{family}), 2)
+}
+
func TestStale(t *testing.T) {
pi := &PeerInfo{}
attrs := []bgp.PathAttributeInterface{bgp.NewPathAttributeOrigin(0)}