' RTNETLINK答案:文件存在'

时间:2015-12-18 03:42:45

标签: python linux ubuntu networking trafficshaping

当我添加延迟命令时,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)

上面的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本身的区别是什么?

2 个答案:

答案 0 :(得分:1)

这不是致命的错误:'文件存在'只是说已经定义了这样的仿真和“无效的参数”。内核已知或已删除此类仿真。

快速小样本:

# ~ $ 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

答案 1 :(得分:0)

使用:

sudo tc qdisc replace dev eth0 root netem delay 100ms

或:

sudo tc qdisc del dev eth0 root
sudo tc qdisc add dev eth0 root netem delay 100ms