From 40f82a62ed9fe381fdcca71fbd77283a8077c1c5 Mon Sep 17 00:00:00 2001 From: ISHIDA Wataru Date: Tue, 23 Jun 2015 17:15:56 +0900 Subject: server/api: add api to monitor changes of neighbor state Signed-off-by: ISHIDA Wataru --- server/grpc_server.go | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'server/grpc_server.go') diff --git a/server/grpc_server.go b/server/grpc_server.go index aa36a264..12a3a87a 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -48,7 +48,6 @@ const ( REQ_GLOBAL_RIB REQ_GLOBAL_ADD REQ_GLOBAL_DELETE - REQ_GLOBAL_MONITOR_BEST_CHANGED REQ_POLICY_PREFIX REQ_POLICY_PREFIXES REQ_POLICY_PREFIX_ADD @@ -74,6 +73,8 @@ const ( REQ_POLICY_COMMUNITY_ADD REQ_POLICY_COMMUNITY_DELETE REQ_POLICY_COMMUNITIES_DELETE + REQ_MONITOR_GLOBAL_BEST_CHANGED + REQ_MONITOR_NEIGHBOR_PEER_STATE ) const GRPC_PORT = 8080 @@ -210,7 +211,7 @@ func (s *Server) MonitorBestChanged(arg *api.Arguments, stream api.Grpc_MonitorB var reqType int switch arg.Resource { case api.Resource_GLOBAL: - reqType = REQ_GLOBAL_MONITOR_BEST_CHANGED + reqType = REQ_MONITOR_GLOBAL_BEST_CHANGED default: return fmt.Errorf("unsupported resource type: %v", arg.Resource) } @@ -237,6 +238,27 @@ END: return err } +func (s *Server) MonitorPeerState(arg *api.Arguments, stream api.Grpc_MonitorPeerStateServer) error { + var rf bgp.RouteFamily + req := NewGrpcRequest(REQ_MONITOR_NEIGHBOR_PEER_STATE, arg.RouterId, rf, nil) + s.bgpServerCh <- req + + var err error + + for res := range req.ResponseCh { + if err = res.Err(); err != nil { + log.Debug(err.Error()) + goto END + } + if err = stream.Send(res.Data.(*api.Peer)); err != nil { + goto END + } + } +END: + req.EndCh <- struct{}{} + return err +} + func (s *Server) neighbor(reqType int, arg *api.Arguments) (*api.Error, error) { rf, err := convertAf2Rf(arg.Af) if err != nil { @@ -555,7 +577,7 @@ func NewGrpcRequest(reqType int, remoteAddr string, rf bgp.RouteFamily, d interf RouteFamily: rf, RemoteAddr: remoteAddr, ResponseCh: make(chan *GrpcResponse), - EndCh: make(chan struct{}), + EndCh: make(chan struct{}, 1), Data: d, } return r -- cgit v1.2.3