-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathresults.go
64 lines (56 loc) · 1.9 KB
/
results.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package twamp
import (
"log"
"math"
"time"
)
/*
TWAMP test result timestamps have been normalized to UNIX epoch time.
*/
type TwampResults struct {
SeqNum uint32 `json:"seqnum"`
Timestamp time.Time `json:"timestamp"`
ErrorEstimate uint16 `json:"errorEstimate"`
ReceiveTimestamp time.Time `json:"receiveTimestamp"`
SenderSeqNum uint32 `json:"senderSeqnum"`
SenderTimestamp time.Time `json:"senderTimestamp"`
SenderErrorEstimate uint16 `json:"senderErrorEstimate"`
SenderTTL byte `json:"senderTTL"`
FinishedTimestamp time.Time `json:"finishedTimestamp"`
SenderSize int `json:"senderSize"`
SenderPaddingSize int `json:"senderPaddingSize"`
IsDuplicate bool `json:"isDuplicate"`
}
func (r *TwampResults) GetWait() time.Duration {
return r.Timestamp.Sub(r.ReceiveTimestamp)
}
func (r *TwampResults) GetRTT() time.Duration {
return r.FinishedTimestamp.Sub(r.SenderTimestamp)
}
func (r *TwampResults) PrintResults() {
log.Printf("TWAMP test took %s.\n", r.GetRTT())
log.Printf("Sender Sequence Number: %d", r.SenderSeqNum)
log.Printf("Receiver Sequence Number: %d", r.SeqNum)
}
type PingResultStats struct {
Min time.Duration `json:"min"`
Max time.Duration `json:"max"`
Avg time.Duration `json:"avg"`
StdDev time.Duration `json:"stddev"`
Transmitted uint64 `json:"tx"`
Received uint64 `json:"rx"`
Loss float64 `json:"loss"`
Duplicates uint64 `json:"dup"`
}
type PingResults struct {
Results []*TwampResults `json:"results"`
Stat *PingResultStats `json:"stats"`
}
func (r *PingResults) stdDev(mean time.Duration) time.Duration {
total := float64(0)
for _, result := range r.Results {
total += math.Pow(float64(result.GetRTT()-mean), 2)
}
variance := total / float64(len(r.Results)-1)
return time.Duration(math.Sqrt(variance))
}