better strtoint
This commit is contained in:
parent
97dbe0c4c8
commit
cbdc1f5d67
@ -1,6 +1,7 @@
|
|||||||
package pools
|
package pools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@ -51,6 +52,14 @@ func NewExtCommunitiesPool() *CommunitiesPool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func extPrefixToInt(s string) int {
|
||||||
|
v := 0
|
||||||
|
for i, c := range s {
|
||||||
|
v += int(math.Pow(1000.0, float64(i))) * int(c)
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
||||||
// AcquireExt a list of ext bgp communities
|
// AcquireExt a list of ext bgp communities
|
||||||
func (p *CommunitiesPool) AcquireExt(communities []api.ExtCommunity) []api.ExtCommunity {
|
func (p *CommunitiesPool) AcquireExt(communities []api.ExtCommunity) []api.ExtCommunity {
|
||||||
p.Lock()
|
p.Lock()
|
||||||
@ -59,10 +68,7 @@ func (p *CommunitiesPool) AcquireExt(communities []api.ExtCommunity) []api.ExtCo
|
|||||||
// Make identification list
|
// Make identification list
|
||||||
ids := make([]int, len(communities))
|
ids := make([]int, len(communities))
|
||||||
for i, comm := range communities {
|
for i, comm := range communities {
|
||||||
r := 0 // RO
|
r := extPrefixToInt(comm[0].(string))
|
||||||
if comm[0].(string) == "rt" {
|
|
||||||
r = 1
|
|
||||||
}
|
|
||||||
icomm := []int{r, comm[1].(int), comm[2].(int)}
|
icomm := []int{r, comm[1].(int), comm[2].(int)}
|
||||||
|
|
||||||
// get community identifier
|
// get community identifier
|
||||||
|
Loading…
x
Reference in New Issue
Block a user