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/grpc_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/grpc_server.go')
-rw-r--r-- | server/grpc_server.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index b14845b2..aa36a264 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -48,6 +48,7 @@ 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 @@ -205,6 +206,37 @@ func (s *Server) GetRib(arg *api.Arguments, stream api.Grpc_GetRibServer) error return nil } +func (s *Server) MonitorBestChanged(arg *api.Arguments, stream api.Grpc_MonitorBestChangedServer) error { + var reqType int + switch arg.Resource { + case api.Resource_GLOBAL: + reqType = REQ_GLOBAL_MONITOR_BEST_CHANGED + default: + return fmt.Errorf("unsupported resource type: %v", arg.Resource) + } + + rf, err := convertAf2Rf(arg.Af) + if err != nil { + return err + } + + req := NewGrpcRequest(reqType, "", rf, nil) + s.bgpServerCh <- req + + for res := range req.ResponseCh { + if err = res.Err(); err != nil { + log.Debug(err.Error()) + goto END + } + if err = stream.Send(res.Data.(*api.Path)); 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 { @@ -512,6 +544,7 @@ type GrpcRequest struct { RemoteAddr string RouteFamily bgp.RouteFamily ResponseCh chan *GrpcResponse + EndCh chan struct{} Err error Data interface{} } @@ -522,6 +555,7 @@ func NewGrpcRequest(reqType int, remoteAddr string, rf bgp.RouteFamily, d interf RouteFamily: rf, RemoteAddr: remoteAddr, ResponseCh: make(chan *GrpcResponse), + EndCh: make(chan struct{}), Data: d, } return r |