-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
33 lines (24 loc) · 836 Bytes
/
example.py
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
import time
from tcnetempy.Fault import *
from tcnetempy.TcNetem import TcNetem
# create an instance of Delay with time=100ms and jitter=20ms
delay = Delay(time="100ms", jitter="20ms")
# create an instance of Loss with rate=5%
loss = Loss(rate="5%")
# create an instance of Reorder with rate=5% and gap=2
reorder = Reorder(rate="5%", gap="2")
# get the command for each fault
delay_cmd = delay.build_command()
loss_cmd = loss.build_command()
reorder_cmd = reorder.build_command()
# print the commands
print(delay_cmd) # "delay 100ms 20ms"
print(loss_cmd) # "loss 5%"
print(reorder_cmd) # "reorder 5% gap 2"
# create a TcNetem instance for the "eth0" interface
tc_netem = TcNetem(interface="eth0")
tc_netem.add_faults([delay, loss, reorder])
# sleep for 10 seconds
time.sleep(10)
# delete the netem qdisc
tc_netem.delete()