diff options
author | ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp> | 2015-06-12 12:51:10 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-06-25 22:26:06 +0900 |
commit | e17379e9d954dcd105bc39bcbaf011443815e8f2 (patch) | |
tree | 8e4c0b9b5ae92b30115494470c6b57fabfd19461 /server/server.go | |
parent | a7ee9eed9e5e8bc27a5328b993b775585e536e07 (diff) |
server/api: add api to monitor changes of best paths
Signed-off-by: ISHIDA Wataru <ishida.wataru@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/server/server.go b/server/server.go index 939c2f56..cc19ecc7 100644 --- a/server/server.go +++ b/server/server.go @@ -52,6 +52,7 @@ type BgpServer struct { policyUpdateCh chan config.RoutingPolicy policyMap map[string]*policy.Policy routingPolicy config.RoutingPolicy + broadcastReqs []*GrpcRequest neighborMap map[string]*Peer localRibMap map[string]*LocalRib @@ -354,6 +355,9 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { if len(pathList) == 0 { continue } + + server.broadcastBests(pathList) + msgList := table.CreateUpdateMsgFromPaths(pathList) for _, targetPeer := range server.neighborMap { if targetPeer.isRouteServerClient() || targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED { @@ -404,6 +408,24 @@ func applyPolicies(peer *Peer, loc *LocalRib, isExport bool, pathList []table.Pa return ret } +func (server *BgpServer) broadcastBests(bests []table.Path) { + for _, path := range bests { + result := &GrpcResponse{ + Data: path.ToApiStruct(), + } + remainReqs := make([]*GrpcRequest, 0, len(server.broadcastReqs)) + for _, req := range server.broadcastReqs { + select { + case <-req.EndCh: + continue + case req.ResponseCh <- result: + } + remainReqs = append(remainReqs, req) + } + server.broadcastReqs = remainReqs + } +} + func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClient bool, pathList []table.Path) []*SenderMsg { msgs := make([]*SenderMsg, 0) @@ -432,6 +454,8 @@ func (server *BgpServer) propagateUpdate(neighborAddress string, RouteServerClie return msgs } + server.broadcastBests(sendPathList) + for _, targetPeer := range server.neighborMap { if targetPeer.isRouteServerClient() || targetPeer.fsm.state != bgp.BGP_FSM_ESTABLISHED { continue @@ -790,6 +814,8 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { close(grpcReq.ResponseCh) } + case REQ_GLOBAL_MONITOR_BEST_CHANGED: + server.broadcastReqs = append(server.broadcastReqs, grpcReq) case REQ_NEIGHBORS: for _, peer := range server.neighborMap { result := &GrpcResponse{ |