8
from script_commands import (
16
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).')
30
def run(delay=500, port=443):
31
tc('qdisc add dev lo root handle 1: prio')
32
tc('qdisc add dev lo parent 1:3 handle 30: netem delay %dms' % delay)
33
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
34
' dport %d 0xffff flowid 1:3' % port)
35
tc('filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip'
36
' sport %d 0xffff flowid 1:3' % port)
39
Command.commands['start'] = StartCommand
42
class StopCommand(Command):
46
parser = OptionParser()
51
tc('qdisc del dev lo root')
54
Command.commands['stop'] = StopCommand
58
if __name__ == "__main__":
60
Command.run_subcommand(sys.argv[1:])
61
except UserError as e:
62
sys.stderr.write(str(e)+'\n')