16
17
subprocess.call('sudo tc ' + command, shell=True)
19
class StartCommand(Command):
23
parser = OptionParser()
25
'-d', '--delay', dest='delay', type='int',
26
help='Length of delay in miliseconds (each way).'
27
' Default: %default.')
31
def run(delay=500, port=443):
32
tc('qdisc add dev lo root handle 1: prio')
33
tc('qdisc add dev lo parent 1:3 handle 30: netem delay %dms' % delay)
34
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
35
' dport %d 0xffff flowid 1:3' % port)
36
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
37
' sport %d 0xffff flowid 1:3' % port)
40
Command.commands['start'] = StartCommand
43
class StopCommand(Command):
47
parser = OptionParser()
52
tc('qdisc del dev lo root')
55
Command.commands['stop'] = StopCommand
20
@types(delay='int', port='int')
21
@helps(delay='Length of delay in miliseconds (each way).',
22
port='Port to induce delay on.')
23
def start(delay=500, port=443):
24
tc('qdisc add dev lo root handle 1: prio')
25
tc('qdisc add dev lo parent 1:3 handle 30: netem delay %dms' % delay)
26
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
27
' dport %d 0xffff flowid 1:3' % port)
28
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
29
' sport %d 0xffff flowid 1:3' % port)
32
Command.commands['start'] = start
36
tc('qdisc del dev lo root')
39
Command.commands['stop'] = stop