diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-19 14:54:14 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2015-08-19 14:54:14 +0900 |
commit | 271d42a440645c6e6b12cdd48bde94bfbf6df7bf (patch) | |
tree | 5adf3908c20b390ca29f0c5a12a57eb5fff9fd4a /table/destination.go | |
parent | 856f867aea28dcee4d2f7b6d312cefe6808202de (diff) |
gobgp: improve the time to show routes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 16 |
1 files changed, 15 insertions, 1 deletions
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) { |