summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 16:01:20 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-26 16:01:20 +0900
commit5966466632bd73676ec80ca71c5082f88cb65bd6 (patch)
treefecd12fd6d7f02e5efb79f3d9511161fd0fa56a6
parente7354de8bbc20bc507723dc185940f7368723ca4 (diff)
move gRPC-related code for REQ_GET_VRF to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--server/grpc_server.go10
-rw-r--r--server/server.go23
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)