summaryrefslogtreecommitdiffhomepage
path: root/server/grpc_server.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-11 10:12:26 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2016-07-20 04:25:25 +0900
commite090609b146fdde93714e966aa8ec300b5842ba3 (patch)
treed198865abf0c5600b28a7648ca1aa233fa0953d2 /server/grpc_server.go
parentc31164d90d1728e8c565cb8348adad0316cc60db (diff)
move gRPC-related code in vrf.go to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/grpc_server.go')
-rw-r--r--server/grpc_server.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go
index 69313092..a47222c5 100644
--- a/server/grpc_server.go
+++ b/server/grpc_server.go
@@ -546,13 +546,33 @@ 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) {
- req := NewGrpcRequest(REQ_GET_VRF, "", bgp.RouteFamily(0), nil)
- s.bgpServerCh <- req
- res := <-req.ResponseCh
- if res.Err() != nil {
- return nil, res.Err()
+ 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))
+ for _, rt := range rts {
+ b, _ := rt.Serialize()
+ ret = append(ret, b)
+ }
+ return ret
+ }
+ rd, _ := v.Rd.Serialize()
+ return &api.Vrf{
+ Name: v.Name,
+ Rd: rd,
+ ImportRt: f(v.ImportRt),
+ ExportRt: f(v.ExportRt),
+ }
+ }
+
+ for _, v := range d.([]*table.Vrf) {
+ l = append(l, toApi(v))
}
- return res.Data.(*api.GetVrfResponse), res.Err()
+ return &api.GetVrfResponse{Vrfs: l}, nil
}
func (s *Server) get(typ int, d interface{}) (interface{}, error) {