【问题标题】:tc: attaching many netems to an interfacetc:将许多网络连接到一个接口
【发布时间】:2015-04-02 18:42:43
【问题描述】:

我希望模拟在主机上不同端口上运行的一组服务的延迟。我想模拟不同服务的不同延迟,可能在给定主机上可能有很多延迟,希望没有任何限制。

我发现这样做的唯一方法是使用 prio qdisc。这是一个例子:

IF=eth0
tc qdisc add dev $IF root handle 1: prio bands 16 priomap 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

# this loop is only a sample to make the example runnable; values will vary in practice
for handle in {2..16}; do
 # add a delay for the service on port 20000 + $handle
 tc qdisc add dev $IF handle $handle: parent 1:$handle netem delay 1000ms # example; this will vary in practice
 # add a filter to send the traffic to the correct netem
 tc filter add dev $IF pref $handle protocol ip u32 match ip sport $(( 20000 + $handle )) 0xffff flowid 1:$handle
done

如果您运行上面的命令,您会注意到句柄 11-16 没有被创建并失败并出现错误。

注意。这是对上述内容的撤消。

IF=eth0
for handle in {2..16}; do
 tc filter del dev $IF pref $handle
 tc qdisc del dev $IF handle $handle: parent 1:$handle netem delay 1000ms
done
tc qdisc del dev $IF root

有没有办法在一个界面中添加超过 10 个网络?

【问题讨论】:

    标签: linux network-programming kernel trafficshaping


    【解决方案1】:

    使用 htb 和类解决它:

    IF=eth0
    tc qdisc add dev $IF root handle 1: htb
    tc class add dev $IF parent 1: classid 1:1 htb rate 1000Mbps
    
    for handle in {2..32}; do
     tc class add dev $IF parent 1:1 classid 1:$handle htb rate 1000Mbps
     tc qdisc add dev $IF handle $handle: parent 1:$handle netem delay 1000ms
     tc filter add dev $IF pref $handle protocol ip u32 match ip sport $(( 20000 + $handle )) 0xffff flowid 1:$handle
    done
    

    【讨论】:

      猜你喜欢
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多