diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-06 12:40:17 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-01-06 12:40:17 +0900 |
commit | 302632715c1dded7af7038d448ac66aeb5f44b49 (patch) | |
tree | 2bb06a4e4a0464eb21ddf69b2b1f2de536573652 /server/server.go | |
parent | 784578ec55d90492b16d6fe45197e5a74c40790d (diff) |
rpki: add monitor command support
monitor the change of rpki validation results:
$ gobgp monitor rpki
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 40 |
1 files changed, 38 insertions, 2 deletions
diff --git a/server/server.go b/server/server.go index 00f047ad..c18284dd 100644 --- a/server/server.go +++ b/server/server.go @@ -613,6 +613,33 @@ func (server *BgpServer) dropPeerAllRoutes(peer *Peer) []*SenderMsg { return msgs } +func (server *BgpServer) broadcastValidationResults(results []*api.ROAResult) { + for _, result := range results { + remainReqs := make([]*GrpcRequest, 0, len(server.broadcastReqs)) + for _, req := range server.broadcastReqs { + select { + case <-req.EndCh: + continue + default: + } + if req.RequestType != REQ_MONITOR_ROA_VALIDATION_RESULT { + remainReqs = append(remainReqs, req) + continue + } + m := &broadcastGrpcMsg{ + req: req, + result: &GrpcResponse{ + Data: result, + }, + } + server.broadcastMsgs = append(server.broadcastMsgs, m) + + remainReqs = append(remainReqs, req) + } + server.broadcastReqs = remainReqs + } +} + func (server *BgpServer) broadcastBests(bests []*table.Path) { for _, path := range bests { if !path.IsFromZebra { @@ -901,7 +928,16 @@ func (server *BgpServer) handleFSMMessage(peer *Peer, e *FsmMsg) []*SenderMsg { msgs = append(msgs, newSenderMsg(peer, msgList)) } if len(pathList) > 0 { - server.roaManager.validate(pathList) + isMonitor := func() bool { + if len(server.broadcastReqs) > 0 { + return true + } + return false + }() + vResults := server.roaManager.validate(pathList, isMonitor) + if isMonitor { + server.broadcastValidationResults(vResults) + } m, altered := server.propagateUpdate(peer, pathList) msgs = append(msgs, m...) @@ -1893,7 +1929,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { ResponseErr: err, } close(grpcReq.ResponseCh) - case REQ_MONITOR_GLOBAL_BEST_CHANGED, REQ_MONITOR_NEIGHBOR_PEER_STATE: + case REQ_MONITOR_GLOBAL_BEST_CHANGED, REQ_MONITOR_NEIGHBOR_PEER_STATE, REQ_MONITOR_ROA_VALIDATION_RESULT: server.broadcastReqs = append(server.broadcastReqs, grpcReq) case REQ_MRT_GLOBAL_RIB, REQ_MRT_LOCAL_RIB: server.handleMrt(grpcReq) |