mirror of
https://github.com/alice-lg/alice-lg.git
synced 2024-05-11 05:55:03 +00:00
Merge branch 'bugfix/multitable-birdwatcher-check-protocol-up' into develop
This commit is contained in:
@ -290,7 +290,7 @@ func (self *MultiTableBirdwatcher) Neighbours() (*api.NeighboursResponse, error)
|
||||
// Sum up all routes from all peers for a table
|
||||
for _, protocol := range tree[table].(map[string]interface{}) {
|
||||
// Skip peers that are not up (start/down)
|
||||
if protocol.(map[string]interface{})["state"].(string) != "up" {
|
||||
if !isProtocolUp(protocol.(map[string]interface{})["state"].(string)) {
|
||||
continue
|
||||
}
|
||||
allRoutesImported += int64(protocol.(map[string]interface{})["routes"].(map[string]interface{})["imported"].(float64))
|
||||
@ -331,7 +331,7 @@ func (self *MultiTableBirdwatcher) Neighbours() (*api.NeighboursResponse, error)
|
||||
// to query birdwatcher again.
|
||||
for _, protocol := range tree[table].(map[string]interface{}) {
|
||||
// Skip peers that are not up (start/down)
|
||||
if protocol.(map[string]interface{})["state"].(string) != "up" {
|
||||
if !isProtocolUp(protocol.(map[string]interface{})["state"].(string)) {
|
||||
continue
|
||||
}
|
||||
filtered[protocol.(map[string]interface{})["protocol"].(string)] = int(protocol.(map[string]interface{})["routes"].(map[string]interface{})["imported"].(float64))
|
||||
|
@ -2,6 +2,7 @@ package birdwatcher
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/alice-lg/alice-lg/backend/api"
|
||||
@ -51,3 +52,8 @@ func (self *LockMap) Unlock(key string) {
|
||||
}
|
||||
mutex.(*sync.Mutex).Unlock()
|
||||
}
|
||||
|
||||
func isProtocolUp(protocol string) bool {
|
||||
protocol = strings.ToLower(protocol)
|
||||
return protocol == "up"
|
||||
}
|
||||
|
21
backend/sources/birdwatcher/utils_tests.go
Normal file
21
backend/sources/birdwatcher/utils_tests.go
Normal file
@ -0,0 +1,21 @@
|
||||
package birdwatcher
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestIsProtocolUp(t *testing.T) {
|
||||
tests := map[string]bool{
|
||||
"up": true,
|
||||
"uP": true,
|
||||
"Up": true,
|
||||
"UP": true,
|
||||
"down": false,
|
||||
}
|
||||
|
||||
for up, expected := range tests {
|
||||
if isProtocolUp(up) != expected {
|
||||
t.Error("f(", up, ") != ", expected)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user