...
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package netem
15
16 import (
17 "math"
18
19 chaosdaemon "github.com/chaos-mesh/chaos-mesh/pkg/chaosdaemon/pb"
20 )
21
22
23
24
25
26
27
28 func MergeNetem(a, b *chaosdaemon.Netem) *chaosdaemon.Netem {
29 if a == nil && b == nil {
30 return nil
31 }
32
33
34 if a == nil {
35 a = &chaosdaemon.Netem{}
36 }
37 if b == nil {
38 b = &chaosdaemon.Netem{}
39 }
40 return &chaosdaemon.Netem{
41 Time: maxu32(a.GetTime(), b.GetTime()),
42 Jitter: maxu32(a.GetJitter(), b.GetJitter()),
43 DelayCorr: maxf32(a.GetDelayCorr(), b.GetDelayCorr()),
44 Limit: maxu32(a.GetLimit(), b.GetLimit()),
45 Loss: maxf32(a.GetLoss(), b.GetLoss()),
46 LossCorr: maxf32(a.GetLossCorr(), b.GetLossCorr()),
47 Gap: maxu32(a.GetGap(), b.GetGap()),
48 Duplicate: maxf32(a.GetDuplicate(), b.GetDuplicate()),
49 DuplicateCorr: maxf32(a.GetDuplicateCorr(), b.GetDuplicateCorr()),
50 Reorder: maxf32(a.GetReorder(), b.GetReorder()),
51 ReorderCorr: maxf32(a.GetReorderCorr(), b.GetReorderCorr()),
52 Corrupt: maxf32(a.GetCorrupt(), b.GetCorrupt()),
53 CorruptCorr: maxf32(a.GetCorruptCorr(), b.GetCorruptCorr()),
54 }
55 }
56
57 func maxu32(a, b uint32) uint32 {
58 if a > b {
59 return a
60 }
61 return b
62 }
63
64 func maxf32(a, b float32) float32 {
65 return float32(math.Max(float64(a), float64(b)))
66 }
67