Linux starts support QoS from Kernel 2.1.105, but you need to recompile the kernel. When running make config, set the experimental _options to Y, and set class based queueing (CBQ), TOKEN BUCKET FLOW, Traffic Shapers to Y, run make dep; make clean; make bzilo, generate a new kernel. In the Linux operating system, the traffic controller (TC) is mainly to establish a queue at the output port for flow control, and the method of control is based on the route, that is, the traffic control of the network number based on the purpose IP address or destination subnet. Flow controller TC, its basic function module is queue, classification, and filter. Linux kernels supported queues, Class Based Queue, Token Bucket Flow, CSZ, First In First Out, Priority, Teql, SFQ, ATM, RED. The queues and classifications we discussed here are CBQ (Class based Queue), and the filter is based on Route. Configure and use traffic controller TC, mainly divided into the following: Its basic use steps are: 1) Bind a CBQ queue for network physical devices (such as Ethernet card eth0); 2) Creating a classification on the queue; 3) establish a routing filter for each classification; 4) Finally Compatible with the filter to establish a specific routing table. First assume a simple environment, as shown below: The IP address of the Ethernet card (Eth0) on the traffic controller is 192.168.1.66, which is built on it. CBQ queue. Assume that the average size of the package is 1000 bytes, the size of the package interval transmission unit is 8 bytes, and the maximum number of transmitted packets that can receive conflicts is 20 bytes. If there are three types of traffic need to be controlled: 1) is sent to the host 1, its IP address is 192.168.1.24. The flow rate bandwidth is controlled at 8 Mbit, priority is 2; 2) is sent to host 2, its IP address is 192.168.1.26. Its flow bandwidth is controlled at 1 Mbit, priority is 1; 3) is a subnet number of 192.168.1.0, and the subnet mask is 255.255.255.0. The flow bandwidth is controlled at 1 Mbit, the priority is 6. 1. Establish a queue in general, just create a queue for a network card. Bind a CBQ queue to the network physical device Eth0, its number is 1: 0; the actual bandwidth of the network physical device ETH0 is 10 mbit, the average size of the package is 1000 bytes; the size of the package interval transmission unit is 8 bytes. The minimum transmission package is 64 bytes. · TC QDISC Add dev eth0 root handle 1: CBQ Bandwidth 10Mbit Avpkt 1000 Cell 8 MPU 64 2. Establishing a classification classification is built on the queue. In general, a queue needs to establish a root classification and then build sub-categories there. For classification, the number is actuated in the order of its classification, the number is small; once it conforms to a classification matching rule, the data packet is sent by this classification, and the subsequent classification is no longer played. 1) Create root category 1: 1; allocate bandwidth of 10Mbit, priority is 8.
· TC Class Add Dev Eth0 Parent 1: 0 ClassID 1: 1 CBQ Bandwidth 10 Mbit Rate 10Mbit Maxburst 20 Allot 1514 PRIO 8 AVPKT 1000 Cell 8 Weight 1Mbit This queue is 10Mbit, the actual allocated bandwidth is 10Mbit, can receive conflicts The maximum number of transmitted packets is 20 bytes; the maximum transmission unit plus the MAC head is 1514 bytes, the priority level is 8, the average size of the package is 1000 bytes, and the size of the package interval transmission unit is 8 bytes, corresponding The weight of the actual bandwidth is 1 Mbit. 2) Creating a classification 1: 2, its parent classification is 1: 1, the assigned bandwidth is 8Mbit, the priority is 2. · TC Class Add Dev Eth0 Parent 1: 1 ClassID 1: 2 CBQ Bandwidth 10 Mbit Rate 8Mbit Maxburst 20 Allot 1514 Prio 2 Avpkt 1000 Cell 8 Weight 800kbit Split 1: 0 Bounded This queue has a maximum available bandwidth of 10Mbit, the actual allocated bandwidth is 8Mbit, the maximum transmission of conflictable transmission ?????? The number of packets is 20 bytes; the maximum transmission unit plus the size of the MAC head is 1514 bytes, the priority level is 1, the average size of the package is 1000 bytes, package The size of the interval transmit unit is 8 bytes, corresponding to the actual bandwidth weight of 800 kbit, the separation point of the classification is 1: 0, and the unused bandwidth is not used. 3) Creating a classification 1: 3, its parent classification is 1: 1, the assigned bandwidth is 1 Mbit, the priority is 1. · TC Class Add Dev Eth0 Parent 1: 1 ClassID 1: 3 CBQ Bandwidth 10 Mbit Rate 1 Mbit Maxburst 20 Allot 1514 Prio 1 Avpkt 1000 Cell 8 Weight 100kbit Split 1: 0 The maximum available bandwidth of 10Mbit, the actual allocated bandwidth is 1Mbit , The maximum number of transmitted packets can be received by the conflict is 20 bytes; the maximum transmission unit plus the size of the MAC head is 1514 bytes, the priority level is 2, the average size of the package is 1000 bytes, the size of the package interval transmission unit is 8 Bytes, corresponding to the actual bandwidth weight of 100kbit, the separation point of the classification is 1: 0. 4) Creating Categories 1: 4, its parent classification is 1: 1, the assigned bandwidth is 1 Mbit, the priority is 6. · TC Class Add Dev Eth0 Parent 1: 1 ClassID 1: 4 CBQ Bandwidth 10Mbit Rate 1 Mbit Maxburst 20 Allot 1514 Prio 6 Avpkt 1000 Cell 8 Weight 100kbit Split 1: 0 The maximum available bandwidth of 10Mbit, actually allocated bandwidth is 64kbit , The maximum number of transmitted packets can be received by 20 bytes; the maximum transmission unit plus the size of the MAC head is 1514 bytes, the priority level is 1, the average size of the package is 1000 bytes, the size of the package interval transmission unit is 8 Bytes, corresponding to the actual bandwidth weight of 100kbit, the separation point of the classification is 1: 0. 3. Establish a filter filter mainly serve the classification. Generally, you only need to provide a filter for root categories and then provide routing mappings for each subclass.
1) Application Route classifier to the root of the CBQ queue, the parent classification number is 1: 0; the filter protocol is IP, the priority is 100, the filter is based on the routing table. · TC Filter Add Dev Eth0 Parent 1: 0 Protocol IP Prio 100 Route 2) Establishing Routing Map Classification 1: 2, 1: 3, 1: 4 · TC Filter Add Dev Eth0 Parent 1: 0 Protocol IP Prio 100 Route to 2 FlowID 1: 2 · TC Filter Add dev eth0 Parent 1: 0 Protocol IP PRIO 100 ROTE TO 3 FLOWID 1: 3 · TC Filter Add dev eth0 Parent 1: 0 Protocol IP PRIO 100 ROUTE TO 4 FLOWID 1: 4 4. Creating a route The route is a route mapped by the previously established. 1) Packets sent to Host 192.168.1.24 Through Classification 2 Forward (Classification 2 Rate 8Mbit) · IP Route Add 192.168.1.66 Realm 2 2) Packets sent to host 192.168.1.30 3 Forwarding (Classification 3) · IP Route Add 192.168.1.30 DEV ETH0 VIA 192.168.1.66 Realm 3 3) Packets sent to subnet 192.168.1.0/24 Through classification 4 forwarding (categorizing 4 rate 1Mbit) · IP Route Add 192.168.1.0/24 dev eth0 VIA 192.168.1.66 Realm 4 Note: Generally, the network segment directly connected to the flow controller is recommended to use IP host address traffic control limits, do not use subnet traffic control limits. If you must use subnet traffic control restrictions on Direct Line Subnet, the corresponding steps are required to be originally established by the system before the routing map of the subnet is created. 5. Monitoring mainly includes monitoring existing queues, categories, filters, and routing. 1) Show the situation of the queue Simply display the queue status of the specified device (Eth0) · TC QDISC LS dev eth0 QDISC CBQ 1: Rate 10Mbit (Bounded, ISOLATED) Prio No-Transmit Details Show the queue of the specified device (here ETH0) Status · TC -S QDISC LS dev eth0 qdisc CBQ 1: Rate 10Mbit (Bounded, Isolat ?????? Ed) Prio NO-Transmit Sent 7646731 BYtes 13232 PKTS (Dropped 0, Overlimits 0) Borrowed 0 Overactions 0 Avgidle 31 Undertime 0 Here mainly shows that 13,232 packets transmitted through the queue, the data traffic is 7646731 bytes, and the number of packets discarded is 0, and the number of packets exceeding the rate limit is 0.
2) Displaying the classification of the classification of the specified device (ETH0) Classification Status · TC Class Ls Dev Eth0 Class CBQ 1: root Rate 10Mbit (Bounded, Isolated) Prio NO-Transmit Class CBQ 1: 1 Parent 1: Rate 10Mbit PRIO NO-Transmit # no-transmit Represents the priority 8 CBQ 1: 2 Parent 1: 1 Rate 8 Mbit Prio 2 CBQ 1: 3 Parent 1: 1 Rate 1 Mbit Prio 1 Class CBQ 1: 4 Parent 1: 1 Rate 1 Mbit PRIO 6 Detailed Displays the Classification Status of Specified Devices (here ETH0) • TC -S Class Ls Dev Eth0 Class CBQ 1: Root Rate 10 Mbit (Bounded, Isolated) Prio no-Transmit Sent 17725304 Bytes 32088 PKTS (Dropped 0, Overlimits 0) borrowed 0 overactions 0 avgidle 31 undertime 0 class cbq 1: 1 parent 1: rate 10Mbit prio no-transmit Sent 16627774 bytes 28884 pkts (dropped 0, overlimits 0) borrowed 16163 overactions 0 avgidle 587 undertime 0 class cbq 1: 2 parent 1: 1 rate 8Mbit prio 2 Sent 628829 bytes 3130 pkts (dropped 0, overlimits 0) borrowed 0 overactions 0 avgidle 4137 undertime 0 class cbq 1: 3 parent 1: 1 rate 1Mbit prio 1 Sent 0 bytes 0 pkts (dropped 0, overlimits 0) Borrowed 0 Overacions 0 Avgidle 159654 Undertime 0 Class C BQ 1: 4 Parent 1: 1 Rate 1 Mbit PRIO 6 SENT 5552879 BYTES 8076 PKTS (Dropped 0, Overlimits 0) BORROWED 3797 OVERACITIONS 0 Avgidle 159557 Undertime 0 This mainly shows the data packet, data traffic, and discarded packages transmitted by different categories. Number, the number of packets exceeding the rate limit, and the like. The condition of the root classification (Class CBQ 1: 0) should be similar to the condition of the queue. For example, the classification class CBQ 1: 4 transmits 8076 packets, with a data flow rate of 55,52879 bytes, and the number of packets discarded is 0, and the number of packets exceeding the rate limit is zero. Show filter • Tc -s filter ls dev eth0 filter Parent 1: protocol ip pref 100 route filter parent 1: protocol ip pref 100 route fh 0xfffff0002 Flowid 1: 2 To 2 filter Parent 1: protocol ip pref 100 route fh 0xfff0003 Flowid 1: 3 To 3 Filter Parent 1: Protocol IP Pref 100 Route FH 0xfff0004 Flowid 1: 4 TO 4 Here FlowID 1: 2 Represents Classification CBQ 1: 2, TO 2 Represents Via Route 2 Send.
Show existing routing status · IP route 192.168.1.66 dev eth0 scope link 192.168.1.24 via 192.168.1.24 dev eth0 realm 2 2 ?????? 02.102.24.216 dev ppp0 proto kernel scope link src 202.102.76.5 192.168.1.30 via 192.168.1.66 dev eth0 realm 3 192.168.1.0/24 via 192.168.1.66 dev eth0 realm 4 192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.66 172.16.1.0/24 via 192.168.1.66 dev eth0 scope link 127.0 . 0.0 / 8 Dev LO Scope Link Default VIA 202.102.24.216 DEV PPP0 Default VIA 192.168.1.254 DEV ETH0 As shown above, the end containing a REALM display line is a routing filter. 6. Maintenance mainly includes adding, modifying, and deleting queues, categories, filters, and routing. Add actions generally in accordance with the order of "Queuing -> Classification -> Filters -> Routing"; there is no requirement; delete is performed in the order of "Routing -> Filter -> Classification -> Queu". 1) Maintenance of the queue generally configure a queue for each Ethernet card for a flow controller, usually without adding, modifying, and removing the queue without adding, modifying and deleting actions. 2) Sorting maintenance Addition adding action is implemented through the TC Class Add command, as shown in the previous. Modifying the modification action is implemented by tc class change command, as follows: • TC Class Change Dev Eth0 Parent 1: 1 ClassID 1: 2 CBQ Bandwidth 10 Mbit Rate 7Mbit Maxburst 20 Allot 1514 Prio 2 Avpkt 1000 Cell 8 Weight 700kbit Split 1: 0 Bounded Use carefully for the bounded command. Once you are added, you can only add it to be added by deleting. Deleting Deleting Actions can only be performed before the category is not working, once the data is transmitted through the classification, it cannot be deleted. Therefore, it is necessary to modify through the shell file, and the delete action is completed by restarting. 3) The maintenance of the filter is added to the TC filter add command, as shown in the previous. Modifying the modification action is implemented by the TC Filter Change command, as follows: • TC Filter Change Dev Eth0 Parent 1: 0 Protocol IP PRIO 100 ROUTE TO 10 FLOWID 1: 8 Delete Delete Action is implemented through the TC Filter Del command, as follows: · TC FILTER DEV ETH0 PARENT 1: 0 Protocol IP PRIO 100 ROUTE TO 10 4) Maintenance Addition of One Map Routing with Filters The Adding Action is implemented through the IP Route Add command, as shown in the previous.