Linux bandwidth management system

Source: Internet
Author: User

Original Linux inventory
Http://www.linuxmine.com
Linux contains the complex bandwidth management system Tc (traffic control, traffic control ). The system supports classification, priority, sharing, input, and output traffic limits. This system is comparable to a dedicated bandwidth management system.
1. Basic Components
TC consists of three basic components: queueing discipline, class, and classifiers ).
The queue rules can be viewed as the device's traffic/data packet manager. The queue rules encapsulate the other two main TC components (classes and classifiers) to control data flow.
Currently, some device queue rules can be used to manage devices, including CBQ, priority, and CSZ (Clark-Shenker-Zhang. CBQ is the ultimate queue, that is, it can contain other queues (or even other CBQ ).
Classes are managed by device queue rules. A class consists of several rules used to manage the data owned by the class. For example, all data packets in a certain type are at a rate of 1 Mbps, and a maximum of 3 Mbps is allowed within a period of time between midnight and AM.
Some queue rules can be bound to classes, including FIFO (first-in-first-out), red (Random Early Detection), SFQ (random fair queue), and token bucket ).
If no queue rules are bound to the device, use the basic FIFO. In addition, CBQ, CSZ, and priority can also be used for classes and subclass of classes. This indicates that TC can be used to easily build complicated traffic control. Management queue rules can be called class queueing disciplines ).
Generally, class queue rules manage the data and queue of the class, and decide to delay, discard or re-classify the packages managed by the class. Classifier or filter description package and map them to classes managed by queue rules.
These filters generally provide a simple description language, specifying the methods for selecting packages and ing packages to classes.
Currently, TC can use the following filters: fwmark classifier, u32 classifier, route-based classifier, And rsvp classifier (for IPv6 and IPv4 respectively, the fwmark classifier allows us to use the Linux netfilter code to select traffic, while the u32 classifier allows us to select traffic based on the any header. All firewall filters, such as ipchains, can be used to classify packets.
TC code is in the kernel. Different functional blocks can be compiled into modules or directly written into the kernel. And kernel code or module communication and settings are completed by user-level program TC.
2. Example
2.1 compile the kernel
First, make sure to select the kernel/user netlink socket, because only in this way can TC communicate with the kernel through Netlink.
Then, the queue rules and classifier are compiled into the kernel. These include:
QoS or fair queueing, CBQ packet scheduler, CSZ packet scheduler, the simplest PRIO pseudo doscheduler, red queue, SFQ queue, TBF queue, QoS support, rate estimator, packet classifier API, routing-tables-based classifier, u32 classifier, special RSVP classifier, and special RSVP classifier for IPv6.
Then the compilation and installation processes are well known.
2.2 Creation
[Internet] --- <E3, T3, etc.> --- [Linux router] --- [Office + ISP]
Eth1 eth0
The Linux router in has two interfaces, eth0 and eth1. Eth1 is connected to the vro, and eth0 is connected to the subnet, including the company firewall.
Since we can only limit the content to be sent, we need two independent but possibly very similar rule sets. We can change the sending order to control the transmission rate. By modifying the queue on eth0, we can determine the download rate of the customer. By modifying the queue on eth1, we can determine the upload rate of our own user (upload) speed.
For example, the company's Internet connection bandwidth is 10 MB, meeting the needs of external customers and their own users; at this time, we need a strategy for management and coordination. CBQ can meet our needs.
We have two main classes: 'isp 'and 'Office '. We can decide that the customer has 8 MB of bandwidth and the office user has 2 MB of bandwidth.
First, we will release the following command:
# TC qdisc add Dev eth0 root handle 10: CBQ bandwidth 10 Mbit avpkt 1000
The meaning is: we set the queue rule of eth0. Root indicates that this is the root rule, and its handle is set to 10 :'. Its type is CBQ. The bandwidth is 10 MB, and the average package size is 1000 bytes.
The following generates the root class ):
# TC class add Dev eth0 parent classid CBQ bandwidth 10 Mbit Rate
10 Mbit allot 1514 weight 1 Mbit PRIO 8 maxburst 20 avpkt 1000
This command actually has more meaning than the previous command. Among them, 1514 is the MTU value.
The following is an ISP class:
# TC class add Dev eth0 parent 10classid CBQ bandwidth 10 Mbit Rate
8 Mbit allot 1514 weight 800 kbit PRIO 5 maxburst 20 avpkt 1000 bounded
We allocated 8 MB of bandwidth to Him, and bounded indicates that this class cannot exceed this threshold value.
The following is an office class:
# TC class add Dev eth0 parent 10classid CBQ bandwidth 10 Mbit Rate
2 Mbit allot 1514 weight 200 kbit PRIO 5 maxburst 20 avpkt 1000 bounded
For clarity, our classes can be expressed as follows:
We have notified the kernel of our class. We also need to tell the kernel how to manage the queue, as shown below:
# TC qdisc add Dev eth0 parent 10:100 SFQ quantum 1514b perturb 15
# TC qdisc add Dev eth0 parent 10:200 SFQ quantum 1514b perturb 15
Here, we use the random fair queue (SFQ), and its performance is acceptable when the CPU consumption cycle is small. Some other queue rules may be better, but they need to occupy a large amount of CPU resources. The token bucket filter is also frequently used.
One more thing is to do: Tell the ing between the kernel Network Package and the class.
# TC filter add Dev eth0 parent 10:0 Protocol ip prio 100 u32 Match ip DST
150.151.23.24 flowid 10:200
# TC filter add Dev eth0 parent 10:0 Protocol ip prio 25 u32 Match ip DST
150.151.0.0/16 flowid 10: 100
Here, we assume that the Office is behind the firewall 150.151.23.24, and other IP addresses belong to the ISP. U32 matching is a simple match. We can use netfilter to generate more complex matching rules.
We have allocated the download bandwidth. below is the allocation of the upload bandwidth:
# TC qdisc add Dev eth1 root handle 20: CBQ bandwidth 10 Mbit avpkt 1000
# TC class add Dev eth1 parent 20:0 classid 20:1 CBQ bandwidth 10 Mbit Rate
10 Mbit allot 1514 weight 1 Mbit PRIO 8 maxburst 20 avpkt 1000
# TC class add Dev eth1 parent 20:1 classid 20:100 CBQ bandwidth 10 Mbit Rate
8 Mbit allot 1514 weight 800 kbit PRIO 5 maxburst 20 avpkt 1000
Bounded
# TC class add Dev eth1 parent 20:1 classid 20:200 CBQ bandwidth 10 Mbit Rate
2 Mbit allot 1514 weight 200 kbit PRIO 5 maxburst 20 avpkt 1000
Bounded
# TC qdisc add Dev eth1 parent 20:100 SFQ quantum 1514b perturb 15
# TC qdisc add Dev eth1 parent 20:200 SFQ quantum 1514b perturb 15
# TC filter add Dev eth1 parent 20:0 Protocol ip prio 100 u32 Match ip SRC
150.151.23.24 flowid 20:200
# TC filter add Dev eth1 parent 20:0 Protocol ip prio 25 u32 Match ip SRC
150.151.0.0/16 flowid 20:100
This is basically the same as the previous description, so I will not explain it more.
Note:
In the previous example, we noticed that even if most ISP customers are offline, our office users still only have 2 Mbps of bandwidth, which is a waste. We can delete the 'bounded' parameter so that various types can borrow bandwidth from each other.
However, some classes may not want to borrow bandwidth from other classes. For example, two ISP lines on one line are opposite to each other. In this case, we can add the keyword 'isolated '.
3. Conclusion
Currently, QoS (Service Quality) provided by Linux is the most complex and complete among all operating systems. In addition, BSD's altq should also be said to be quite good; however, it is far behind Linux in terms of complexity, flexibility, and scalability. I am not clear about whether Microsoft products provide such functions. Sun's Solaris provides CBQ and RSVP functions.
Linux also supports the DiffServ feature of IETF. Linux has many features in QoS, which will greatly increase the market share of Linux.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.