summaryrefslogtreecommitdiffhomepage
path: root/api/grpc_server.go
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-19 10:25:50 +0900
committerIWASE Yusuke <iwase.yusuke0@gmail.com>2018-06-19 12:01:48 +0900
commitb992c538652580cb4150524328dc2c3b13425863 (patch)
tree9911930f2771d7cfb815c9f3624fa13c46766626 /api/grpc_server.go
parentb73933c4b20e15f468944edd7012a7cc90adf0e7 (diff)
api: Use attribute.proto struct in message Vrf
The current formats of the RD and import/export RTs in message Vrf are the binary type representation, this patch fixes to use the structures defined in attribute.proto file. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com>
Diffstat (limited to 'api/grpc_server.go')
-rw-r--r--api/grpc_server.go37
1 files changed, 10 insertions, 27 deletions
diff --git a/api/grpc_server.go b/api/grpc_server.go
index 135546b5..2f116980 100644
--- a/api/grpc_server.go
+++ b/api/grpc_server.go
@@ -1103,21 +1103,12 @@ func (s *Server) EnableZebra(ctx context.Context, arg *EnableZebraRequest) (*Ena
func (s *Server) GetVrf(ctx context.Context, arg *GetVrfRequest) (*GetVrfResponse, error) {
toApi := func(v *table.Vrf) *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 &Vrf{
Name: v.Name,
- Rd: rd,
+ Rd: MarshalRD(v.Rd),
Id: v.Id,
- ImportRt: f(v.ImportRt),
- ExportRt: f(v.ExportRt),
+ ImportRt: MarshalRTs(v.ImportRt),
+ ExportRt: MarshalRTs(v.ExportRt),
}
}
vrfs := s.bgpServer.GetVrf()
@@ -1132,25 +1123,17 @@ func (s *Server) AddVrf(ctx context.Context, arg *AddVrfRequest) (r *AddVrfRespo
if arg == nil || arg.Vrf == nil {
return nil, fmt.Errorf("invalid request")
}
- 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
+ rd, err := UnmarshalRD(arg.Vrf.Rd)
+ if err != nil {
+ return nil, err
}
- im, err := f(arg.Vrf.ImportRt)
+ im, err := UnmarshalRTs(arg.Vrf.ImportRt)
if err != nil {
- return &AddVrfResponse{}, err
+ return nil, err
}
- ex, err := f(arg.Vrf.ExportRt)
+ ex, err := UnmarshalRTs(arg.Vrf.ExportRt)
if err != nil {
- return &AddVrfResponse{}, err
+ return nil, err
}
return &AddVrfResponse{}, s.bgpServer.AddVrf(arg.Vrf.Name, arg.Vrf.Id, rd, im, ex)
}