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 /server/server.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 'server/server.go')
-rw-r--r-- | server/server.go | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/server/server.go b/server/server.go index ef10f1f6..336a2b0e 100644 --- a/server/server.go +++ b/server/server.go @@ -428,7 +428,7 @@ func (server *BgpServer) Serve() { } moded := server.RSimportPaths(peer, pathList) if len(moded) > 0 { - server.globalRib.ProcessPaths(moded) + server.globalRib.ProcessPaths(nil, moded) } } server.neighborMap[addr] = peer @@ -588,9 +588,21 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer, families []bgp.RouteFamil msgs := make([]*SenderMsg, 0) options := &table.PolicyOptions{} + ids := make([]string, 0, len(server.neighborMap)) + if peer.isRouteServerClient() { + for _, targetPeer := range server.neighborMap { + if !targetPeer.isRouteServerClient() || targetPeer == peer || targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED { + continue + } + ids = append(ids, targetPeer.TableID()) + } + } else { + ids = append(ids, table.GLOBAL_RIB_NAME) + } for _, rf := range families { - dsts, withdrawn := server.globalRib.DeletePathsByPeer(peer.fsm.peerInfo, rf) + best, withdrawn := server.globalRib.DeletePathsByPeer(ids, peer.fsm.peerInfo, rf) server.validatePaths(nil, withdrawn, true) + if peer.isRouteServerClient() { for _, targetPeer := range server.neighborMap { if !targetPeer.isRouteServerClient() || targetPeer == peer || targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED { @@ -599,10 +611,10 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer, families []bgp.RouteFamil if _, ok := targetPeer.fsm.rfMap[rf]; !ok { continue } - pathList := make([]*table.Path, 0, len(dsts)) + pathList := make([]*table.Path, 0, len(best[targetPeer.TableID()])) options.Neighbor = targetPeer.fsm.peerInfo.Address - for _, dst := range dsts { - if path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, dst.NewFeed(targetPeer.TableID())), options); path != nil { + for _, bestPath := range best[targetPeer.TableID()] { + if path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, bestPath), options); path != nil { pathList = append(pathList, path) } } @@ -611,9 +623,8 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer, families []bgp.RouteFamil targetPeer.adjRibOut.Update(pathList) } } else { - sendPathList := make([]*table.Path, 0, len(dsts)) - for _, dst := range dsts { - path := dst.NewFeed(table.GLOBAL_RIB_NAME) + sendPathList := make([]*table.Path, 0, len(best[table.GLOBAL_RIB_NAME])) + for _, path := range best[table.GLOBAL_RIB_NAME] { if path != nil { sendPathList = append(sendPathList, path) } @@ -874,16 +885,30 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) ([] } moded = append(moded, server.RSimportPaths(targetPeer, pathList)...) } - dsts, newly, withdrawn := rib.ProcessPaths(append(pathList, moded...)) + isTarget := func(p *Peer) bool { + if !p.isRouteServerClient() || p.fsm.state != bgp.BGP_FSM_ESTABLISHED || p.fsm.pConf.GracefulRestart.State.LocalRestarting { + return false + } + return true + } + + ids := make([]string, 0, len(server.neighborMap)) + for _, targetPeer := range server.neighborMap { + if isTarget(targetPeer) { + ids = append(ids, targetPeer.TableID()) + } + } + best, newly, withdrawn := rib.ProcessPaths(ids, append(pathList, moded...)) server.validatePaths(newly, withdrawn, false) + for _, targetPeer := range server.neighborMap { - if !targetPeer.isRouteServerClient() || targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED || targetPeer.fsm.pConf.GracefulRestart.State.LocalRestarting { + if !isTarget(targetPeer) { continue } - sendPathList := make([]*table.Path, 0, len(dsts)) + sendPathList := make([]*table.Path, 0, len(best[targetPeer.TableID()])) options.Neighbor = targetPeer.fsm.peerInfo.Address - for _, dst := range dsts { - path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, dst.NewFeed(targetPeer.TableID())), options) + for _, bestPath := range best[targetPeer.TableID()] { + path := server.policy.ApplyPolicy(targetPeer.TableID(), table.POLICY_DIRECTION_EXPORT, filterpath(targetPeer, bestPath), options) if path != nil { sendPathList = append(sendPathList, path) } @@ -897,14 +922,13 @@ func (server *BgpServer) propagateUpdate(peer *Peer, pathList []*table.Path) ([] pathList[idx] = server.policy.ApplyPolicy(table.GLOBAL_RIB_NAME, table.POLICY_DIRECTION_IMPORT, path, nil) } alteredPathList = pathList - dsts, newly, withdrawn := rib.ProcessPaths(pathList) + best, newly, withdrawn := rib.ProcessPaths([]string{table.GLOBAL_RIB_NAME}, pathList) server.validatePaths(newly, withdrawn, false) - sendPathList := make([]*table.Path, 0, len(dsts)) + sendPathList := make([]*table.Path, 0, len(best[table.GLOBAL_RIB_NAME])) if server.bgpConfig.Global.Collector.Enabled { sendPathList = pathList } else { - for _, dst := range dsts { - path := dst.NewFeed(table.GLOBAL_RIB_NAME) + for _, path := range best[table.GLOBAL_RIB_NAME] { if path != nil { sendPathList = append(sendPathList, path) } @@ -2400,7 +2424,7 @@ func (server *BgpServer) handleGrpcModNeighbor(grpcReq *GrpcRequest) (sMsgs []*S } moded := server.RSimportPaths(peer, pathList) if len(moded) > 0 { - server.globalRib.ProcessPaths(moded) + server.globalRib.ProcessPaths(nil, moded) } } server.neighborMap[addr] = peer |