summaryrefslogtreecommitdiffhomepage
path: root/packet/bgp/bgp.go
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-07 10:05:04 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2018-05-07 21:18:04 +0900
commitdc9fe2b1cc7db1a8d53d4f3553681b9531a4ff0e (patch)
tree27544a114f60c9a70571e62bb8d4526a01f6518d /packet/bgp/bgp.go
parentcc42a3137cd8d09521b6776ba0f1d76c186f4713 (diff)
table: use shorter key for map of ipv4 and ipv6 prefixes
save about 100MB memory. Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'packet/bgp/bgp.go')
-rw-r--r--packet/bgp/bgp.go28
1 files changed, 24 insertions, 4 deletions
diff --git a/packet/bgp/bgp.go b/packet/bgp/bgp.go
index ef2e3e20..ea7c6844 100644
--- a/packet/bgp/bgp.go
+++ b/packet/bgp/bgp.go
@@ -4755,12 +4755,32 @@ func GetRouteFamily(name string) (RouteFamily, error) {
return RouteFamily(0), fmt.Errorf("%s isn't a valid route family name", name)
}
-func NewPrefixFromRouteFamily(afi uint16, safi uint8) (prefix AddrPrefixInterface, err error) {
- switch AfiSafiToRouteFamily(afi, safi) {
+func NewPrefixFromRouteFamily(afi uint16, safi uint8, prefixStr ...string) (prefix AddrPrefixInterface, err error) {
+ family := AfiSafiToRouteFamily(afi, safi)
+
+ f := func(s string) AddrPrefixInterface {
+ addr, net, _ := net.ParseCIDR(s)
+ len, _ := net.Mask.Size()
+ switch family {
+ case RF_IPv4_UC, RF_IPv4_MC:
+ return NewIPAddrPrefix(uint8(len), addr.String())
+ }
+ return NewIPv6AddrPrefix(uint8(len), addr.String())
+ }
+
+ switch family {
case RF_IPv4_UC, RF_IPv4_MC:
- prefix = NewIPAddrPrefix(0, "")
+ if len(prefixStr) > 0 {
+ prefix = f(prefixStr[0])
+ } else {
+ prefix = NewIPAddrPrefix(0, "")
+ }
case RF_IPv6_UC, RF_IPv6_MC:
- prefix = NewIPv6AddrPrefix(0, "")
+ if len(prefixStr) > 0 {
+ prefix = f(prefixStr[0])
+ } else {
+ prefix = NewIPv6AddrPrefix(0, "")
+ }
case RF_IPv4_VPN:
prefix = NewLabeledVPNIPAddrPrefix(0, "", *NewMPLSLabelStack(), nil)
case RF_IPv6_VPN: