diff options
author | Marcus Wichelmann <mail@marcusw.de> | 2021-02-20 21:25:39 +0100 |
---|---|---|
committer | Marcus Wichelmann <mail@marcusw.de> | 2021-03-29 20:53:53 +0200 |
commit | 3c437e5aecab18454c5d70fd35272060bc3c95cf (patch) | |
tree | 489423ce9d54a5502fe58c6db1072c003c3efb05 | |
parent | 76f40ede0d466dfc7b1151d4e36b619a0daae51e (diff) |
Added ListDynamicNeighbor message to API
-rw-r--r-- | api/attribute.pb.go | 2 | ||||
-rw-r--r-- | api/gobgp.proto | 5 | ||||
-rw-r--r-- | pkg/server/grpc_server.go | 16 | ||||
-rw-r--r-- | pkg/server/server.go | 31 |
4 files changed, 54 insertions, 0 deletions
diff --git a/api/attribute.pb.go b/api/attribute.pb.go index efa63584..3113bce6 100644 --- a/api/attribute.pb.go +++ b/api/attribute.pb.go @@ -161,6 +161,8 @@ It has these top-level messages: ListPeerGroupResponse AddDynamicNeighborRequest DeleteDynamicNeighborRequest + ListDynamicNeighborRequest + ListDynamicNeighborResponse AddPathRequest AddPathResponse DeletePathRequest diff --git a/api/gobgp.proto b/api/gobgp.proto index 99dc6b4d..7757bcc6 100644 --- a/api/gobgp.proto +++ b/api/gobgp.proto @@ -50,6 +50,7 @@ service GobgpApi { rpc UpdatePeerGroup(UpdatePeerGroupRequest) returns(UpdatePeerGroupResponse); rpc AddDynamicNeighbor(AddDynamicNeighborRequest) returns(google.protobuf.Empty); + rpc ListDynamicNeighbor(ListDynamicNeighborRequest) returns(stream ListDynamicNeighborResponse); rpc DeleteDynamicNeighbor(DeleteDynamicNeighborRequest) returns(google.protobuf.Empty); rpc AddPath(AddPathRequest) returns(AddPathResponse); @@ -191,6 +192,10 @@ message DeleteDynamicNeighborRequest { string peer_group = 2; } +message ListDynamicNeighborRequest { string peer_group = 1; } + +message ListDynamicNeighborResponse { DynamicNeighbor dynamic_neighbor = 1; } + message AddPathRequest { TableType table_type = 1; string vrf_id = 2; diff --git a/pkg/server/grpc_server.go b/pkg/server/grpc_server.go index 1ae58055..b0cae8d3 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) ListDynamicNeighbor(r *api.ListDynamicNeighborRequest, stream api.GobgpApi_ListDynamicNeighborServer) error { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + fn := func(dn *api.DynamicNeighbor) { + if err := stream.Send(&api.ListDynamicNeighborResponse{DynamicNeighbor: dn}); err != nil { + cancel() + return + } + } + return s.bgpServer.ListDynamicNeighbor(ctx, r, fn) +} + func (s *server) ListPeerGroup(r *api.ListPeerGroupRequest, stream api.GobgpApi_ListPeerGroupServer) error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() @@ -861,6 +873,10 @@ func (s *server) AddDynamicNeighbor(ctx context.Context, r *api.AddDynamicNeighb return &empty.Empty{}, s.bgpServer.AddDynamicNeighbor(ctx, r) } +func (s *server) DeleteDynamicNeighbor(ctx context.Context, r *api.DeleteDynamicNeighborRequest) (*empty.Empty, error) { + return &empty.Empty{}, s.bgpServer.DeleteDynamicNeighbor(ctx, r) +} + func newPrefixFromApiStruct(a *api.Prefix) (*table.Prefix, error) { _, prefix, err := net.ParseCIDR(a.IpPrefix) if err != nil { diff --git a/pkg/server/server.go b/pkg/server/server.go index 090d97b8..84a1e2da 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -2715,6 +2715,37 @@ func (s *BgpServer) GetBgp(ctx context.Context, r *api.GetBgpRequest) (*api.GetB return rsp, nil } +func (s *BgpServer) ListDynamicNeighbor(ctx context.Context, r *api.ListDynamicNeighborRequest, fn func(neighbor *api.DynamicNeighbor)) error { + toApi := func(dn *config.DynamicNeighbor) *api.DynamicNeighbor { + return &api.DynamicNeighbor{ + Prefix: dn.Config.Prefix, + PeerGroup: dn.Config.PeerGroup, + } + } + var l []*api.DynamicNeighbor + s.mgmtOperation(func() error { + peerGroupName := r.PeerGroup + for k, group := range s.peerGroupMap { + if peerGroupName != "" && peerGroupName != k { + continue + } + for _, dn := range group.dynamicNeighbors { + l = append(l, toApi(dn)) + } + } + return nil + }, false) + for _, dn := range l { + select { + case <-ctx.Done(): + return nil + default: + fn(dn) + } + } + return nil +} + func (s *BgpServer) ListPeerGroup(ctx context.Context, r *api.ListPeerGroupRequest, fn func(*api.PeerGroup)) error { var l []*api.PeerGroup s.mgmtOperation(func() error { |