diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-20 13:42:38 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-20 13:42:38 +0900 |
commit | 859cedf4771364458b283a351b04326232d549b6 (patch) | |
tree | be3009701fbf7f68bd53bb3860a71504308c3a54 /server/server.go | |
parent | e6074318b7f94caeb31f90c7ee3489460cc781c4 (diff) |
server: fix for sorting adj-in/out routes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/server/server.go b/server/server.go index 5f708ea2..cd4134da 100644 --- a/server/server.go +++ b/server/server.go @@ -1211,15 +1211,32 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { log.Debugf("RouteFamily=%v adj-rib-out found : %d", rf.String(), len(paths)) } - results := make([]*GrpcResponse, len(paths)) - for i, p := range paths { - result := &GrpcResponse{ + toResult := func(p *table.Path) *GrpcResponse { + return &GrpcResponse{ Data: &api.Destination{ Prefix: p.GetNlri().String(), Paths: []*api.Path{p.ToApiStruct()}, }, } - results[i] = result + } + + results := make([]*GrpcResponse, len(paths)) + if rf == bgp.RF_IPv4_UC { + r := radix.New() + for _, p := range paths { + r.Insert(table.CidrToRadixkey(p.GetNlri().String()), toResult(p)) + } + i := 0 + r.Walk(func(s string, v interface{}) bool { + r, _ := v.(*GrpcResponse) + results[i] = r + i++ + return false + }) + } else { + for i, p := range paths { + results[i] = toResult(p) + } } go sendMultipleResponses(grpcReq, results) |