diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-08-02 00:16:33 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2017-08-02 00:16:33 +0900 |
commit | 07196197675c07c712eba0c24a934dcbe20783e4 (patch) | |
tree | f2f08f2606040b90e3f2abe2960f2160d4b93145 /table/destination.go | |
parent | 15f598ad8e5be47725cc7aea31c80e38e346c408 (diff) |
table: allocate bitmap for path id dynamically
allocating 256 bytes per prefix isn't a good idea. Let's allocate 8
bytes by default and expand dynamically if necessary.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Diffstat (limited to 'table/destination.go')
-rw-r--r-- | table/destination.go | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/table/destination.go b/table/destination.go index 15d80e1d..9a26b4d3 100644 --- a/table/destination.go +++ b/table/destination.go @@ -147,16 +147,21 @@ type Destination struct { newPathList paths oldKnownPathList paths RadixKey string - localIdMap Bitmap + localIdMap *Bitmap } -func NewDestination(nlri bgp.AddrPrefixInterface, known ...*Path) *Destination { +func NewDestination(nlri bgp.AddrPrefixInterface, mapSize int, known ...*Path) *Destination { d := &Destination{ routeFamily: bgp.AfiSafiToRouteFamily(nlri.AFI(), nlri.SAFI()), nlri: nlri, knownPathList: known, withdrawList: make([]*Path, 0), newPathList: make([]*Path, 0), + localIdMap: NewBitmap(mapSize), + } + // the id zero means id is not allocated yet. + if mapSize != 0 { + d.localIdMap.Flag(0) } switch d.routeFamily { case bgp.RF_IPv4_UC, bgp.RF_IPv6_UC, bgp.RF_IPv4_MPLS, bgp.RF_IPv6_MPLS: @@ -345,7 +350,12 @@ func (dest *Destination) Calculate() *Destination { for _, path := range dest.knownPathList { if path.GetNlri().PathLocalIdentifier() == 0 { - path.GetNlri().SetPathLocalIdentifier(uint32(dest.localIdMap.FindandSetZeroBit())) + id, err := dest.localIdMap.FindandSetZeroBit() + if err != nil { + dest.localIdMap.Expand() + id, _ = dest.localIdMap.FindandSetZeroBit() + } + path.GetNlri().SetPathLocalIdentifier(uint32(id)) } } // Clear new paths as we copied them. @@ -1022,7 +1032,7 @@ func (old *Destination) Select(option ...DestinationSelectOption) *Destination { } } } - new := NewDestination(old.nlri) + new := NewDestination(old.nlri, 0) for _, path := range paths { p := path.Clone(path.IsWithdraw) p.Filter("", path.Filtered(id)) |