Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We are developing a client/server applications. There are three types of network data in our server app: Realtime data such as those of Video/audio, Critical Data such as those of Database data and BestEfforts data as those of common file transfer.

We plan to set the QOS field of each IP packet to indicate which data type of the above three the ip packet belongs to, then use TC to set different Maximum rates for these three types of data.

As far as I know setting qos field is viable, but I wonder if we can limit the rate of ip packets by specifying qos value (the value of QOS field in IP header).

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

I guess you mean 8-bit TOS field in IPv4 packet header. Have you alread read LARTC HOWTO? This is the guide you definitely need to read. Briefly, you need to

1) Define QDISCs and CLASSes in which traffic is classified, prioritized and shaped (egress traffic can be shaped only !!!). In general, any packet which needs to be sent is enqueued to QDISC of network interface.

CEIL=10
tc qdisc add dev eth0 root handle 1: htb default 15
tc class add dev eth0 parent 1: classid 1:1 htb rate ${CEIL}mbit ceil ${CEIL}mbit
tc class add dev eth0 parent 1:1 classid 1:10 htb rate 4mbit ceil ${CEIL}mbit prio 0
tc class add dev eth0 parent 1:1 classid 1:11 htb rate 1mbit ceil ${CEIL}mbit prio 1
tc class add dev eth0 parent 1:1 classid 1:12 htb rate 6mbit ceil ${CEIL}mbit prio 2
tc qdisc add dev eth0 parent 1:11 handle 110: sfq perturb 10
tc qdisc add dev eth0 parent 1:12 handle 120: sfq perturb 10

Classes with lower prio field are tried first. So the class 1:10 may be dedicated for packets requiring e.g. minimum delay. The classes 1:11 and 1:12 have attached SFQ queuing discipline to ensure more fair bandwidth sharing.

2) Define FILTERs to enqueue a packet to the right CLASS.

tc filter add dev eth0 parent 1:0 protocol ip prio 1 handle 10 fw classid 1:10
tc filter add dev eth0 parent 1:0 protocol ip prio 2 handle 11 fw classid 1:11
tc filter add dev eth0 parent 1:0 protocol ip prio 3 handle 12 fw classid 1:12

This simply tells that a packet with mark 10 goes to class 10 and so on.

3) Define iptables rules to mark a packet to enqueue it to the right CLASS

iptables -t mangle -A PREROUTING -m tos --tos Minimize-Delay -j MARK --set-mark 0x10
iptables -t mangle -A PREROUTING -m tos --tos Minimize-Cost -j MARK --set-mark 0x11
iptables -t mangle -A PREROUTING -m tos --tos Maximize-Throughput -j MARK --set-mark 0x12

I use iptables tos module on purpose to show you how you can match specific values of TOS field and mark it accordingly. For more about this module run

iptables -m tos --help
share|improve this answer
    
What does it mean of "ip prio 1", don't we need to use statements such as "protocol ip u32 match ip xxxxx xxxx" where "xxxx xxxx" specifies the QOS value in the IP header?? –  Steve Peng Sep 12 '13 at 11:37
    
The prio specifies a priority the same way like for class. This means which filter is tried first and so on. Yep, you can use u32 classifier instead of iptables but I personally prefer iptables as it's more convenient. –  dsmsk80 Sep 12 '13 at 12:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.