我正在寻找模拟在主机上不同端口上运行的一组服务的延迟。我想模拟不同服务的不同延迟,可能在给定主机上可能有很多延迟,希望没有任何限制。
我发现这样做的唯一方法是使用 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 个以上的网络?