diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-19 16:20:30 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-19 16:20:30 +0900 |
commit | 34c10c943f9b581285316f529a982d69bf9d8fd5 (patch) | |
tree | 5c49135fe676a6d50020497de48eee4f92d56391 /server/server.go | |
parent | 271d42a440645c6e6b12cdd48bde94bfbf6df7bf (diff) |
server: fix LOCAL_RIB sends back sorted ipv4 routes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'server/server.go')
-rw-r--r-- | server/server.go | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/server/server.go b/server/server.go index 78e9095f..6984885f 100644 --- a/server/server.go +++ b/server/server.go @@ -1086,24 +1086,32 @@ func sendMultipleResponses(grpcReq *GrpcRequest, results []*GrpcResponse) { func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { var msgs []*SenderMsg + sortedDsts := func(t *table.Table) []*GrpcResponse { + results := make([]*GrpcResponse, len(t.GetDestinations())) + + r := radix.New() + for _, dst := range t.GetDestinations() { + result := &GrpcResponse{} + result.Data = dst.ToApiStruct() + r.Insert(dst.RadixKey, result) + } + i := 0 + r.Walk(func(s string, v interface{}) bool { + r, _ := v.(*GrpcResponse) + results[i] = r + i++ + return false + }) + + return results + } + switch grpcReq.RequestType { case REQ_GLOBAL_RIB: if t, ok := server.localRibMap[GLOBAL_RIB_NAME].rib.Tables[grpcReq.RouteFamily]; ok { results := make([]*GrpcResponse, len(t.GetDestinations())) if grpcReq.RouteFamily == bgp.RF_IPv4_UC { - r := radix.New() - for _, dst := range t.GetDestinations() { - result := &GrpcResponse{} - result.Data = dst.ToApiStruct() - r.Insert(dst.RadixKey, result) - } - i := 0 - r.Walk(func(s string, v interface{}) bool { - r, _ := v.(*GrpcResponse) - results[i] = r - i++ - return false - }) + results = sortedDsts(server.localRibMap[GLOBAL_RIB_NAME].rib.Tables[grpcReq.RouteFamily]) } else { i := 0 for _, dst := range t.GetDestinations() { @@ -1160,12 +1168,16 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) []*SenderMsg { remoteAddr := grpcReq.Name if t, ok := server.localRibMap[remoteAddr].rib.Tables[grpcReq.RouteFamily]; ok { results := make([]*GrpcResponse, len(t.GetDestinations())) - i := 0 - for _, dst := range t.GetDestinations() { - result := &GrpcResponse{} - result.Data = dst.ToApiStruct() - results[i] = result - i++ + if grpcReq.RouteFamily == bgp.RF_IPv4_UC { + results = sortedDsts(server.localRibMap[remoteAddr].rib.Tables[grpcReq.RouteFamily]) + } else { + i := 0 + for _, dst := range t.GetDestinations() { + result := &GrpcResponse{} + result.Data = dst.ToApiStruct() + results[i] = result + i++ + } } go sendMultipleResponses(grpcReq, results) } |