@@ -18,6 +18,8 @@ import (
18
18
)
19
19
20
20
var ip , command , gateway , intf , logLevel , nsPath , mac string
21
+ var latency , jitter uint
22
+ var loss float64
21
23
var log = logrus .New ()
22
24
23
25
func init () {
@@ -27,6 +29,9 @@ func init() {
27
29
flag .StringVar (& gateway , "gw" , "" , "gateway of the request (default will be the default route of the given interface)" )
28
30
flag .StringVar (& logLevel , "log-level" , "info" , "min level of logs to print" )
29
31
flag .StringVar (& mac , "mac" , "" , "mac address of the interface inside the namespace (default will be a random one)" )
32
+ flag .UintVar (& latency , "latency" , 0 , "latency added on the interface in ms" )
33
+ flag .UintVar (& jitter , "jitter" , 0 , "jitter added on the interface in ms" )
34
+ flag .Float64Var (& loss , "loss" , 0 , "loss added on the interface in percentage" )
30
35
flag .StringVar (
31
36
& nsPath ,
32
37
"ns-path" ,
@@ -202,6 +207,28 @@ func main() {
202
207
return
203
208
}
204
209
210
+ // Check if we need to add Qdisc attributes
211
+ if latency != 0 || jitter != 0 || loss != 0 {
212
+ log .Debugf ("Add TC : latency %d ms | jitter %d ms | loss %f" , latency * 1000 , jitter * 1000 , loss )
213
+ netem := netlink.NetemQdiscAttrs {
214
+ Latency : uint32 (latency ) * 1000 ,
215
+ Jitter : uint32 (jitter ) * 1000 ,
216
+ Loss : float32 (loss ),
217
+ }
218
+ qdisc := netlink .NewNetem (
219
+ netlink.QdiscAttrs {
220
+ LinkIndex : link .Attrs ().Index ,
221
+ Parent : netlink .HANDLE_ROOT ,
222
+ },
223
+ netem ,
224
+ )
225
+ err = netlink .QdiscAdd (qdisc )
226
+ if err != nil {
227
+ log .Warn ("Error while setting qdisc on macVlan: " , err )
228
+ return
229
+ }
230
+ }
231
+
205
232
log .Debugf ("Set %s as the route" , gwaddr )
206
233
// ============================= Set the default route in the namespace
207
234
err = netlink .RouteAdd (& netlink.Route {
0 commit comments