Skip to content
Snippets Groups Projects
Commit e52ad631 authored by Daniel Czerwonk's avatar Daniel Czerwonk
Browse files

improved performance on as path prepend

parent 196ac647
No related branches found
No related tags found
No related merge requests found
...@@ -2,6 +2,8 @@ package route ...@@ -2,6 +2,8 @@ package route
import ( import (
"fmt" "fmt"
"strconv"
"strings"
"github.com/taktv6/tflow2/convert" "github.com/taktv6/tflow2/convert"
) )
...@@ -155,11 +157,20 @@ func (b *BGPPath) Print() string { ...@@ -155,11 +157,20 @@ func (b *BGPPath) Print() string {
} }
func (b *BGPPath) Prepend(asn uint32, times uint16) { func (b *BGPPath) Prepend(asn uint32, times uint16) {
if times == 0 {
return
}
asnStr := strconv.FormatUint(uint64(asn), 10)
path := make([]string, times+1)
for i := 0; uint16(i) < times; i++ { for i := 0; uint16(i) < times; i++ {
b.ASPath = fmt.Sprintf("%d %s", asn, b.ASPath) path[i] = asnStr
} }
path[times] = b.ASPath
b.ASPathLen = b.ASPathLen + uint16(times) b.ASPath = strings.TrimSuffix(strings.Join(path, " "), " ")
b.ASPathLen = b.ASPathLen + times
} }
func (p *BGPPath) Copy() *BGPPath { func (p *BGPPath) Copy() *BGPPath {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment