Traffic Control manual page: TC

Source: Internet
Author: User
Summary
  
TC is a tool for setting Linux kernel traffic control.
  
Name
TC-display/maintain traffic control settings
Summary
 
TC qdisc [add | change | replace | link] Dev [Parent qdisc-ID |
Root] [Handle qdisc-id] qdisc [qdisc specific parameters]
  
TC class [add | change | replace] Dev parent qdisc-ID [classid class-id] qdisc [qdisc specific parameters]
  
 
TC filter [add | change | replace] Dev [Parent qdisc-ID | Root
] Protocol protocol PRIO priority filtertype [filtertype specific
Parameters] flowid flow-ID
  
TC [-S |-D] qdisc show [Dev]
  
TC [-S |-D] class show Dev TC filter show Dev
  
  
Introduction
TC is used for traffic control of Linux kernel. Traffic control includes the following methods:
  
Shaping (Restriction)
When the traffic is limited, its transmission rate is controlled below a certain value. The limit value can be much smaller than the valid bandwidth, so that the traffic burst can be smooth and the network is more stable. Shaping only applies to outbound traffic.
  
Scheduling (scheduling) Network Management home www.bitscn.net

By transmitting scheduled data packets, you can allocate bandwidth within the bandwidth range according to the priority. Scheduling is only suitable for outbound traffic.
  
Grouping ing (Policy)
Shaping is used to process outbound traffic, while policiing is used to process received data.
  
Dropping)
If the traffic exceeds a specified bandwidth, the packet is discarded, whether in or out.
  
Traffic processing is controlled by three types of objects: qdisc (queuing rules), Class (category), and filter (filter ).
  
Qdisc (queuing Rules)
 
Qdisc (queuing rule) is short for queueing discipline. It is a traffic
Control. At any time, if the kernel needs to send packets through a network interface, it needs to add the packets to the queue according to the qdisc (queuing rule) configured for this interface. However
Then, the kernel extracts data packets from qdisc as much as possible and delivers them to the Network Adapter Driver Module.
The simplest qdisc is pfifo, which does not process any incoming data packets. data packets are first-in-first-out in the queue. However, it will save packets that cannot be processed by the network interface at the moment.
  
  
Class)
Some qdisc (queuing rules) can contain some categories, and different categories can contain more in-depth qdisc (queuing Rules ), the subdivided qdisc can also queue data packets in the queue. By setting the Departure Order of various types of data packets, qdisc can set the priority of network data traffic. China Network Management Alliance bitscn.com
  
Filter)
 
Filters are used to classify data packets and determine which qdisc they follow to enter the queue. Data packets must be classified whenever they enter the category of a subclass. Classification Method
There can be multiple types. Using fileter is one of them. When the filter is used for classification, the kernel will call all the filters attached to this class
Return a decision. If no decision is returned, further processing is performed, and the processing method is related to qdisc.
It should be noted that filters are in qdisc and cannot act as subjects.
  
  
Classless qdisc (qdisc cannot be classified)
Non-category qdisc includes:
[P | B] FIFO
Use the simplest qdisc, pure first-in-first-out. There is only one parameter: limit, which is used to set the queue length. pfifo is based on the number of data packets; bfifo is based on the number of bytes.
Pfifo_fast
 
When you compile the kernel
Router) Compilation option. pfifo_fast is the standard qdisc of the system. Its Queue includes three bands ). Use the FIFO rule in each band. And three
The band priority is also different. Band 0 has the highest priority and Band 2 has the lowest priority. If the band contains data packets, the system will not process the band.
The data packets in 1 are the same between Band 1 and Band 2. The data packet is based on the service type (type
Service, TOS) is allocated in three more bands. Network Management ujia U. bitscn @ com
Red
Red is short for Random Early Detection (Random Early Detection. If this qdisc is used, when the bandwidth usage is close to the specified bandwidth, the system will randomly discard some data packets. It is ideal for high-bandwidth applications.
SFQ
SFQ is short for Stochastic fairness queueing. It sorts the traffic by session (Session-corresponding to each TCP connection or UDP stream) and sends packets for each session cyclically.
TBF
TBF is short for token bucket filter and is suitable for reducing the flow rate to a certain value.
Configuration of qdisc that cannot be classified
If no classifier qdisc is available, the classifier qdisc can only be attached to the root of the device. Their usage is as follows:
TC qdisc add Dev root qdisc QDISC-PARAMETERS
  
To delete an unclassified qdisc, run the following command:
  
TC qdisc del Dev Root
  
If no qdisc is set on a network interface, pfifo_fast serves as the default qdisc.
  
  
Classful qdisc (classification qdisc)
Classifier qdisc includes:
CBQ
 
CBQ is class based
The abbreviation of queueing. It implements a rich structure of Connection Sharing categories, including the ability to restrict bandwidth and manage bandwidth priorities. Tape
The Width limit is completed by calculating the idle time of the connection. The idle time is calculated based on the frequency of data packet departure events and the bandwidth of lower-layer connections (data link layer. Www.bitscn.com
Htb
 
Htb is hierarchy token
The abbreviation of a bucket. Through improvement on the basis of practice, it realizes a rich Connection Sharing category system. Using htb can easily ensure the bandwidth of each category, although it also allows a specific class
In order to break through the upper limit of bandwidth and use other types of bandwidth. Htb can use TBF (token bucket filter) to limit the bandwidth and classify the priorities.
Prio
 
Prio qdisc does not limit the bandwidth because packets of different categories are separated sequentially. Use PRIO
Qdisc can easily manage the traffic priority. Only data packets of the high-priority type are sent after they are all sent. To facilitate management, you need to use
Type of service (ToS) for iptables or ipchains to process data packets ).
Operating principle
Classes form a tree. Each class has only one parent class, and a class can have multiple child classes. Some qdisc (such as CBQ and htb) allow dynamic addition of classes at runtime, while other qdisc (such as PRIO) do not allow dynamic creation of classes.
The qdisc that allows dynamic addition of classes can have zero or more sub-classes, Which queue data packets.
  
In addition, each class has a leaf qdisc. By default, this leaf qdisc queues in pfifo mode. We can also use other types of qdisc to replace this default qdisc. In addition, the leaf qdisc can be classified, but each subclass can only have one leaf qdisc. Network Management Alliance bitscn @ com
  
When a data packet enters a classification qdisc, it is classified into a subclass. We can use the following three methods to classify data packets, but not all qdisc can use these three methods.
  
TC Filter)
If a filter is attached to a class, related commands query them. The filter can match all the fields of the data packet header, or the tags made by ipchains or iptables.
Type of service)
Some qdisc have built-in rules based on the type of service (ToS) for data packet classification.
SKB-> priority
User space applications can use the so_priority option to set a class ID in the SKB-> priority field.
Each node of the tree can have its own filter, but the high-level filter can also be directly used for its subclass.
If the data packet is not successfully classified, it will be ranked in the leaf qdisc of this class. The relevant details are on the qdisc manual page.
  
  
Naming rules
All qdisc, classes, and filters have IDs. The ID can be set manually or automatically assigned by the kernel.
An ID consists of a master serial number and a slave serial number. The two numbers are separated by a colon.
  
  
Qdisc
A qdisc is assigned a master serial number, called a handle, and uses the slave serial number as the class namespace. The handle is expressed in the same way as 10. Traditionally, You need to explicitly allocate a handle to qdisc with sub-classes. Network Management friend network www_bitscn_net

  
Class)
The class in the same qdisc shares the master serial number of the qdisc, but each class has its own serial number, which is called the Class Identifier (classid ). The Class Identifier is only related to the parent qdisc and has nothing to do with the parent class. The naming conventions of classes are the same as those of qdisc.
  
Filter)
The ID of a filter consists of three parts, which are used only when the filter is hashed. For more information, see the TC-filters manual page.
Unit
All parameters of the TC command can use floating-point numbers, which may involve the following count units.
Bandwidth or flow rate unit:
  
Kbps
Kilobytes/second
Mbps
MB/second
Kbit
Kbits/s
Mbit
Mbits/s
BPS or a number without Unit
Bytes/second
Data quantity unit:
  
Kb or K
Kilobytes
MB or m
MB
Mbit
MB
Kbit
Kilobytes
B or a number without Unit
Bytes
Unit of measurement of time:
S, SEC, or secs
Seconds
Ms, msec, or msecs
Minutes
Us, USEC, usecs, or a non-unit number
Microseconds
  
TC command
TC can use the following command to operate on qdisc, classes, and filters:
Add Network Management ujia www.bitscn.net

 
Add a qdisc, class, or filter to a node. When adding a parameter, you must pass an ancestor as the parameter. When passing the parameter, you can either use ID or directly pass the root of the device. If you want to create
You can use a handle (handle) to name a qdisc or filter. If you want to create a class, you can use the Class Identifier (classid) to name it.
  
Remove
Delete the qdisc specified by a handle. The root qdisc (Root) can also be deleted. All sub-classes on the deleted qdisc and filters attached to each class are automatically deleted.
  
Change
Modify some entries in an alternative way. Except for handle and ancestor, the syntax of the change command is the same as that of the add command.

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.