summaryrefslogtreecommitdiffhomepage
path: root/internal/pkg/table/path.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/path.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/path.go')
-rw-r--r--internal/pkg/table/path.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/internal/pkg/table/path.go b/internal/pkg/table/path.go
index 9f68fde3..0a6debca 100644
--- a/internal/pkg/table/path.go
+++ b/internal/pkg/table/path.go
@@ -1217,3 +1217,29 @@ func (p *Path) SetHash(v uint32) {
func (p *Path) GetHash() uint32 {
return p.attrsHash
}
+
+func nlriToIPNet(nlri bgp.AddrPrefixInterface) *net.IPNet {
+ switch T := nlri.(type) {
+ case *bgp.IPAddrPrefix:
+ return &net.IPNet{
+ IP: net.IP(T.Prefix.To4()),
+ Mask: net.CIDRMask(int(T.Length), 32),
+ }
+ case *bgp.IPv6AddrPrefix:
+ return &net.IPNet{
+ IP: net.IP(T.Prefix.To16()),
+ Mask: net.CIDRMask(int(T.Length), 128),
+ }
+ case *bgp.LabeledIPAddrPrefix:
+ return &net.IPNet{
+ IP: net.IP(T.Prefix.To4()),
+ Mask: net.CIDRMask(int(T.Length), 32),
+ }
+ case *bgp.LabeledIPv6AddrPrefix:
+ return &net.IPNet{
+ IP: net.IP(T.Prefix.To4()),
+ Mask: net.CIDRMask(int(T.Length), 128),
+ }
+ }
+ return nil
+}