@@ -10,39 +10,40 @@ import (
1010)
1111
1212const (
13- tcRootQDisc = `dev %s handle 10: root`
14- tcRootExtra = `default 1`
15- tcDefaultClass = `dev %s parent 10: classid 10:1`
16- tcTargetClass = `dev %s parent 10: classid 10:10`
17- tcNetemRule = `dev %s parent 10:10 handle 100:`
18- tcRate = `rate %vkbit`
19- tcDelay = `delay %vms`
20- tcLDelayistributionNormal = `distribution normal`
21- tcLDelayJitter = `%vms`
22- tcLoss = `loss %v%%`
23- tcReorder = `reorder %f`
24- tcDuplicate = `duplicate %f`
25- tcCorrupt = `corrupt %f`
26- tcAddClass = `sudo tc class add`
27- tcDelClass = `sudo tc class del`
28- tcAddQDisc = `sudo tc qdisc add`
29- tcDelQDisc = `sudo tc qdisc del`
30- iptAddTarget = `sudo %s -A POSTROUTING -t mangle -j CLASSIFY --set-class 10:10`
31- iptDelTarget = `sudo %s -D POSTROUTING -t mangle -j CLASSIFY --set-class 10:10`
32- iptDestIP = `-d %s`
33- iptProto = `-p %s`
34- iptDestPorts = `--match multiport --dports %s`
35- iptDestPort = `--dport %s`
36- iptSrcPorts = `--match multiport --sports %s`
37- iptSrcPort = `--sport %s`
38- iptDelSearch = `class 0010:0010`
39- TcList = `sudo tc qdisc show`
40- IptList = `sudo %s -S -t mangle`
41- Ip4Tables = `iptables`
42- Ip6Tables = `ip6tables`
43- iptDel = `sudo %s -t mangle -D`
44- tcExists = `sudo tc qdisc show | grep "netem"`
45- tcCheck = `sudo tc -s qdisc`
13+ tcRootQDisc = `dev %s handle 10: root`
14+ tcRootExtra = `default 1`
15+ tcDefaultClass = `dev %s parent 10: classid 10:1`
16+ tcTargetClass = `dev %s parent 10: classid 10:10`
17+ tcNetemRule = `dev %s parent 10:10 handle 100:`
18+ tcRate = `rate %vkbit`
19+ tcDelay = `delay %vms`
20+ tcDelayistribution = `distribution %s`
21+ tcDelayJitter = `%vms`
22+ tcDelayCorrelation = `%v%%`
23+ tcLoss = `loss %v%% 25%%`
24+ tcReorder = `reorder %v%% gap 3`
25+ tcDuplicate = `duplicate %v%%`
26+ tcCorrupt = `corrupt %v%%`
27+ tcAddClass = `sudo tc class add`
28+ tcDelClass = `sudo tc class del`
29+ tcAddQDisc = `sudo tc qdisc add`
30+ tcDelQDisc = `sudo tc qdisc del`
31+ iptAddTarget = `sudo %s -A POSTROUTING -t mangle -j CLASSIFY --set-class 10:10`
32+ iptDelTarget = `sudo %s -D POSTROUTING -t mangle -j CLASSIFY --set-class 10:10`
33+ iptDestIP = `-d %s`
34+ iptProto = `-p %s`
35+ iptDestPorts = `--match multiport --dports %s`
36+ iptDestPort = `--dport %s`
37+ iptSrcPorts = `--match multiport --sports %s`
38+ iptSrcPort = `--sport %s`
39+ iptDelSearch = `class 0010:0010`
40+ TcList = `sudo tc qdisc show`
41+ IptList = `sudo %s -S -t mangle`
42+ Ip4Tables = `iptables`
43+ Ip6Tables = `ip6tables`
44+ iptDel = `sudo %s -t mangle -D`
45+ tcExists = `sudo tc qdisc show | grep "netem"`
46+ tcCheck = `sudo tc -s qdisc`
4647
4748 //tcCbq = `cbq avpkt 1000 bandwidth %vkbit`
4849)
@@ -193,16 +194,31 @@ func addNetemRule(cfg *Config, c commander) error {
193194 strs = append (strs , fmt .Sprintf (tcDelay , cfg .Latency ))
194195
195196 if cfg .LatencyJitter > 0 {
196- strs = append (strs , fmt .Sprintf (tcLDelayJitter , cfg .LatencyJitter ))
197+ strs = append (strs , fmt .Sprintf (tcDelayJitter , cfg .LatencyJitter ))
197198
198- if cfg .LatencyDistributionNormal {
199- strs = append (strs , tcLDelayistributionNormal )
199+ if cfg .LatencyCorrelation > 0 {
200+ strs = append (strs , fmt .Sprintf (tcDelayCorrelation , cfg .LatencyCorrelation ))
201+ }
202+
203+ if len (cfg .LatencyDistribution ) > 0 {
204+ strs = append (strs , fmt .Sprintf (tcDelayistribution , cfg .LatencyDistribution ))
200205 }
201206 }
202- }
203207
204- log .Debug ("TargetBandwidth: %d" , cfg .TargetBandwidth )
208+ if cfg .LatencyReorder > 0 {
209+ strs = append (strs , fmt .Sprintf (tcReorder , strconv .FormatFloat (cfg .LatencyReorder , 'f' , 2 , 64 ))) //"reorder 50% gap 3"
210+ }
211+
212+ if cfg .LatencyDuplicate > 0 {
213+ strs = append (strs , fmt .Sprintf (tcDuplicate , strconv .FormatFloat (cfg .LatencyDuplicate , 'f' , 2 , 64 ))) //"duplicate 50%"
214+ }
205215
216+ if cfg .LatencyCorrupt > 0 {
217+ strs = append (strs , fmt .Sprintf (tcCorrupt , strconv .FormatFloat (cfg .LatencyCorrupt , 'f' , 2 , 64 ))) //"corrupt 2%"
218+ }
219+ }
220+
221+ log .Debug ("TargetBandwidth: %d, but if you used 'rate' in a netem command, you will received an error." , cfg .TargetBandwidth )
206222 if cfg .TargetBandwidth > - 1 {
207223 // If you used 'rate' in netem, it will has an error.
208224 //strs = append(strs, fmt.Sprintf(tcRate, cfg.TargetBandwidth))
@@ -215,7 +231,7 @@ func addNetemRule(cfg *Config, c commander) error {
215231 cmd := strings .Join (strs , " " )
216232
217233 log .Debug ("Adding a netem rule :" )
218-
234+ log . Debug ( "%s" , cmd )
219235 return c .execute (cmd )
220236}
221237
0 commit comments