summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/grpc_server.go32
-rw-r--r--server/server.go6
-rw-r--r--table/vrf.go28
3 files changed, 45 insertions, 21 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) {
diff --git a/server/server.go b/server/server.go
index 5d1e2892..76d214b8 100644
--- a/server/server.go
+++ b/server/server.go
@@ -1380,11 +1380,11 @@ func (server *BgpServer) handleVrfRequest(req *GrpcRequest) []*table.Path {
}
goto END
case REQ_GET_VRF:
- l := make([]*api.Vrf, 0, len(server.globalRib.Vrfs))
+ l := make([]*table.Vrf, 0, len(server.globalRib.Vrfs))
for _, vrf := range server.globalRib.Vrfs {
- l = append(l, vrf.ToApiStruct())
+ l = append(l, vrf.Clone())
}
- result.Data = &api.GetVrfResponse{Vrfs: l}
+ result.Data = l
case REQ_ADD_VRF:
msgs, result.ResponseErr = server.handleAddVrfRequest(req)
result.Data = &api.AddVrfResponse{}
diff --git a/table/vrf.go b/table/vrf.go
index 16e02ed4..c8fc2a16 100644
--- a/table/vrf.go
+++ b/table/vrf.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2014 Nippon Telegraph and Telephone Corporation.
+// Copyright (C) 2014-2016 Nippon Telegraph and Telephone Corporation.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -16,7 +16,6 @@
package table
import (
- api "github.com/osrg/gobgp/api"
"github.com/osrg/gobgp/packet/bgp"
)
@@ -28,21 +27,26 @@ type Vrf struct {
LabelMap map[string]uint32
}
-func (v *Vrf) ToApiStruct() *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)
+func (v *Vrf) Clone() *Vrf {
+ f := func(rt []bgp.ExtendedCommunityInterface) []bgp.ExtendedCommunityInterface {
+ l := make([]bgp.ExtendedCommunityInterface, 0, len(rt))
+ for _, v := range rt {
+ l = append(l, v)
}
- return ret
+ return l
}
- rd, _ := v.Rd.Serialize()
- return &api.Vrf{
+ return &Vrf{
Name: v.Name,
- Rd: rd,
+ Rd: v.Rd,
ImportRt: f(v.ImportRt),
ExportRt: f(v.ExportRt),
+ LabelMap: func() map[string]uint32 {
+ m := make(map[string]uint32)
+ for k, v := range v.LabelMap {
+ m[k] = v
+ }
+ return m
+ }(),
}
}