summaryrefslogtreecommitdiffhomepage
path: root/table/destination.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-19 14:54:14 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-19 14:54:14 +0900
commit271d42a440645c6e6b12cdd48bde94bfbf6df7bf (patch)
tree5adf3908c20b390ca29f0c5a12a57eb5fff9fd4a /table/destination.go
parent856f867aea28dcee4d2f7b6d312cefe6808202de (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.go16
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) {