summaryrefslogtreecommitdiffhomepage
path: root/table
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-20 13:42:38 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-20 13:42:38 +0900
commit859cedf4771364458b283a351b04326232d549b6 (patch)
treebe3009701fbf7f68bd53bb3860a71504308c3a54 /table
parente6074318b7f94caeb31f90c7ee3489460cc781c4 (diff)
server: fix for sorting adj-in/out routes
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table')
-rw-r--r--table/destination.go20
1 files changed, 11 insertions, 9 deletions
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
}