summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-11-09 21:11:03 -0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-11-12 21:21:54 -0800
commit0ef26666ef8e920d3fa0a4ebb9c3c8fea4e6cb36 (patch)
tree8cf03170029be413806a6ef3d73c5eae9ac68ccc /table
parent6d52e8c1e5d4de4dfea37656b50c71579343b5f7 (diff)
table: use old best path instead of withdrawn paths
Preparation for removing in-memory adj-out. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/destination.go25
-rw-r--r--table/destination_test.go14
-rw-r--r--table/table_manager.go14
3 files changed, 26 insertions, 27 deletions
diff --git a/table/destination.go b/table/destination.go
index 2d081682..f9ed0e2f 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -206,11 +206,12 @@ func (dd *Destination) validatePath(path *Path) {
//
// Modifies destination's state related to stored paths. Removes withdrawn
// paths from known paths. Also, adds new paths to known paths.
-func (dest *Destination) Calculate(ids []string) (map[string]*Path, []*Path, []*Path) {
- best := make(map[string]*Path, len(ids))
+func (dest *Destination) Calculate(ids []string) (map[string]*Path, map[string]*Path, []*Path) {
+ bestList := make(map[string]*Path, len(ids))
+ oldList := make(map[string]*Path, len(ids))
oldKnownPathList := dest.knownPathList
// First remove the withdrawn paths.
- withdrawnList := dest.explicitWithdraw()
+ dest.explicitWithdraw()
// Do implicit withdrawal
dest.implicitWithdraw()
// Collect all new paths into known paths.
@@ -220,7 +221,7 @@ func (dest *Destination) Calculate(ids []string) (map[string]*Path, []*Path, []*
// Compute new best path
dest.computeKnownBestPath()
- f := func(id string) *Path {
+ f := func(id string) (*Path, *Path) {
old := func() *Path {
for _, p := range oldKnownPathList {
if p.Filtered(id) == POLICY_DIRECTION_NONE {
@@ -237,22 +238,22 @@ func (dest *Destination) Calculate(ids []string) (map[string]*Path, []*Path, []*
// given RT prefix, for building the outbound route filter, and not just
// the best path.
if best.GetRouteFamily() == bgp.RF_RTC_UC {
- return best
+ return best, old
}
- return nil
+ return nil, old
}
if best == nil {
if old == nil {
- return nil
+ return nil, nil
}
- return old.Clone(true)
+ return old.Clone(true), old
}
- return best
+ return best, old
}
var multi []*Path
for _, id := range ids {
- best[id] = f(id)
+ bestList[id], oldList[id] = f(id)
if id == GLOBAL_RIB_NAME && UseMultiplePaths.Enabled {
multipath := func(paths []*Path) []*Path {
mp := make([]*Path, 0, len(paths))
@@ -285,13 +286,13 @@ func (dest *Destination) Calculate(ids []string) (map[string]*Path, []*Path, []*
if diff(oldM, newM) {
multi = newM
if len(newM) == 0 {
- multi = []*Path{best[id]}
+ multi = []*Path{bestList[id]}
}
}
}
}
- return best, withdrawnList, multi
+ return bestList, oldList, multi
}
// Removes withdrawn paths.
diff --git a/table/destination_test.go b/table/destination_test.go
index 7cace89e..7bcf6599 100644
--- a/table/destination_test.go
+++ b/table/destination_test.go
@@ -438,17 +438,17 @@ func TestMultipath(t *testing.T) {
d.AddNewPath(path1)
d.AddNewPath(path2)
- best, w, multi := d.Calculate([]string{GLOBAL_RIB_NAME})
+ best, old, multi := d.Calculate([]string{GLOBAL_RIB_NAME})
assert.Equal(t, len(best), 1)
- assert.Equal(t, len(w), 0)
+ assert.Equal(t, old[GLOBAL_RIB_NAME], (*Path)(nil))
assert.Equal(t, len(multi), 2)
assert.Equal(t, len(d.GetKnownPathList(GLOBAL_RIB_NAME)), 2)
path3 := path2.Clone(true)
d.AddWithdraw(path3)
- best, w, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
+ best, old, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
assert.Equal(t, len(best), 1)
- assert.Equal(t, len(w), 1)
+ assert.Equal(t, old[GLOBAL_RIB_NAME], path1)
assert.Equal(t, len(multi), 1)
assert.Equal(t, len(d.GetKnownPathList(GLOBAL_RIB_NAME)), 1)
@@ -465,9 +465,8 @@ func TestMultipath(t *testing.T) {
path4 := ProcessMessage(updateMsg, peer3, time.Now())[0]
d.AddNewPath(path4)
- best, w, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
+ best, _, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
assert.Equal(t, len(best), 1)
- assert.Equal(t, len(w), 0)
assert.Equal(t, len(multi), 1)
assert.Equal(t, len(d.GetKnownPathList(GLOBAL_RIB_NAME)), 2)
@@ -482,9 +481,8 @@ func TestMultipath(t *testing.T) {
path5 := ProcessMessage(updateMsg, peer2, time.Now())[0]
d.AddNewPath(path5)
- best, w, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
+ best, _, multi = d.Calculate([]string{GLOBAL_RIB_NAME})
assert.Equal(t, len(best), 1)
- assert.Equal(t, len(w), 0)
assert.Equal(t, len(multi), 2)
assert.Equal(t, len(d.GetKnownPathList(GLOBAL_RIB_NAME)), 3)
diff --git a/table/table_manager.go b/table/table_manager.go
index 4b52e745..ae00d3ce 100644
--- a/table/table_manager.go
+++ b/table/table_manager.go
@@ -185,9 +185,9 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) {
return msgs, nil
}
-func (manager *TableManager) calculate(ids []string, destinations []*Destination) (map[string][]*Path, []*Path, [][]*Path) {
- withdrawn := make([]*Path, 0, len(destinations))
+func (manager *TableManager) calculate(ids []string, destinations []*Destination) (map[string][]*Path, map[string][]*Path, [][]*Path) {
best := make(map[string][]*Path, len(ids))
+ old := make(map[string][]*Path, len(ids))
emptyDsts := make([]*Destination, 0, len(destinations))
var multi [][]*Path
@@ -200,11 +200,11 @@ func (manager *TableManager) calculate(ids []string, destinations []*Destination
"Topic": "table",
"Key": dst.GetNlri().String(),
}).Debug("Processing destination")
- paths, w, m := dst.Calculate(ids)
+ paths, olds, m := dst.Calculate(ids)
for id, path := range paths {
best[id] = append(best[id], path)
+ old[id] = append(old[id], olds[id])
}
- withdrawn = append(withdrawn, w...)
if m != nil {
multi = append(multi, m)
}
@@ -218,10 +218,10 @@ func (manager *TableManager) calculate(ids []string, destinations []*Destination
t := manager.Tables[dst.Family()]
t.deleteDest(dst)
}
- return best, withdrawn, multi
+ return best, old, multi
}
-func (manager *TableManager) DeletePathsByPeer(ids []string, info *PeerInfo, rf bgp.RouteFamily) (map[string][]*Path, []*Path, [][]*Path) {
+func (manager *TableManager) DeletePathsByPeer(ids []string, info *PeerInfo, rf bgp.RouteFamily) (map[string][]*Path, map[string][]*Path, [][]*Path) {
if t, ok := manager.Tables[rf]; ok {
dsts := t.DeleteDestByPeer(info)
return manager.calculate(ids, dsts)
@@ -229,7 +229,7 @@ func (manager *TableManager) DeletePathsByPeer(ids []string, info *PeerInfo, rf
return nil, nil, nil
}
-func (manager *TableManager) ProcessPaths(ids []string, pathList []*Path) (map[string][]*Path, []*Path, [][]*Path) {
+func (manager *TableManager) ProcessPaths(ids []string, pathList []*Path) (map[string][]*Path, map[string][]*Path, [][]*Path) {
m := make(map[string]bool, len(pathList))
dsts := make([]*Destination, 0, len(pathList))
for _, path := range pathList {