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/destination.go | |
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/destination.go')
-rw-r--r-- | table/destination.go | 62 |
1 files changed, 32 insertions, 30 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. |