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