sip server 的 Qos 实现实例

来源:互联网 发布:佳能ip1180打印机端口 编辑:程序博客网 时间:2024/05/20 11:23


There are three types of traffic - RTP, Signalling and Others. Now, the Bandwidth proportion for the three types of traffic are fixed.


Qos 默认没开启:


# tc qdisc ls dev eth2
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
#
# tc qdisc ls dev eth0
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
#
# tc class ls dev eth2
#
# tc class ls dev eth0
#
# tc filter ls dev eth2
#
# tc filter ls dev eth0
#

# iptables -t mangle -nvL --line-numbers
Chain PREROUTING (policy ACCEPT 470K packets, 215M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 435K packets, 210M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 2329 packets, 227K bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 118K packets, 66M bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     3728  236K MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:53 MARK set 0x7
2        1    40 MARK       2    --  *      *       0.0.0.0/0            0.0.0.0/0           MARK set 0x7
3        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:161 MARK set 0x7
4        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:520 MARK set 0x7
5        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpts:67:68 MARK set 0x7
6        0     0 MARK       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp spt:30005 MARK set 0x7

Chain POSTROUTING (policy ACCEPT 175K packets, 109M bytes)
num   pkts bytes target     prot opt in     out     source               destination         
#

开启Qos 的 Bandwidth control,设置如下

RTP packets has the highest priority. 1/2 bandwidth is reserved;

Signalling has the second priority. 7/16 bandwidth is reserved;

1/16 bandwidth is reserved for Others;

Upstream Bandwidth 1 M

Downstream Bandwidth 10M


删除原来的iptables mangle 设置:

iptables -t mangle -D POSTROUTING -p udp --sport 5070 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -D POSTROUTING -p udp --sport 5060 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -D POSTROUTING -p udp --sport 30000:30060  -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -D POSTROUTING -p udp --sport 35000:38000 -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -D OUTPUT -p udp --sport 5070 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -D OUTPUT -p udp --sport 5060 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -D OUTPUT -p udp --sport 30000:30060  -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -D OUTPUT -p udp --sport 35000:38000 -j MARK --set-mark 0x3 2>/dev/null
tc qdisc del dev br0 root 2>/dev/null
tc qdisc del dev eth2 root 2>/dev/null

新的iptables mangle 设置:
iptables -t mangle -A POSTROUTING -p udp --sport 5070 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -A POSTROUTING -p udp --sport 5060 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -A POSTROUTING -p udp --sport 30000:30060  -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -A POSTROUTING -p udp --sport 35000:38000 -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -A OUTPUT -p udp --sport 5070 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -A OUTPUT -p udp --sport 5060 -j MARK --set-mark 0x2 2>/dev/null
iptables -t mangle -A OUTPUT -p udp --sport 30000:30060  -j MARK --set-mark 0x3 2>/dev/null
iptables -t mangle -A OUTPUT -p udp --sport 35000:38000 -j MARK --set-mark 0x3 2>/dev/null

Wan口的设置:
device=eth2, totalband=1024
lowband=64, middleband=448, highband=512
lowweight=896, middleweight=1024, highweight=1024


tc qdisc add dev eth2 root handle 1: htb default 15
tc class add dev eth2 parent 1: classid 1:1 htb rate 1024kbit ceil 1024kbit
tc class add dev eth2 parent 1:1 classid 1:10 htb rate 512kbit ceil 1024kbit prio 1
tc class add dev eth2 parent 1:1 classid 1:12 htb rate 448kbit ceil 1024kbit prio 2  
tc class add dev eth2 parent 1:1 classid 1:15 htb rate 64kbit ceil 896kbit prio 3  
tc qdisc add dev eth2 parent 1:15 handle 150: sfq  quantum 1514b perturb 15
tc filter add dev eth2 parent 1:0 protocol ip prio 0 handle 3 fw classid 1:10
tc filter add dev eth2 parent 1:0 protocol ip prio 2 handle 2 fw classid 1:12

Lan口的设置:

device=br0, totalband=10240
lowband=640, middleband=4480, highband=5120
lowweight=8960, middleweight=10240, highweight=10240

tc qdisc add dev br0 root handle 1: htb default 15
tc class add dev br0 parent 1: classid 1:1 htb rate 10240kbit ceil 10240kbit
tc class add dev br0 parent 1:1 classid 1:10 htb rate 5120kbit ceil 10240kbit prio 1
tc class add dev br0 parent 1:1 classid 1:12 htb rate 4480kbit ceil 10240kbit prio 2  
tc class add dev br0 parent 1:1 classid 1:15 htb rate 640kbit ceil 8960kbit prio 3  
tc qdisc add dev br0 parent 1:15 handle 150: sfq  quantum 1514b perturb 15
tc filter add dev br0 parent 1:0 protocol ip prio 0 handle 3 fw classid 1:10
tc filter add dev br0 parent 1:0 protocol ip prio 2 handle 2 fw classid 1:12

#
#


查看结果


# tc qdisc ls dev eth2
qdisc htb 1: r2q 10 default 15 direct_packets_stat 0
qdisc sfq 150: parent 1:15 limit 128p quantum 1514b perturb 15sec
#
# tc qdisc ls dev eth0
qdisc pfifo_fast 0: root bands 3 priomap  1 2 2 2 1 2 0 0 1 1 1 1 1 1 1 1
#
# tc class ls dev eth2
class htb 1:10 parent 1:1 prio 1 rate 512000bit ceil 1024Kbit burst 1664b cburst 1728b
class htb 1:1 root rate 1024Kbit ceil 1024Kbit burst 1728b cburst 1728b
class htb 1:12 parent 1:1 prio 2 rate 448000bit ceil 1024Kbit burst 1655b cburst 1728b
class htb 1:15 parent 1:1 leaf 150: prio 3 rate 64000bit ceil 896000bit burst 1608b cburst 1711b
#
# tc class ls dev eth0
#
# tc filter ls dev eth2
filter parent 1: protocol ip pref 2 fw
filter parent 1: protocol ip pref 2 fw handle 0x2 classid 1:12
filter parent 1: protocol ip pref 49152 fw
filter parent 1: protocol ip pref 49152 fw handle 0x3 classid 1:10
#
# tc filter ls dev eth0
#



# iptables -t mangle -nvL --line-numbers
Chain PREROUTING (policy ACCEPT 944 packets, 487K bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 920 packets, 483K bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 17 packets, 1198 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 934 packets, 457K bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1       81  4985 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpt:53 MARK set 0x7
2        6   240 MARK       2    --  *      *       0.0.0.0/0            0.0.0.0/0           MARK set 0x7
3        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:161 MARK set 0x7
4        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:520 MARK set 0x7
5        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp dpts:67:68 MARK set 0x7
6        0     0 MARK       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp spt:30005 MARK set 0x7
7        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:5070 MARK set 0x2
8       57 26789 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:5060 MARK set 0x2
9        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spts:30000:30060 MARK set 0x3
10       0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spts:35000:38000 MARK set 0x3

Chain POSTROUTING (policy ACCEPT 1302 packets, 687K bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:5070 MARK set 0x2
2       57 26789 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spt:5060 MARK set 0x2
3        0     0 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spts:30000:30060 MARK set 0x3
4        2   124 MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0           udp spts:35000:38000 MARK set 0x3
#

# ip route
10.0.0.0/24 dev br0  proto kernel  scope link  src 10.0.0.55
192.168.1.0/24 dev eth2  proto kernel  scope link  src 192.168.1.55
192.168.1.0/24 via 192.168.1.133 dev eth2  metric 1
default via 192.168.1.133 dev eth2
#






原创粉丝点击