diff options
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. |