diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-21 10:10:17 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-10-21 10:10:17 +0900 |
commit | 0e64f7c080fafb61dd97023bb25e0c59b53b7556 (patch) | |
tree | a473434c09fefa27cd9c4a80018841cd3afcc4f1 | |
parent | a1a86cd2127cd30c7781563ac8e00257f1214779 (diff) |
server: remove peer's getBests method
Use TableManager's getBestPathList
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/peer.go | 12 | ||||
-rw-r--r-- | server/server.go | 2 | ||||
-rw-r--r-- | table/table_manager.go | 27 |
3 files changed, 21 insertions, 20 deletions
diff --git a/server/peer.go b/server/peer.go index ea1d8098..55240cf6 100644 --- a/server/peer.go +++ b/server/peer.go @@ -124,7 +124,7 @@ func (peer *Peer) getAccepted(rfList []bgp.RouteFamily) []*table.Path { } func (peer *Peer) getBestFromLocal() ([]*table.Path, []*table.Path) { - pathList, filtered := peer.ApplyPolicy(table.POLICY_DIRECTION_EXPORT, filterpath(peer, peer.getBests(peer.localRib))) + pathList, filtered := peer.ApplyPolicy(table.POLICY_DIRECTION_EXPORT, filterpath(peer, peer.localRib.GetBestPathList(peer.localRib.GetRFlist()))) if peer.isRouteServerClient() == false { for _, path := range pathList { path.UpdatePathAttrs(&peer.gConf, &peer.conf) @@ -249,16 +249,6 @@ func (peer *Peer) handleBGPmessage(m *bgp.BGPMessage) ([]*table.Path, bool, []*b return pathList, update, bgpMsgList } -func (peer *Peer) getBests(rib *table.TableManager) []*table.Path { - pathList := []*table.Path{} - for _, rf := range peer.configuredRFlist() { - for _, paths := range rib.GetBestPathList(rf) { - pathList = append(pathList, paths) - } - } - return pathList -} - func (peer *Peer) startFSMHandler(incoming chan *fsmMsg) { peer.fsm.h = NewFSMHandler(peer.fsm, incoming, peer.outgoing) } diff --git a/server/server.go b/server/server.go index 417d09d7..5f6ec58a 100644 --- a/server/server.go +++ b/server/server.go @@ -1124,7 +1124,7 @@ func (server *BgpServer) handleModPathRequest(grpcReq *GrpcRequest) []*table.Pat macIpAdv := evpnNlri.RouteTypeData.(*bgp.EVPNMacIPAdvertisementRoute) etag := macIpAdv.ETag mac := macIpAdv.MacAddress - paths := server.globalRib.GetBestPathList(bgp.RF_EVPN) + paths := server.globalRib.GetBestPathList([]bgp.RouteFamily{bgp.RF_EVPN}) if m := getMacMobilityExtendedCommunity(etag, mac, paths); m != nil { extcomms = append(extcomms, m) } diff --git a/table/table_manager.go b/table/table_manager.go index f52f1ae9..4cb196a1 100644 --- a/table/table_manager.go +++ b/table/table_manager.go @@ -456,6 +456,16 @@ func (manager *TableManager) handleMacMobility(path *Path) []*Destination { return dsts } +func (manager *TableManager) getDestinationCount(rfList []bgp.RouteFamily) int { + count := 0 + for _, rf := range rfList { + if _, ok := manager.Tables[rf]; ok { + count += len(manager.Tables[rf].GetDestinations()) + } + } + return count +} + func (manager *TableManager) GetPathList(rf bgp.RouteFamily) []*Path { if _, ok := manager.Tables[rf]; !ok { return []*Path{} @@ -468,14 +478,15 @@ func (manager *TableManager) GetPathList(rf bgp.RouteFamily) []*Path { return paths } -func (manager *TableManager) GetBestPathList(rf bgp.RouteFamily) []*Path { - if _, ok := manager.Tables[rf]; !ok { - return []*Path{} - } - destinations := manager.Tables[rf].GetDestinations() - paths := make([]*Path, 0, len(destinations)) - for _, dest := range destinations { - paths = append(paths, dest.GetBestPath()) +func (manager *TableManager) GetBestPathList(rfList []bgp.RouteFamily) []*Path { + paths := make([]*Path, 0, manager.getDestinationCount(rfList)) + for _, rf := range rfList { + if _, ok := manager.Tables[rf]; ok { + destinations := manager.Tables[rf].GetDestinations() + for _, dest := range destinations { + paths = append(paths, dest.GetBestPath()) + } + } } return paths } |