Translation(s): none


TC Overview

Traffic Control (tc) used to control network traffic.

Installation

TC bundled with iproute package in Debian.

# apt-get install iproute

Queueing Disciplines

We can only shape data that we transmit. Using queueing we control the data flow.

In a router you might want control the traffic distributing inside your network. Several queueing disciplines (qdisc) can be used with tc. Choose a qdisc based on your requirements.

Simple Classless Queueing Disciplines

It has no configurable internal subdivisions. The classless queueing disciplines accept data, then reschedule, delay or drop based on queueing disciplines (qdisc).

Token Bucket Filter (TBF)

Simple and easy, for slowing an interface down. TBF for details.

#tc qdisc add dev eth1 root tbf rate 220kbit latency 50ms burst 1540 

explanation:

qdisc - queueing discipline 
latency - number of bytes that can be queued waiting for tokens to become available.
burst - Size of the bucket, in bytes.
rate - speedknob

Stochastic Fairness Queueing (SFQ)

Round robin type, provide each session the chance to send data in turn. It changes its hashing algorithm within an interval. No single session will able to dominate outgoing bandwidth. SFQ for details.

#tc qdisc add dev eth1 root sfq perturb 10

explanation:

qdisc - queuing discipline 
perturb - Reconfigure hashing once this many seconds.

Testing Classless Queueing

To check the status run:

#tc -s -d qdisc show dev eth1

To remove it:

#tc qdisc del dev eth1 root

Classful Queueing Disciplines

It helps to set different kinds of traffic priority. Classful Queueing for details.

Hierarchical Token Bucket (HTB)

Let assume we want to create some rules for a small office using HTB. HTB manual from devik for details.

tc qdisc example

attachment:tc_qdisc_example_implementation.png

eth0 - external interface - PUBLIC_IP 
eth1 - internal interface - LOCAL_IP 

Email will get the highest priority
General/Other will get the medium priority.
Video streaming will get the lowest priority.

Creating root 1: and 1:1 using HTB (default 6 means follow 1:6 if no rule matched)

#tc qdisc add dev eth1 root handle 1: htb default 6
#tc class add dev eth1 parent 1: classid 1:1 htb rate 2mbit ceil 2mbit

Creating leaf class 1:5 (prio represents priority, and 0 means high priority)

#tc class add dev eth1 parent 1:1 classid 1:5 htb rate 1mbit ceil 1.5mbit
#tc filter add dev eth1 protocol ip parent 1:0 prio 0 u32 match ip src YOUR_MAIL_SERVER_IP/32 flowid 1:5
#tc filter add dev eth1 protocol ip parent 1:0 prio 0 u32 match ip sport 22 0xffff flowid 1:5

Creating leaf class 1:6 (It is set as default in root qdisc, so we are not setting any rules)

#tc class add dev eth1 parent 1:1 classid 1:6 htb rate 0.5mbit ceil 1.5mbit

Creating leaf class 1:7 (use /32 for specific IP, /24 for that series. Priority low - prio 5. You can get the IP address using "iptraf" tool)

#tc class add dev eth1 parent 1:1 classid 1:7 htb rate 0.2mbit ceil 1mbit
#tc filter add dev eth1 protocol ip parent 1:0 prio 5 u32 match ip src VIDEO_STREAM_IP/32 flowid 1:7

Optionally we can also add discipline with leaf (for an example we are adding SFQ with leaf class 1:5)

#tc qdisc add dev eth1 parent 1:5 handle 20: sfq perturb 10

To remove it:

#tc qdisc del dev eth1 root handle 1: htb 


See:


CategorySystemAdministration