diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-08 10:44:02 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2018-11-08 10:44:02 +0900 |
commit | b48c5613dd62f99854bfa2d87b62838b4b0d14b7 (patch) | |
tree | 266f5d4b226b83193fb51f05ecea2378e6aa5ef1 /pkg/server/grpc_server.go | |
parent | d4e04188ce7a406642b1dadd038b98a4e02627f1 (diff) |
server: Add PeerTable API
go native API that corresponds to MonitorTable gRPC API.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'pkg/server/grpc_server.go')
-rw-r--r-- | pkg/server/grpc_server.go | 60 |
1 files changed, 8 insertions, 52 deletions
diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index b8a1f9e8..2b4fe02b 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -171,62 +171,18 @@ func (s *Server) ListPath(r *api.ListPathRequest, stream api.GobgpApi_ListPathSe } func (s *Server) MonitorTable(arg *api.MonitorTableRequest, stream api.GobgpApi_MonitorTableServer) error { - if arg == nil { - return fmt.Errorf("invalid request") - } - w, err := func() (*watcher, error) { - switch arg.Type { - case api.Resource_GLOBAL: - return s.bgpServer.watch(watchBestPath(arg.Current)), nil - case api.Resource_ADJ_IN: - if arg.PostPolicy { - return s.bgpServer.watch(watchPostUpdate(arg.Current)), nil - } - return s.bgpServer.watch(watchUpdate(arg.Current)), nil - default: - return nil, fmt.Errorf("unsupported resource type: %v", arg.Type) - } - }() + tm, err := s.bgpServer.NewTableMonitor(arg) if err != nil { - return nil + return err } - return func() error { - defer func() { w.Stop() }() + defer tm.Close() - sendPath := func(pathList []*table.Path) error { - for _, path := range pathList { - f := bgp.AfiSafiToRouteFamily(uint16(arg.Family.Afi), uint8(arg.Family.Safi)) - if path == nil || (arg.Family != nil && f != path.GetRouteFamily()) { - continue - } - if err := stream.Send(&api.MonitorTableResponse{Path: toPathApi(path, nil)}); err != nil { - return err - } - } - return nil - } - - for ev := range w.Event() { - switch msg := ev.(type) { - case *watchEventBestPath: - if err := sendPath(func() []*table.Path { - if len(msg.MultiPathList) > 0 { - l := make([]*table.Path, 0) - for _, p := range msg.MultiPathList { - l = append(l, p...) - } - return l - } else { - return msg.PathList - } - }()); err != nil { - return err - } - case *watchEventUpdate: - if err := sendPath(msg.PathList); err != nil { - return err - } + for v := range tm.Inbox { + if err := stream.Send(&api.MonitorTableResponse{ + Path: v, + }); err != nil { + return err } } return nil |