summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table/destination.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-25 20:33:59 +0900
committerFUJITA Tomonori <fujita.tomonori@gmail.com>2019-10-25 20:38:33 +0900
commitb4e2d9e440a4eb6d3091a7c586d2e55b69ec968a (patch)
tree68af74b393dda96a33d47a995b8c3f12680e51e2 /internal/pkg/table/destination.go
parent6e81f596b1e924337470417cf1e3faa3260308da (diff)
table: replace radix with crit-bit algo for longer-prefixes search
faster and less memory usage. Now go-radix has gone. Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'internal/pkg/table/destination.go')
-rw-r--r--internal/pkg/table/destination.go32
1 files changed, 0 insertions, 32 deletions
diff --git a/internal/pkg/table/destination.go b/internal/pkg/table/destination.go
index 4adc6290..2880f662 100644
--- a/internal/pkg/table/destination.go
+++ b/internal/pkg/table/destination.go
@@ -74,38 +74,6 @@ func (r *BestPathReason) String() string {
return BestPathReasonStringMap[*r]
}
-func IpToRadixkey(b []byte, max uint8) string {
- var buffer bytes.Buffer
- for i := 0; i < len(b) && i < int(max); i++ {
- fmt.Fprintf(&buffer, "%08b", b[i])
- }
- return buffer.String()[:max]
-}
-
-func CidrToRadixkey(cidr string) string {
- _, n, _ := net.ParseCIDR(cidr)
- ones, _ := n.Mask.Size()
- return IpToRadixkey(n.IP, uint8(ones))
-}
-
-func AddrToRadixkey(addr bgp.AddrPrefixInterface) string {
- var (
- ip net.IP
- size uint8
- )
- switch T := addr.(type) {
- case *bgp.IPAddrPrefix:
- mask := net.CIDRMask(int(T.Length), net.IPv4len*8)
- ip, size = T.Prefix.Mask(mask).To4(), uint8(T.Length)
- case *bgp.IPv6AddrPrefix:
- mask := net.CIDRMask(int(T.Length), net.IPv6len*8)
- ip, size = T.Prefix.Mask(mask).To16(), uint8(T.Length)
- default:
- return CidrToRadixkey(addr.String())
- }
- return IpToRadixkey(ip, size)
-}
-
type PeerInfo struct {
AS uint32
ID net.IP