diff --git a/backend/sources/birdwatcher/source_multitable.go b/backend/sources/birdwatcher/source_multitable.go index 93851c7..914d487 100644 --- a/backend/sources/birdwatcher/source_multitable.go +++ b/backend/sources/birdwatcher/source_multitable.go @@ -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)) diff --git a/backend/sources/birdwatcher/utils.go b/backend/sources/birdwatcher/utils.go index 0ca122d..834f607 100644 --- a/backend/sources/birdwatcher/utils.go +++ b/backend/sources/birdwatcher/utils.go @@ -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" +} diff --git a/backend/sources/birdwatcher/utils_tests.go b/backend/sources/birdwatcher/utils_tests.go new file mode 100644 index 0000000..232837c --- /dev/null +++ b/backend/sources/birdwatcher/utils_tests.go @@ -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) + } + } +}