In the absence of infinite bandwidth there will always be a need to hand out capacity accord-
ing to rules. Traditionally this has been a main reason to add non-IP technology to a network,
like ATM or frame relay. Since IP is steadily taking over the world, Linux is well placed to
play a role in enabling IP to take over traffic controlling functions from other technologies.
What is qdisc??
• Queueing Discipline(qdisc) :An algorithm that manages the queue of a device, either in-
coming (ingress) or outgoing (egress).
• Classless qdisc A qdisc with no configurable internal subdivisions.
• Classful qdisc A classful qdisc contains multiple classes. Each of these classes
contains a further qdisc, which may again be classful, but need not be.
Some Important Available Queueing Disciplines
• pfifo_fast
• Token Bucket Filter(TBF)
• Stochastic Fairness Queueing
• Prio
• CBQ
• Hierarchical Token Bucket(HTB)
Token Bucket (TB){Analogy Used in Shaping Traffic}
A token bucket is nothing but a common algorithm used to control the amount of data that is injected into a network, allowing for bursts of data to be sent. It is used for network traffic shaping or rate limiting. With token bucket you can define the maximum rate of traffic allowed on an interface at a given moment in time.
tokens/sec
| |
| | Bucket to
| | to hold b tokens
+======+=====+
|
|
| \|/
Packets | +============+
stream | ---> | token wait | ---> Remove token ---> eth0
| +============+
- The TB filter puts tokens into the bucket at a certain rate.
- Each token is permission for the source to send a specific number of bits into the network.
- Bucket can hold b tokens as per shaping rules.
- Kernel can send packet if you've a token else traffic need to wait.
Tc is used to configure Traffic Control in the Linux kernel. Traffic Control consists of the following:
- SHAPING
- When traffic is shaped, its rate of transmission is under control. Shaping may be more than lowering the available bandwidth - it is also used to smooth out bursts in traffic for better network behaviour. Shaping occurs on egress.
- SCHEDULING
- By scheduling the transmission of packets it is possible to improve interactivity for traffic that needs it while still guaranteeing bandwidth to bulk transfers. Reordering is also called prioritizing, and happens only on egress.
- POLICING
- Where shaping deals with transmission of traffic, policing pertains to traffic arriving. Policing thus occurs on ingress.
- DROPPING
- Traffic exceeding a set bandwidth may also be dropped forthwith, both on ingress and on egress.
- Processing of traffic is controlled by three kinds of objects: qdiscs, classes and filters.
- Example Problem: We have two customers, A and B, both connected to the internet via eth0. We want to allocate 60 kbps to B and 40 kbps to A. Next we want to subdivide A's bandwidth 30kbps for WWW and 10kbps for everything else. Any unused bandwidth can be used by any class which needs it (in proportion of its allocated share).
- tc qdisc add dev eth0 root handle 1: htb default 12
- This command attaches queue discipline HTB to eth0 and gives it the "handle" 1:. This is just a name or identifier with which to refer to it below. The default 12 means that any traffic that is not otherwise classified will be assigned to class 1:12
tc class add dev eth0 parent 1: classid 1:1 htb rate 100kbps ceil 100kbps tc class add dev eth0 parent 1:1 classid 1:10 htb rate 30kbps ceil 100kbps tc class add dev eth0 parent 1:1 classid 1:11 htb rate 10kbps ceil 100kbps tc class add dev eth0 parent 1:1 classid 1:12 htb rate 60kbps ceil 100kbps
The first line creates a "root" class, 1:1 under the qdisc 1:. The definition of a root class is one with the htb qdisc as its parent. A root class, like other classes under an htb qdisc allows its children to borrow from each other, but one root class cannot borrow from another. We also have to describe which packets belong in which class. This is really not related to the HTB qdisc.
tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 \ match ip src 1.2.3.4 match ip dport 80 0xffff flowid 1:10 tc filter add dev eth0 protocol ip parent 1:0 prio 1 u32 \ match ip src 1.2.3.4 flowid 1:11
(We identify A by its IP address which we imagine here to be 1.2.3.4.) - u32 is a filter that matches on IP destination port 80 *exactly* and send it to band 1:10 and 1:11.
No comments:
Post a Comment