From c1e7463e361632de60337cfd52dc44eb453d9746 Mon Sep 17 00:00:00 2001 From: Marcus Wichelmann Date: Sun, 14 Feb 2021 22:23:54 +0100 Subject: Added ListPeerGroup message to API --- pkg/server/grpc_server.go | 12 ++++++++++++ pkg/server/server.go | 25 +++++++++++++++++++++++++ 2 files changed, 37 insertions(+) (limited to 'pkg/server') diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 2d25734a..1ae58055 100644 --- a/pkg/server/grpc_server.go +++ b/pkg/server/grpc_server.go @@ -102,6 +102,18 @@ func (s *server) serve() error { return nil } +func (s *server) ListPeerGroup(r *api.ListPeerGroupRequest, stream api.GobgpApi_ListPeerGroupServer) error { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + fn := func(pg *api.PeerGroup) { + if err := stream.Send(&api.ListPeerGroupResponse{PeerGroup: pg}); err != nil { + cancel() + return + } + } + return s.bgpServer.ListPeerGroup(ctx, r, fn) +} + func parseHost(host string) (string, string) { const unixScheme = "unix://" if strings.HasPrefix(host, unixScheme) { diff --git a/pkg/server/server.go b/pkg/server/server.go index c5b2b0ff..25fd31cc 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2715,6 +2715,31 @@ func (s *BgpServer) GetBgp(ctx context.Context, r *api.GetBgpRequest) (*api.GetB return rsp, nil } +func (s *BgpServer) ListPeerGroup(ctx context.Context, r *api.ListPeerGroupRequest, fn func(*api.PeerGroup)) error { + var l []*api.PeerGroup + s.mgmtOperation(func() error { + peerGroupName := r.PeerGroupName + l = make([]*api.PeerGroup, 0, len(s.peerGroupMap)) + for k, group := range s.peerGroupMap { + if peerGroupName != "" && peerGroupName != k { + continue + } + pg := config.NewPeerGroupFromConfigStruct(group.Conf) + l = append(l, pg) + } + return nil + }, false) + for _, pg := range l { + select { + case <-ctx.Done(): + return nil + default: + fn(pg) + } + } + return nil +} + func (s *BgpServer) ListPeer(ctx context.Context, r *api.ListPeerRequest, fn func(*api.Peer)) error { var l []*api.Peer s.mgmtOperation(func() error { -- cgit v1.2.3