|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?注册
×
这是我用的测试代码(参考一个叫tc2的程序编写的),请大家帮忙看一看,谢谢!
#!/bin/sh
DEV="eth1"
DOWNLINK=1500
start_routing()
{
echo -n "队列设置开始start......"
tc qdisc add dev $DEV root handle 1: htb default 24
tc class add dev $DEV parent 1: classid 1:1 htb rate 500Mbit ceil 500Mbit prio 0
tc class add dev $DEV parent 1:1 classid 1:11 htb rate 100Mbit ceil 100Mbit prio 1
tc class add dev $DEV parent 1:1 classid 1:12 htb rate 150Mbit ceil 200Mbit prio 2
tc class add dev $DEV parent 1: classid 1:2 htb rate 500Mbit prio 3
tc class add dev $DEV parent 1:2 classid 1:21 htb rate 100Mbit ceil 100Mbit prio 4
tc class add dev $DEV parent 1:2 classid 1:22 htb rate 100Mbit ceil 100Mbit prio 5
tc class add dev $DEV parent 1:2 classid 1:23 htb rate 50Mbit ceil 50Mbit prio 6
tc class add dev $DEV parent 1:2 classid 1:24 htb rate 20Mbit ceil 20Mbit prio 7
tc qdisc add dev $DEV parent 1:11 handle 111: sfq perturb 5
tc qdisc add dev $DEV parent 1:12 handle 112: sfq perturb 5
tc qdisc add dev $DEV parent 1:21 handle 121: sfq perturb 10
tc qdisc add dev $DEV parent 1:22 handle 122: sfq perturb 10
tc qdisc add dev $DEV parent 1:23 handle 133: sfq perturb 10
tc qdisc add dev $DEV parent 1:24 handle 124: sfq perturb 10
echo "队列设置成功.done."
echo -n "设置包过滤 Setting up Filters......"
tc filter add dev $DEV parent 1:0 protocol ip prio 1 handle 1 fw classid 1:11
tc filter add dev $DEV parent 1:0 protocol ip prio 2 handle 2 fw classid 1:12
tc filter add dev $DEV parent 1:0 protocol ip prio 3 handle 3 fw classid 1:21
tc filter add dev $DEV parent 1:0 protocol ip prio 4 handle 4 fw classid 1:22
tc filter add dev $DEV parent 1:0 protocol ip prio 5 handle 5 fw classid 1:23
tc filter add dev $DEV parent 1:0 protocol ip prio 6 handle 6 fw classid 1:24
echo "设置过滤器成功.done."
tc qdisc add dev $DEV handle ffff: ingress
tc filter add dev $DEV parent ffff: protocol ip prio 50 handle 8 fw police rate ${DOWNLINK}kbit burst 10k drop flowid :8
}
start_mangle()
{
echo -n "开始给数据包打标记......start mangle mark......"
iptables -t mangle -A PREROUTING -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j RETURN
iptables -t mangle -A PREROUTING -p icmp -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -p icmp -j RETURN
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 22 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 22 -j RETURN
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 25 -j MARK --set-mark 4
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 25 -j RETURN
iptables -t mangle -A PREROUTING -p udp -m udp --dport 53 -j MARK --set-mark 1
iptables -t mangle -A PREROUTING -p udp -m udp --dport 53 -j RETURN
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 80 -j MARK --set-mark 3
iptables -t mangle -A PREROUTING -p tcp -m tcp --dport 80 -j RETURN
iptables -t mangle -A PREROUTING -p tcp -m tcp -s 192.168.0.110 -d 192.168.1.111 --dport 8081 -j MARK --set-mark 3
iptables -t mangle -A PREROUTING -p tcp -m tcp -s 192.168.0.110 -d 192.168.1.111 --dport 8081 -j RETURN
iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 22 -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p tcp -m tcp --dport 22 -j RETURN
iptables -t mangle -A OUTPUT -p icmp -j MARK --set-mark 1
iptables -t mangle -A OUTPUT -p icmp -j RETURN
iptables -t mangle -A OUTPUT -p tcp -m length --length :64 -j MARK --set-mark 2
iptables -t mangle -A OUTPUT -p tcp -m length --length :64 -j RETURN
iptables -t mangle -A PREROUTING -i $DEV -j MARK --set-mark 6
iptables -t mangle -A PREROUTING -i $DEV -j LOG
echo "标记完毕! mangle mark done!"
}
我使用ttcpw来收发包,使数据包走1:21分类,当其rate设置100M以下时,结果很准确,一旦超过100M时,无论是tc还是ttcpw统计出来的速率只有四五十兆。我的三台实验机器网卡均为千兆,彼此用交叉线直连。
请大家帮帮忙,知道原因的回一声,谢谢! |
|