summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--server/server.go25
-rw-r--r--table/destination.go20
2 files changed, 32 insertions, 13 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)
diff --git a/table/destination.go b/table/destination.go
index f669cced..55c90b53 100644
--- a/table/destination.go
+++ b/table/destination.go
@@ -41,6 +41,16 @@ const (
BPR_ROUTER_ID = "Router ID"
)
+func CidrToRadixkey(cidr string) string {
+ _, n, _ := net.ParseCIDR(cidr)
+ ones, _ := n.Mask.Size()
+ var buffer bytes.Buffer
+ for i := 0; i < len(n.IP) && i < ones; i++ {
+ buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
+ }
+ return buffer.String()[:ones]
+}
+
type PeerInfo struct {
AS uint32
ID net.IP
@@ -84,15 +94,7 @@ func NewDestination(nlri bgp.AddrPrefixInterface) *Destination {
newPathList: make([]*Path, 0),
}
if d.routeFamily == bgp.RF_IPv4_UC {
- d.RadixKey = func(cidr string) string {
- _, n, _ := net.ParseCIDR(cidr)
- ones, _ := n.Mask.Size()
- var buffer bytes.Buffer
- for i := 0; i < len(n.IP) && i < ones; i++ {
- buffer.WriteString(fmt.Sprintf("%08b", n.IP[i]))
- }
- return buffer.String()[:ones]
- }(nlri.String())
+ d.RadixKey = CidrToRadixkey(nlri.String())
}
return d
}