From 5966466632bd73676ec80ca71c5082f88cb65bd6 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 26 Jul 2016 16:01:20 +0900 Subject: move gRPC-related code for REQ_GET_VRF to grpc_server.go Signed-off-by: FUJITA Tomonori --- server/grpc_server.go | 10 +++------- server/server.go | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/server/grpc_server.go b/server/grpc_server.go index 34aa1f9d..ca852f83 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -772,11 +772,6 @@ func (s *Server) GetRoa(ctx context.Context, arg *api.GetRoaRequest) (*api.GetRo } func (s *Server) GetVrf(ctx context.Context, arg *api.GetVrfRequest) (*api.GetVrfResponse, error) { - d, err := s.get(REQ_GET_VRF, arg) - if err != nil { - return nil, err - } - l := make([]*api.Vrf, 0, len(d.([]*table.Vrf))) toApi := func(v *table.Vrf) *api.Vrf { f := func(rts []bgp.ExtendedCommunityInterface) [][]byte { ret := make([][]byte, 0, len(rts)) @@ -794,8 +789,9 @@ func (s *Server) GetVrf(ctx context.Context, arg *api.GetVrfRequest) (*api.GetVr ExportRt: f(v.ExportRt), } } - - for _, v := range d.([]*table.Vrf) { + vrfs := s.bgpServer.GetVrf() + l := make([]*api.Vrf, 0, len(vrfs)) + for _, v := range vrfs { l = append(l, toApi(v)) } return &api.GetVrfResponse{Vrfs: l}, nil diff --git a/server/server.go b/server/server.go index 17d42ce5..82195a93 100644 --- a/server/server.go +++ b/server/server.go @@ -1247,12 +1247,6 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path { Data: paths, } goto END - case REQ_GET_VRF: - l := make([]*table.Vrf, 0, len(server.globalRib.Vrfs)) - for _, vrf := range server.globalRib.Vrfs { - l = append(l, vrf.Clone()) - } - result.Data = l case REQ_ADD_VRF: msgs, result.ResponseErr = server.handleAddVrfRequest(req) result.Data = &api.AddVrfResponse{} @@ -1309,6 +1303,21 @@ func (s *BgpServer) Start(c *config.Global) (err error) { return nil } +func (s *BgpServer) GetVrf() (l []*table.Vrf) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + l = make([]*table.Vrf, 0, len(s.globalRib.Vrfs)) + for _, vrf := range s.globalRib.Vrfs { + l = append(l, vrf.Clone()) + } + } + return l +} + func (s *BgpServer) Stop() (err error) { ch := make(chan struct{}) defer func() { <-ch }() @@ -1693,7 +1702,7 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { rsp := server.roaManager.handleGRPC(grpcReq) grpcReq.ResponseCh <- rsp close(grpcReq.ResponseCh) - case REQ_VRF, REQ_GET_VRF, REQ_ADD_VRF, REQ_DELETE_VRF: + case REQ_VRF, REQ_ADD_VRF, REQ_DELETE_VRF: pathList := server.handleVrfRequest(grpcReq) if len(pathList) > 0 { server.propagateUpdate(nil, pathList) -- cgit v1.2.3