当我添加延迟命令时,PARAMIKO返回“2”作为退出状态(而它返回“0”用于带宽命令设置)。2号行吗?(谷歌没帮上忙,我猜2一定是某种错误)。
我使用的命令是:-

delay_cmd = "sudo tc qdisc add dev eth0 parent 1: handle 1: netem delay %dms" %(delay)

我们基本上是想遵循这个原则:
# tc qdisc add dev eth0 root netem delay 100ms
来自在线教程。
应该设置bw、filter和delay的命令块是这样的。(我猜我可能弄乱了父/类id)。你能看出我做错了什么吗?
   cmd2 = "sudo tc class add dev %s parent 1: classid 1:1 htb rate %dmbps ceil %dmbps" % (interface, bandwidth, 2*bandwidth )
    filter_cmd = "sudo tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match ip dst %s/%d flowid 1:1" % (interface, ip, subnetmasklength)
    delay_cmd = "sudo tc qdisc add dev eth0 parent 1:0 handle 1: netem delay %dms" %(delay)

这是我收到的错误:
'RTNETLINK answers: File exists'

这是我们设置延迟和带宽的脚本:
def exec_bw_config2(ssh, interface, bandwidth, ip, subnetmasklength, delay):
    clear_bw_config2(ssh, interface)
    # create a qdisc (queuing discipline), 12 is default class
    cmd1 = "sudo tc qdisc add dev %s root handle 1: htb default 12" % interface
    print cmd1
    block_exec(ssh, cmd1)

    # define the performance for default class
    cmd2 = "sudo tc class add dev %s parent 1: classid 1:1 htb rate %dmbps ceil %dmbps" % (interface, bandwidth, 2*bandwidth )
    print cmd2

    block_exec(ssh, cmd2)


    filter_cmd = "sudo tc filter add dev %s protocol ip parent 1:0 prio 1 u32 match ip dst %s/%d flowid 1:1" % (interface, ip, subnetmasklength)
    print filter_cmd
    block_exec(ssh, filter_cmd)


delay_cmd = "sudo tc qdisc add dev eth0 parent 1: handle 1: netem delay %dms" %(delay)
    print delay_cmd
    block_exec(ssh, delay_cmd)

那么上面的延迟指令有什么问题吗?
这就是我们在代码中所说的:
def main():
    myhosts = ["10.0.1.192", "10.0.1.191", "10.0.1.190"]
    username="ubuntu"
    port=22
    #key = get_private_key()
    for host in myhosts:
        ssh = get_ssh(username, host, port)
        clear_bw_config2(ssh, "eth0")
        exec_bw_config2(ssh, "eth0", int(sys.argv[1]) , "10.0.1.0", 24, int(sys.argv[2]))

    # iterate over hosts here
    # for everyhost,
    # 1. create ssh connection
    # 2. run the exec_bw_config with params
    return

进一步说明parent 1: handleparent 1:2 handle之间的区别是什么?

最佳答案

这并不是一个致命的错误:“文件存在”只是说这样的仿真已经定义了,“无效的参数”,这样的仿真不知道内核或者已经删除了。
快速小样本:

# ~ $ sudo tc qdisc add dev eth0 root netem delay 0ms
# ~ $ sudo tc qdisc add dev eth0 root netem delay 0ms
RTNETLINK answers: File exists
# ~ $ sudo tc qdisc del dev eth0 root netem delay 0ms
# ~ $ sudo tc qdisc del dev eth0 root netem delay 0ms
RTNETLINK answers: Invalid argument

10-07 16:59