diff options
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) { |