From 271d42a440645c6e6b12cdd48bde94bfbf6df7bf Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Wed, 19 Aug 2015 14:54:14 +0900 Subject: gobgp: improve the time to show routes Signed-off-by: FUJITA Tomonori --- table/destination.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'table/destination.go') diff --git a/table/destination.go b/table/destination.go index 75072732..f669cced 100644 --- a/table/destination.go +++ b/table/destination.go @@ -16,6 +16,7 @@ package table import ( + "bytes" "encoding/binary" "encoding/json" "fmt" @@ -71,16 +72,29 @@ type Destination struct { newPathList []*Path bestPath *Path bestPathReason string + RadixKey string } func NewDestination(nlri bgp.AddrPrefixInterface) *Destination { - return &Destination{ + d := &Destination{ routeFamily: bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()), nlri: nlri, knownPathList: make([]*Path, 0), withdrawList: make([]*Path, 0), 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()) + } + return d } func (dd *Destination) MarshalJSON() ([]byte, error) { -- cgit v1.2.3