-
Notifications
You must be signed in to change notification settings - Fork 34
/
helpers.go
47 lines (40 loc) · 1.13 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"math"
"net"
"strconv"
"strings"
)
// validateIP ensures a valid IP4/IP6 address is provided.
func validateIP(ip string) error {
if ip := net.ParseIP(ip); ip != nil {
return nil
}
return fmt.Errorf("%s is not a valid v4 or v6 IP", ip)
}
func splitPerfPair(tunnelDestInput string) []string {
return strings.Split(tunnelDestInput, ":")
}
// convertKbitsToBits iperf3 no longer supports bps, so convert Kbps to bps for tsdb plotting.
func convertKbitsToBits(kbps string) (int, error) {
// round the number to remove any decimals.
float, err := strconv.ParseFloat(kbps, 32)
if err != nil {
return 0, err
}
kbpsInt := int(math.Round(float))
bps := kbpsInt * 1000
return bps, nil
}
// printPerfServers concatenate the perf server pairs to make readable for a debug print.
func printPerfServers(perfServers []servers) {
var endpointList []string
for _, serverPair := range perfServers {
for k, v := range serverPair {
endPointAddressPair := fmt.Sprintf("%s:%s", k, v)
endpointList = append(endpointList, endPointAddressPair)
log.Debugf("[Config] Perf Server = %s", endPointAddressPair)
}
}
}