diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-10 20:12:25 -0800 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-03-14 00:44:15 +0900 |
commit | 2ef757bc5f71d4131910d0973ffd7026cca73f9f (patch) | |
tree | 004801d58a78bcef11892bb144bff870ead7c291 /table | |
parent | 7d68855c86daa8fa8202f5cbdf585d9d8c1d3d21 (diff) |
table: remove Destination's oldKnownPathList
Withdrawn pathes are kept to be referenced thus the memory for them
are not freed. Kill oldKnownPathList and Destination's NewFeed().
Destination's Calculate() returns the best paths.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r-- | table/destination.go | 62 | ||||
-rw-r--r-- | table/table_manager.go | 22 | ||||
-rw-r--r-- | table/table_manager_test.go | 5 |
3 files changed, 47 insertions, 42 deletions
diff --git a/table/destination.go b/table/destination.go index 31072561..8f9676b1 100644 --- a/table/destination.go +++ b/table/destination.go @@ -111,13 +111,12 @@ func NewPeerInfo(g *config.Global, p *config.Neighbor) *PeerInfo { } type Destination struct { - routeFamily bgp.RouteFamily - nlri bgp.AddrPrefixInterface - oldKnownPathList paths - knownPathList paths - withdrawList paths - newPathList paths - RadixKey string + routeFamily bgp.RouteFamily + nlri bgp.AddrPrefixInterface + knownPathList paths + withdrawList paths + newPathList paths + RadixKey string } func NewDestination(nlri bgp.AddrPrefixInterface) *Destination { @@ -201,15 +200,6 @@ func (dd *Destination) GetBestPath(id string) *Path { return nil } -func (dd *Destination) oldBest(id string) *Path { - for _, p := range dd.oldKnownPathList { - if p.Filtered(id) == POLICY_DIRECTION_NONE { - return p - } - } - return nil -} - func (dd *Destination) addWithdraw(withdraw *Path) { dd.validatePath(withdraw) dd.withdrawList = append(dd.withdrawList, withdraw) @@ -236,8 +226,9 @@ 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() ([]*Path, []*Path) { - dest.oldKnownPathList = dest.knownPathList +func (dest *Destination) Calculate(ids []string) (map[string]*Path, []*Path, []*Path) { + best := make(map[string]*Path, len(ids)) + oldKnownPathList := dest.knownPathList updated := dest.newPathList // First remove the withdrawn paths. withdrawnList := dest.explicitWithdraw() @@ -249,22 +240,33 @@ func (dest *Destination) Calculate() ([]*Path, []*Path) { dest.newPathList = make([]*Path, 0) // Compute new best path dest.computeKnownBestPath() - return updated, withdrawnList -} -func (dest *Destination) NewFeed(id string) *Path { - old := dest.oldBest(id) - best := dest.GetBestPath(id) - if best != nil && best.Equal(old) { - return nil - } - if best == nil { - if old == nil { + f := func(id string) *Path { + old := func() *Path { + for _, p := range oldKnownPathList { + if p.Filtered(id) == POLICY_DIRECTION_NONE { + return p + } + } + return nil + }() + best := dest.GetBestPath(id) + if best != nil && best.Equal(old) { return nil } - return old.Clone(true) + if best == nil { + if old == nil { + return nil + } + return old.Clone(true) + } + return best + } + + for _, id := range ids { + best[id] = f(id) } - return best + return best, updated, withdrawnList } // Removes withdrawn paths. diff --git a/table/table_manager.go b/table/table_manager.go index f908bd69..8eeff459 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -216,32 +216,37 @@ func (manager *TableManager) DeleteVrf(name string) ([]*Path, error) { return msgs, nil } -func (manager *TableManager) calculate(destinations []*Destination) ([]*Path, []*Path) { +func (manager *TableManager) calculate(ids []string, destinations []*Destination) (map[string][]*Path, []*Path, []*Path) { newly := make([]*Path, 0, len(destinations)) withdrawn := make([]*Path, 0, len(destinations)) + best := make(map[string][]*Path, len(ids)) + for _, destination := range destinations { log.WithFields(log.Fields{ "Topic": "table", "Key": destination.GetNlri().String(), }).Debug("Processing destination") - n, w := destination.Calculate() + paths, n, w := destination.Calculate(ids) + for id, path := range paths { + best[id] = append(best[id], path) + } newly = append(newly, n...) withdrawn = append(withdrawn, w...) } - return newly, withdrawn + return best, newly, withdrawn } -func (manager *TableManager) DeletePathsByPeer(info *PeerInfo, rf bgp.RouteFamily) ([]*Destination, []*Path) { +func (manager *TableManager) DeletePathsByPeer(ids []string, info *PeerInfo, rf bgp.RouteFamily) (map[string][]*Path, []*Path) { if t, ok := manager.Tables[rf]; ok { dsts := t.DeleteDestByPeer(info) // no newly added paths - _, withdrawn := manager.calculate(dsts) - return dsts, withdrawn + best, _, withdrawn := manager.calculate(ids, dsts) + return best, withdrawn } return nil, nil } -func (manager *TableManager) ProcessPaths(pathList []*Path) ([]*Destination, []*Path, []*Path) { +func (manager *TableManager) ProcessPaths(ids []string, pathList []*Path) (map[string][]*Path, []*Path, []*Path) { m := make(map[string]bool, len(pathList)) dsts := make([]*Destination, 0, len(pathList)) for _, path := range pathList { @@ -267,8 +272,7 @@ func (manager *TableManager) ProcessPaths(pathList []*Path) ([]*Destination, []* } } } - newly, withdrawn := manager.calculate(dsts) - return dsts, newly, withdrawn + return manager.calculate(ids, dsts) } // EVPN MAC MOBILITY HANDLING diff --git a/table/table_manager_test.go b/table/table_manager_test.go index becf69a1..4732d3a3 100644 --- a/table/table_manager_test.go +++ b/table/table_manager_test.go @@ -30,10 +30,9 @@ 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) + best, _, _ := manager.ProcessPaths([]string{GLOBAL_RIB_NAME}, paths) paths2 := make([]*Path, 0, len(paths)) - for _, dst := range dsts { - p := dst.NewFeed(GLOBAL_RIB_NAME) + for _, p := range best[GLOBAL_RIB_NAME] { if p != nil { paths2 = append(paths2, p) } |