diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-10 12:18:29 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-14 00:44:15 +0900 |
commit | 7d68855c86daa8fa8202f5cbdf585d9d8c1d3d21 (patch) | |
tree | 0bcc5384b45f7d5461c5a759413accda1b29b9de /table | |
parent | ce5917c0a8d6206fd1d70a5a476eb99e510fc9f6 (diff) |
table: remove Destination's WithdrawnList and UpdatedPathList used for validation
Withdrawn pathes are kept to be referenced thus the memory for them
are not freed. Nobody uses this so let's remove it.
Paths in UpdatedPathList are also in KnownPathList so doesn't lead to
memory leak. But remove it for simplicity.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 11 | ||||
-rw-r--r-- | table/table_manager.go | 24 | ||||
-rw-r--r-- | table/table_manager_test.go | 2 |
3 files changed, 20 insertions, 17 deletions
diff --git a/table/destination.go b/table/destination.go index f323a6d7..31072561 100644 --- a/table/destination.go +++ b/table/destination.go @@ -117,8 +117,6 @@ type Destination struct { knownPathList paths withdrawList paths newPathList paths - WithdrawnList paths - UpdatedPathList paths RadixKey string } @@ -236,15 +234,13 @@ func (dd *Destination) validatePath(path *Path) { // Calculates best-path among known paths for this destination. // -// Returns: - Best 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() { +func (dest *Destination) Calculate() ([]*Path, []*Path) { dest.oldKnownPathList = dest.knownPathList - dest.UpdatedPathList = dest.newPathList + updated := dest.newPathList // First remove the withdrawn paths. - dest.WithdrawnList = dest.explicitWithdraw() + withdrawnList := dest.explicitWithdraw() // Do implicit withdrawal dest.implicitWithdraw() // Collect all new paths into known paths. @@ -253,6 +249,7 @@ func (dest *Destination) Calculate() { dest.newPathList = make([]*Path, 0) // Compute new best path dest.computeKnownBestPath() + return updated, withdrawnList } func (dest *Destination) NewFeed(id string) *Path { diff --git a/table/table_manager.go b/table/table_manager.go index afb4deac..f908bd69 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -216,26 +216,32 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) { return msgs, nil } -func (manager *TableManager) calculate(destinations []*Destination) { +func (manager *TableManager) calculate(destinations []*Destination) ([]*Path, []*Path) { + newly := make([]*Path, 0, len(destinations)) + withdrawn := make([]*Path, 0, len(destinations)) for _, destination := range destinations { log.WithFields(log.Fields{ "Topic": "table", "Key": destination.GetNlri().String(), }).Debug("Processing destination") - destination.Calculate() + n, w := destination.Calculate() + newly = append(newly, n...) + withdrawn = append(withdrawn, w...) } + return newly, withdrawn } -func (manager *TableManager) DeletePathsByPeer(info *PeerInfo, rf bgp.RouteFamily) []*Destination { +func (manager *TableManager) DeletePathsByPeer(info *PeerInfo, rf bgp.RouteFamily) ([]*Destination, []*Path) { if t, ok := manager.Tables[rf]; ok { dsts := t.DeleteDestByPeer(info) - manager.calculate(dsts) - return dsts + // no newly added paths + _, withdrawn := manager.calculate(dsts) + return dsts, withdrawn } - return nil + return nil, nil } -func (manager *TableManager) ProcessPaths(pathList []*Path) []*Destination { +func (manager *TableManager) ProcessPaths(pathList []*Path) ([]*Destination, []*Path, []*Path) { m := make(map[string]bool, len(pathList)) dsts := make([]*Destination, 0, len(pathList)) for _, path := range pathList { @@ -261,8 +267,8 @@ func (manager *TableManager) ProcessPaths(pathList []*Path) []*Destination { } } } - manager.calculate(dsts) - return dsts + newly, withdrawn := manager.calculate(dsts) + return dsts, newly, withdrawn } // EVPN MAC MOBILITY HANDLING diff --git a/table/table_manager_test.go b/table/table_manager_test.go index 02d96299..becf69a1 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -30,7 +30,7 @@ import ( // this function processes only BGPUpdate func (manager *TableManager) ProcessUpdate(fromPeer *PeerInfo, message *bgp.BGPMessage) ([]*Path, error) { paths := ProcessMessage(message, fromPeer, time.Now()) - dsts := manager.ProcessPaths(paths) + dsts, _, _ := manager.ProcessPaths(paths) paths2 := make([]*Path, 0, len(paths)) for _, dst := range dsts { p := dst.NewFeed(GLOBAL_RIB_NAME) |