From 474f7c3a4d992b4597536e36a2f1597db418580f Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 26 Jul 2016 17:01:26 +0900 Subject: move gRPC-related code for REQ_ADD_VRF and REQ_DELETE_VRF to grpc_server.go Signed-off-by: FUJITA Tomonori --- server/grpc_server.go | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'server/grpc_server.go') diff --git a/server/grpc_server.go b/server/grpc_server.go index ca852f83..e69b2b0d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -804,20 +804,32 @@ func (s *Server) get(typ int, d interface{}) (interface{}, error) { return res.Data, res.Err() } -func (s *Server) AddVrf(ctx context.Context, arg *api.AddVrfRequest) (*api.AddVrfResponse, error) { - d, err := s.get(REQ_ADD_VRF, arg) +func (s *Server) AddVrf(ctx context.Context, arg *api.AddVrfRequest) (r *api.AddVrfResponse, err error) { + rd := bgp.GetRouteDistinguisher(arg.Vrf.Rd) + f := func(bufs [][]byte) ([]bgp.ExtendedCommunityInterface, error) { + ret := make([]bgp.ExtendedCommunityInterface, 0, len(bufs)) + for _, rt := range bufs { + r, err := bgp.ParseExtended(rt) + if err != nil { + return nil, err + } + ret = append(ret, r) + } + return ret, nil + } + im, err := f(arg.Vrf.ImportRt) if err != nil { - return nil, err + return &api.AddVrfResponse{}, err } - return d.(*api.AddVrfResponse), err + ex, err := f(arg.Vrf.ExportRt) + if err != nil { + return &api.AddVrfResponse{}, err + } + return &api.AddVrfResponse{}, s.bgpServer.AddVrf(arg.Vrf.Name, rd, im, ex) } func (s *Server) DeleteVrf(ctx context.Context, arg *api.DeleteVrfRequest) (*api.DeleteVrfResponse, error) { - d, err := s.get(REQ_DELETE_VRF, arg) - if err != nil { - return nil, err - } - return d.(*api.DeleteVrfResponse), err + return &api.DeleteVrfResponse{}, s.bgpServer.DeleteVrf(arg.Vrf.Name) } func (s *Server) AddNeighbor(ctx context.Context, arg *api.AddNeighborRequest) (*api.AddNeighborResponse, error) { -- cgit v1.2.3