diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 17:01:26 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 17:01:26 +0900 |
commit | 474f7c3a4d992b4597536e36a2f1597db418580f (patch) | |
tree | e9313f03b97e8a07b2b837085f63b058009fc501 /server/grpc_server.go | |
parent | 5966466632bd73676ec80ca71c5082f88cb65bd6 (diff) |
move gRPC-related code for REQ_ADD_VRF and REQ_DELETE_VRF 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.go | 30 |
1 files changed, 21 insertions, 9 deletions
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) { |