1TC(8) Linux TC(8)
2
3
4
6 tc - show / manipulate traffic control settings
7
9 tc [ OPTIONS ] qdisc [ add | change | replace | link | delete ] dev DEV
10 [ parent qdisc-id | root ] [ handle qdisc-id ] [ ingress_block
11 BLOCK_INDEX ] [ egress_block BLOCK_INDEX ] qdisc [ qdisc specific pa‐
12 rameters ]
13
14 tc [ OPTIONS ] class [ add | change | replace | delete | show ] dev DEV
15 parent qdisc-id [ classid class-id ] qdisc [ qdisc specific parameters
16 ]
17
18 tc [ OPTIONS ] filter [ add | change | replace | delete | get ] dev DEV
19 [ parent qdisc-id | root ] [ handle filter-id ] protocol protocol prio
20 priority filtertype [ filtertype specific parameters ] flowid flow-id
21
22 tc [ OPTIONS ] filter [ add | change | replace | delete | get ] block
23 BLOCK_INDEX [ handle filter-id ] protocol protocol prio priority fil‐
24 tertype [ filtertype specific parameters ] flowid flow-id
25
26 tc [ OPTIONS ] chain [ add | delete | get ] dev DEV [ parent qdisc-id |
27 root ] filtertype [ filtertype specific parameters ]
28
29 tc [ OPTIONS ] chain [ add | delete | get ] block BLOCK_INDEX filter‐
30 type [ filtertype specific parameters ]
31
32
33 tc [ OPTIONS ] [ FORMAT ] qdisc { show | list } [ dev DEV ] [ root |
34 ingress | handle QHANDLE | parent CLASSID ] [ invisible ]
35
36 tc [ OPTIONS ] [ FORMAT ] class show dev DEV
37
38 tc [ OPTIONS ] filter show dev DEV
39
40 tc [ OPTIONS ] filter show block BLOCK_INDEX
41
42 tc [ OPTIONS ] chain show dev DEV
43
44 tc [ OPTIONS ] chain show block BLOCK_INDEX
45
46
47 tc [ OPTIONS ] monitor [ file FILENAME ]
48
49
50 OPTIONS := { [ -force ] -b[atch] [ filename ] | [ -n[etns] name ] | [
51 -N[umeric] ] | [ -nm | -nam[es] ] | [ { -cf | -c[onf] } [ filename ] ]
52 [ -t[imestamp] ] | [ -t[short] | [ -o[neline] ] }
53
54 FORMAT := { -s[tatistics] | -d[etails] | -r[aw] | -i[ec] | -g[raph] |
55 -j[json] | -p[retty] | -col[or] }
56
57
59 Tc is used to configure Traffic Control in the Linux kernel. Traffic
60 Control consists of the following:
61
62
63 SHAPING
64 When traffic is shaped, its rate of transmission is under con‐
65 trol. Shaping may be more than lowering the available bandwidth
66 - it is also used to smooth out bursts in traffic for better
67 network behaviour. Shaping occurs on egress.
68
69
70 SCHEDULING
71 By scheduling the transmission of packets it is possible to im‐
72 prove interactivity for traffic that needs it while still guar‐
73 anteeing bandwidth to bulk transfers. Reordering is also called
74 prioritizing, and happens only on egress.
75
76
77 POLICING
78 Whereas shaping deals with transmission of traffic, policing
79 pertains to traffic arriving. Policing thus occurs on ingress.
80
81
82 DROPPING
83 Traffic exceeding a set bandwidth may also be dropped forthwith,
84 both on ingress and on egress.
85
86
87 Processing of traffic is controlled by three kinds of objects: qdiscs,
88 classes and filters.
89
90
92 qdisc is short for 'queueing discipline' and it is elementary to under‐
93 standing traffic control. Whenever the kernel needs to send a packet to
94 an interface, it is enqueued to the qdisc configured for that inter‐
95 face. Immediately afterwards, the kernel tries to get as many packets
96 as possible from the qdisc, for giving them to the network adaptor
97 driver.
98
99 A simple QDISC is the 'pfifo' one, which does no processing at all and
100 is a pure First In, First Out queue. It does however store traffic when
101 the network interface can't handle it momentarily.
102
103
105 Some qdiscs can contain classes, which contain further qdiscs - traffic
106 may then be enqueued in any of the inner qdiscs, which are within the
107 classes. When the kernel tries to dequeue a packet from such a class‐
108 ful qdisc it can come from any of the classes. A qdisc may for example
109 prioritize certain kinds of traffic by trying to dequeue from certain
110 classes before others.
111
112
114 A filter is used by a classful qdisc to determine in which class a
115 packet will be enqueued. Whenever traffic arrives at a class with sub‐
116 classes, it needs to be classified. Various methods may be employed to
117 do so, one of these are the filters. All filters attached to the class
118 are called, until one of them returns with a verdict. If no verdict was
119 made, other criteria may be available. This differs per qdisc.
120
121 It is important to notice that filters reside within qdiscs - they are
122 not masters of what happens.
123
124 The available filters are:
125
126 basic Filter packets based on an ematch expression. See tc-ematch(8)
127 for details.
128
129 bpf Filter packets using (e)BPF, see tc-bpf(8) for details.
130
131 cgroup Filter packets based on the control group of their process. See
132 tc-cgroup(8) for details.
133
134 flow, flower
135 Flow-based classifiers, filtering packets based on their flow
136 (identified by selectable keys). See tc-flow(8) and tc-flower(8)
137 for details.
138
139 fw Filter based on fwmark. Directly maps fwmark value to traffic
140 class. See tc-fw(8).
141
142 route Filter packets based on routing table. See tc-route(8) for de‐
143 tails.
144
145 rsvp Match Resource Reservation Protocol (RSVP) packets.
146
147 tcindex
148 Filter packets based on traffic control index. See tc-tcin‐
149 dex(8).
150
151 u32 Generic filtering on arbitrary packet data, assisted by syntax
152 to abstract common operations. See tc-u32(8) for details.
153
154 matchall
155 Traffic control filter that matches every packet. See tc-
156 matchall(8) for details.
157
158
160 Qdiscs may invoke user-configured actions when certain interesting
161 events take place in the qdisc. Each qevent can either be unused, or
162 can have a block attached to it. To this block are then attached fil‐
163 ters using the "tc block BLOCK_IDX" syntax. The block is executed when
164 the qevent associated with the attachment point takes place. For exam‐
165 ple, packet could be dropped, or delayed, etc., depending on the qdisc
166 and the qevent in question.
167
168 For example:
169
170 tc qdisc add dev eth0 root handle 1: red limit 500K avpkt 1K \
171 qevent early_drop block 10
172 tc filter add block 10 matchall action mirred egress mirror dev
173 eth1
174
175
177 The classless qdiscs are:
178
179 choke CHOKe (CHOose and Keep for responsive flows, CHOose and Kill for
180 unresponsive flows) is a classless qdisc designed to both iden‐
181 tify and penalize flows that monopolize the queue. CHOKe is a
182 variation of RED, and the configuration is similar to RED.
183
184 codel CoDel (pronounced "coddle") is an adaptive "no-knobs" active
185 queue management algorithm (AQM) scheme that was developed to
186 address the shortcomings of RED and its variants.
187
188 [p|b]fifo
189 Simplest usable qdisc, pure First In, First Out behaviour. Lim‐
190 ited in packets or in bytes.
191
192 fq Fair Queue Scheduler realises TCP pacing and scales to millions
193 of concurrent flows per qdisc.
194
195 fq_codel
196 Fair Queuing Controlled Delay is queuing discipline that com‐
197 bines Fair Queuing with the CoDel AQM scheme. FQ_Codel uses a
198 stochastic model to classify incoming packets into different
199 flows and is used to provide a fair share of the bandwidth to
200 all the flows using the queue. Each such flow is managed by the
201 CoDel queuing discipline. Reordering within a flow is avoided
202 since Codel internally uses a FIFO queue.
203
204 fq_pie FQ-PIE (Flow Queuing with Proportional Integral controller En‐
205 hanced) is a queuing discipline that combines Flow Queuing with
206 the PIE AQM scheme. FQ-PIE uses a Jenkins hash function to clas‐
207 sify incoming packets into different flows and is used to pro‐
208 vide a fair share of the bandwidth to all the flows using the
209 qdisc. Each such flow is managed by the PIE algorithm.
210
211 gred Generalized Random Early Detection combines multiple RED queues
212 in order to achieve multiple drop priorities. This is required
213 to realize Assured Forwarding (RFC 2597).
214
215 hhf Heavy-Hitter Filter differentiates between small flows and the
216 opposite, heavy-hitters. The goal is to catch the heavy-hitters
217 and move them to a separate queue with less priority so that
218 bulk traffic does not affect the latency of critical traffic.
219
220 ingress
221 This is a special qdisc as it applies to incoming traffic on an
222 interface, allowing for it to be filtered and policed.
223
224 mqprio The Multiqueue Priority Qdisc is a simple queuing discipline
225 that allows mapping traffic flows to hardware queue ranges using
226 priorities and a configurable priority to traffic class mapping.
227 A traffic class in this context is a set of contiguous qdisc
228 classes which map 1:1 to a set of hardware exposed queues.
229
230 multiq Multiqueue is a qdisc optimized for devices with multiple Tx
231 queues. It has been added for hardware that wishes to avoid
232 head-of-line blocking. It will cycle though the bands and ver‐
233 ify that the hardware queue associated with the band is not
234 stopped prior to dequeuing a packet.
235
236 netem Network Emulator is an enhancement of the Linux traffic control
237 facilities that allow one to add delay, packet loss, duplication
238 and more other characteristics to packets outgoing from a se‐
239 lected network interface.
240
241 pfifo_fast
242 Standard qdisc for 'Advanced Router' enabled kernels. Consists
243 of a three-band queue which honors Type of Service flags, as
244 well as the priority that may be assigned to a packet.
245
246 pie Proportional Integral controller-Enhanced (PIE) is a control
247 theoretic active queue management scheme. It is based on the
248 proportional integral controller but aims to control delay.
249
250 red Random Early Detection simulates physical congestion by randomly
251 dropping packets when nearing configured bandwidth allocation.
252 Well suited to very large bandwidth applications.
253
254 sfb Stochastic Fair Blue is a classless qdisc to manage congestion
255 based on packet loss and link utilization history while trying
256 to prevent non-responsive flows (i.e. flows that do not react to
257 congestion marking or dropped packets) from impacting perfor‐
258 mance of responsive flows. Unlike RED, where the marking proba‐
259 bility has to be configured, BLUE tries to determine the ideal
260 marking probability automatically.
261
262 sfq Stochastic Fairness Queueing reorders queued traffic so each
263 'session' gets to send a packet in turn.
264
265 tbf The Token Bucket Filter is suited for slowing traffic down to a
266 precisely configured rate. Scales well to large bandwidths.
267
269 In the absence of classful qdiscs, classless qdiscs can only be at‐
270 tached at the root of a device. Full syntax:
271
272 tc qdisc add dev DEV root QDISC QDISC-PARAMETERS
273
274 To remove, issue
275
276 tc qdisc del dev DEV root
277
278 The pfifo_fast qdisc is the automatic default in the absence of a con‐
279 figured qdisc.
280
281
283 The classful qdiscs are:
284
285 ATM Map flows to virtual circuits of an underlying asynchronous
286 transfer mode device.
287
288 CBQ Class Based Queueing implements a rich linksharing hierarchy of
289 classes. It contains shaping elements as well as prioritizing
290 capabilities. Shaping is performed using link idle time calcula‐
291 tions based on average packet size and underlying link band‐
292 width. The latter may be ill-defined for some interfaces.
293
294 DRR The Deficit Round Robin Scheduler is a more flexible replacement
295 for Stochastic Fairness Queuing. Unlike SFQ, there are no built-
296 in queues -- you need to add classes and then set up filters to
297 classify packets accordingly. This can be useful e.g. for using
298 RED qdiscs with different settings for particular traffic. There
299 is no default class -- if a packet cannot be classified, it is
300 dropped.
301
302 DSMARK Classify packets based on TOS field, change TOS field of packets
303 based on classification.
304
305 ETS The ETS qdisc is a queuing discipline that merges functionality
306 of PRIO and DRR qdiscs in one scheduler. ETS makes it easy to
307 configure a set of strict and bandwidth-sharing bands to imple‐
308 ment the transmission selection described in 802.1Qaz.
309
310 HFSC Hierarchical Fair Service Curve guarantees precise bandwidth and
311 delay allocation for leaf classes and allocates excess bandwidth
312 fairly. Unlike HTB, it makes use of packet dropping to achieve
313 low delays which interactive sessions benefit from.
314
315 HTB The Hierarchy Token Bucket implements a rich linksharing hierar‐
316 chy of classes with an emphasis on conforming to existing prac‐
317 tices. HTB facilitates guaranteeing bandwidth to classes, while
318 also allowing specification of upper limits to inter-class shar‐
319 ing. It contains shaping elements, based on TBF and can priori‐
320 tize classes.
321
322 PRIO The PRIO qdisc is a non-shaping container for a configurable
323 number of classes which are dequeued in order. This allows for
324 easy prioritization of traffic, where lower classes are only
325 able to send if higher ones have no packets available. To facil‐
326 itate configuration, Type Of Service bits are honored by de‐
327 fault.
328
329 QFQ Quick Fair Queueing is an O(1) scheduler that provides near-op‐
330 timal guarantees, and is the first to achieve that goal with a
331 constant cost also with respect to the number of groups and the
332 packet length. The QFQ algorithm has no loops, and uses very
333 simple instructions and data structures that lend themselves
334 very well to a hardware implementation.
335
337 Classes form a tree, where each class has a single parent. A class may
338 have multiple children. Some qdiscs allow for runtime addition of
339 classes (CBQ, HTB) while others (PRIO) are created with a static number
340 of children.
341
342 Qdiscs which allow dynamic addition of classes can have zero or more
343 subclasses to which traffic may be enqueued.
344
345 Furthermore, each class contains a leaf qdisc which by default has
346 pfifo behaviour, although another qdisc can be attached in place. This
347 qdisc may again contain classes, but each class can have only one leaf
348 qdisc.
349
350 When a packet enters a classful qdisc it can be classified to one of
351 the classes within. Three criteria are available, although not all
352 qdiscs will use all three:
353
354 tc filters
355 If tc filters are attached to a class, they are consulted first
356 for relevant instructions. Filters can match on all fields of a
357 packet header, as well as on the firewall mark applied by ipta‐
358 bles.
359
360 Type of Service
361 Some qdiscs have built in rules for classifying packets based on
362 the TOS field.
363
364 skb->priority
365 Userspace programs can encode a class-id in the 'skb->priority'
366 field using the SO_PRIORITY option.
367
368 Each node within the tree can have its own filters but higher level
369 filters may also point directly to lower classes.
370
371 If classification did not succeed, packets are enqueued to the leaf
372 qdisc attached to that class. Check qdisc specific manpages for de‐
373 tails, however.
374
375
377 All qdiscs, classes and filters have IDs, which can either be specified
378 or be automatically assigned.
379
380 IDs consist of a major number and a minor number, separated by a colon
381 - major:minor. Both major and minor are hexadecimal numbers and are
382 limited to 16 bits. There are two special values: root is signified by
383 major and minor of all ones, and unspecified is all zeros.
384
385
386 QDISCS A qdisc, which potentially can have children, gets assigned a
387 major number, called a 'handle', leaving the minor number name‐
388 space available for classes. The handle is expressed as '10:'.
389 It is customary to explicitly assign a handle to qdiscs expected
390 to have children.
391
392
393 CLASSES
394 Classes residing under a qdisc share their qdisc major number,
395 but each have a separate minor number called a 'classid' that
396 has no relation to their parent classes, only to their parent
397 qdisc. The same naming custom as for qdiscs applies.
398
399
400 FILTERS
401 Filters have a three part ID, which is only needed when using a
402 hashed filter hierarchy.
403
404
406 The following parameters are widely used in TC. For other parameters,
407 see the man pages for individual qdiscs.
408
409
410 RATES Bandwidths or rates. These parameters accept a floating point
411 number, possibly followed by either a unit (both SI and IEC
412 units supported), or a float followed by a '%' character to
413 specify the rate as a percentage of the device's speed (e.g. 5%,
414 99.5%). Warning: specifying the rate as a percentage means a
415 fraction of the current speed; if the speed changes, the value
416 will not be recalculated.
417
418 bit or a bare number
419 Bits per second
420
421 kbit Kilobits per second
422
423 mbit Megabits per second
424
425 gbit Gigabits per second
426
427 tbit Terabits per second
428
429 bps Bytes per second
430
431 kbps Kilobytes per second
432
433 mbps Megabytes per second
434
435 gbps Gigabytes per second
436
437 tbps Terabytes per second
438
439
440 To specify in IEC units, replace the SI prefix (k-, m-, g-, t-)
441 with IEC prefix (ki-, mi-, gi- and ti-) respectively.
442
443
444 TC store rates as a 32-bit unsigned integer in bps internally,
445 so we can specify a max rate of 4294967295 bps.
446
447
448 TIMES Length of time. Can be specified as a floating point number fol‐
449 lowed by an optional unit:
450
451 s, sec or secs
452 Whole seconds
453
454 ms, msec or msecs
455 Milliseconds
456
457 us, usec, usecs or a bare number
458 Microseconds.
459
460
461 TC defined its own time unit (equal to microsecond) and stores
462 time values as 32-bit unsigned integer, thus we can specify a
463 max time value of 4294967295 usecs.
464
465
466 SIZES Amounts of data. Can be specified as a floating point number
467 followed by an optional unit:
468
469 b or a bare number
470 Bytes.
471
472 kbit Kilobits
473
474 kb or k
475 Kilobytes
476
477 mbit Megabits
478
479 mb or m
480 Megabytes
481
482 gbit Gigabits
483
484 gb or g
485 Gigabytes
486
487
488 TC stores sizes internally as 32-bit unsigned integer in byte,
489 so we can specify a max size of 4294967295 bytes.
490
491
492 VALUES Other values without a unit. These parameters are interpreted
493 as decimal by default, but you can indicate TC to interpret them
494 as octal and hexadecimal by adding a '0' or '0x' prefix respec‐
495 tively.
496
497
499 The following commands are available for qdiscs, classes and filter:
500
501 add Add a qdisc, class or filter to a node. For all entities, a par‐
502 ent must be passed, either by passing its ID or by attaching di‐
503 rectly to the root of a device. When creating a qdisc or a fil‐
504 ter, it can be named with the handle parameter. A class is named
505 with the classid parameter.
506
507
508 delete A qdisc can be deleted by specifying its handle, which may also
509 be 'root'. All subclasses and their leaf qdiscs are automati‐
510 cally deleted, as well as any filters attached to them.
511
512
513 change Some entities can be modified 'in place'. Shares the syntax of
514 'add', with the exception that the handle cannot be changed and
515 neither can the parent. In other words, change cannot move a
516 node.
517
518
519 replace
520 Performs a nearly atomic remove/add on an existing node id. If
521 the node does not exist yet it is created.
522
523
524 get Displays a single filter given the interface DEV, qdisc-id, pri‐
525 ority, protocol and filter-id.
526
527
528 show Displays all filters attached to the given interface. A valid
529 parent ID must be passed.
530
531
532 link Only available for qdiscs and performs a replace where the node
533 must exist already.
534
535
537 The tc utility can monitor events generated by the kernel such as
538 adding/deleting qdiscs, filters or actions, or modifying existing ones.
539
540 The following command is available for monitor :
541
542 file If the file option is given, the tc does not listen to kernel
543 events, but opens the given file and dumps its contents. The
544 file has to be in binary format and contain netlink messages.
545
546
548 -b, -b filename, -batch, -batch filename
549 read commands from provided file or standard input and invoke
550 them. First failure will cause termination of tc.
551
552
553 -force don't terminate tc on errors in batch mode. If there were any
554 errors during execution of the commands, the application return
555 code will be non zero.
556
557
558 -o, -oneline
559 output each record on a single line, replacing line feeds with
560 the '\' character. This is convenient when you want to count
561 records with wc(1) or to grep(1) the output.
562
563
564 -n, -net, -netns <NETNS>
565 switches tc to the specified network namespace NETNS. Actually
566 it just simplifies executing of:
567
568 ip netns exec NETNS tc [ OPTIONS ] OBJECT { COMMAND | help }
569
570 to
571
572 tc -n[etns] NETNS [ OPTIONS ] OBJECT { COMMAND | help }
573
574
575 -N, -Numeric
576 Print the number of protocol, scope, dsfield, etc directly in‐
577 stead of converting it to human readable name.
578
579
580 -cf, -conf <FILENAME>
581 specifies path to the config file. This option is used in con‐
582 junction with other options (e.g. -nm).
583
584
585 -t, -timestamp
586 When tc monitor runs, print timestamp before the event message
587 in format:
588 Timestamp: <Day> <Month> <DD> <hh:mm:ss> <YYYY> <usecs> usec
589
590
591 -ts, -tshort
592 When tc monitor runs, prints short timestamp before the event
593 message in format:
594 [<YYYY>-<MM>-<DD>T<hh:mm:ss>.<ms>]
595
596
598 The show command has additional formatting options:
599
600
601 -s, -stats, -statistics
602 output more statistics about packet usage.
603
604
605 -d, -details
606 output more detailed information about rates and cell sizes.
607
608
609 -r, -raw
610 output raw hex values for handles.
611
612
613 -p, -pretty
614 for u32 filter, decode offset and mask values to equivalent fil‐
615 ter commands based on TCP/IP. In JSON output, add whitespace to
616 improve readability.
617
618
619 -iec print rates in IEC units (ie. 1K = 1024).
620
621
622 -g, -graph
623 shows classes as ASCII graph. Prints generic stats info under
624 each class if -s option was specified. Classes can be filtered
625 only by dev option.
626
627
628 -c[color][={always|auto|never}
629 Configure color output. If parameter is omitted or always, color
630 output is enabled regardless of stdout state. If parameter is
631 auto, stdout is checked to be a terminal before enabling color
632 output. If parameter is never, color output is disabled. If
633 specified multiple times, the last one takes precedence. This
634 flag is ignored if -json is also given.
635
636
637 -j, -json
638 Display results in JSON format.
639
640
641 -nm, -name
642 resolve class name from /etc/iproute2/tc_cls file or from file
643 specified by -cf option. This file is just a mapping of classid
644 to class name:
645
646 # Here is comment
647 1:40 voip # Here is another comment
648 1:50 web
649 1:60 ftp
650 1:2 home
651
652 tc will not fail if -nm was specified without -cf option but
653 /etc/iproute2/tc_cls file does not exist, which makes it possi‐
654 ble to pass -nm option for creating tc alias.
655
656
657 -br, -brief
658 Print only essential data needed to identify the filter and ac‐
659 tion (handle, cookie, etc.) and stats. This option is currently
660 only supported by tc filter show and tc actions ls commands.
661
662
664 tc -g class show dev eth0
665 Shows classes as ASCII graph on eth0 interface.
666
667 tc -g -s class show dev eth0
668 Shows classes as ASCII graph with stats info under each class.
669
670
672 tc was written by Alexey N. Kuznetsov and added in Linux 2.2.
673
675 tc-basic(8), tc-bfifo(8), tc-bpf(8), tc-cake(8), tc-cbq(8), tc-
676 cgroup(8), tc-choke(8), tc-codel(8), tc-drr(8), tc-ematch(8), tc-
677 ets(8), tc-flow(8), tc-flower(8), tc-fq(8), tc-fq_codel(8), tc-
678 fq_pie(8), tc-fw(8), tc-hfsc(7), tc-hfsc(8), tc-htb(8), tc-mqprio(8),
679 tc-pfifo(8), tc-pfifo_fast(8), tc-pie(8), tc-red(8), tc-route(8), tc-
680 sfb(8), tc-sfq(8), tc-stab(8), tc-tbf(8), tc-tcindex(8), tc-u32(8),
681 User documentation at http://lartc.org/, but please direct bugreports
682 and patches to: <netdev@vger.kernel.org>
683
684
686 Manpage maintained by bert hubert (ahu@ds9a.nl)
687
688
689
690iproute2 16 December 2001 TC(8)