-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiagnosis.go
104 lines (86 loc) · 2.92 KB
/
diagnosis.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package DCP
import (
"encoding/json"
"github.com/google/uuid"
)
type ControlEntity struct {
Id uuid.UUID `json:"id"`
BranchId uuid.UUID `json:"branch_id"`
}
func (ce ControlEntity) MarshalText() ([]byte, error) {
type x ControlEntity
return json.Marshal(x(ce))
}
func (ce *ControlEntity) UnmarshalText(text []byte) error {
type x ControlEntity
return json.Unmarshal(text, (*x)(ce))
}
type CalculationProcessControlEntity struct {
NodesContributedToUpdates map[ControlEntity]int `json:"nodes_contributed_to_updates"`
}
func (dpce *CalculationProcessControlEntity) RegisterContribution(id uuid.UUID, branchId uuid.UUID, added int) {
ce := ControlEntity{
Id: id,
BranchId: branchId,
}
dpce.NodesContributedToUpdates[ce] = added
}
type Diagnosis struct {
NumberOfBroadcasts int `json:"number_of_broadcasts"`
NumberOfUpdates int `json:"number_of_updates"`
NumberOfRejectedDueToThreshold int `json:"number_of_rejected_due_to_threshold"`
NumberOfDuplicates int `json:"number_of_duplicates"`
NumberOfPkMatches int `json:"number_of_pk_matches"`
NumberOfInternalUpdates int `json:"number_of_internal_updates"`
NumberOfPacketsDropped int `json:"number_of_packets_dropped"`
Control *CalculationProcessControlEntity `json:"control"`
Timers *Timer `json:"timers"`
CoSizes []int `json:"co_sizes"`
}
func NewDiagnosis() *Diagnosis {
return &Diagnosis{
NumberOfBroadcasts: 0,
NumberOfUpdates: 0,
NumberOfRejectedDueToThreshold: 0,
NumberOfDuplicates: 0,
NumberOfPkMatches: 0,
NumberOfInternalUpdates: 0,
NumberOfPacketsDropped: 0,
Control: &CalculationProcessControlEntity{
NodesContributedToUpdates: make(map[ControlEntity]int),
},
Timers: &Timer{
Timers: make(map[string]TimerEntry),
},
}
}
func (d *Diagnosis) Init() {
d.NumberOfBroadcasts = 0
d.NumberOfUpdates = 0
d.NumberOfRejectedDueToThreshold = 0
d.NumberOfDuplicates = 0
}
func (d *Diagnosis) IncrementNumberOfBroadcasts() {
d.NumberOfBroadcasts++
}
func (d *Diagnosis) IncrementNumberOfUpdates() {
d.NumberOfUpdates++
}
func (d *Diagnosis) IncrementNumberOgRejectedDueToThreshold() {
d.NumberOfRejectedDueToThreshold++
}
func (d *Diagnosis) IncrementNumberOfDuplicates() {
d.NumberOfDuplicates++
}
func (d *Diagnosis) IncrementNumberOfPkMatches() {
d.NumberOfPkMatches++
}
func (d *Diagnosis) IncrementNumberOfInternalUpdates() {
d.NumberOfInternalUpdates++
}
func (d *Diagnosis) IncrementNumberOfPacketsDropped() {
d.NumberOfPacketsDropped++
}
func (d *Diagnosis) RegisterPacket(len int) {
d.CoSizes = append(d.CoSizes, len)
}