Blame man/man8/tc-tbf.8

Packit d3f73b
.TH TC 8 "13 December 2001" "iproute2" "Linux"
Packit d3f73b
.SH NAME
Packit d3f73b
tbf \- Token Bucket Filter
Packit d3f73b
.SH SYNOPSIS
Packit d3f73b
.B tc qdisc ... tbf rate
Packit d3f73b
rate
Packit d3f73b
.B burst
Packit d3f73b
bytes/cell
Packit d3f73b
.B ( latency
Packit d3f73b
ms
Packit d3f73b
.B | limit
Packit d3f73b
bytes
Packit d3f73b
.B ) [ mpu
Packit d3f73b
bytes
Packit d3f73b
.B [ peakrate
Packit d3f73b
rate
Packit d3f73b
.B mtu
Packit d3f73b
bytes/cell
Packit d3f73b
.B ] ]
Packit d3f73b
.P
Packit d3f73b
burst is also known as buffer and maxburst. mtu is also known as minburst.
Packit d3f73b
.SH DESCRIPTION
Packit d3f73b
Packit d3f73b
The Token Bucket Filter is a classful queueing discipline available for
Packit d3f73b
traffic control with the
Packit d3f73b
.BR tc (8)
Packit d3f73b
command.
Packit d3f73b
Packit d3f73b
TBF is a pure shaper and never schedules traffic. It is non-work-conserving and may throttle
Packit d3f73b
itself, although packets are available, to ensure that the configured rate is not exceeded.
Packit d3f73b
It is able to shape up to 1mbit/s of normal traffic with ideal minimal burstiness,
Packit d3f73b
sending out data exactly at the configured rates.
Packit d3f73b
Packit d3f73b
Much higher rates are possible but at the cost of losing the minimal burstiness. In that
Packit d3f73b
case, data is on average dequeued at the configured rate but may be sent much faster at millisecond
Packit d3f73b
timescales. Because of further queues living in network adaptors, this is often not a problem.
Packit d3f73b
Packit d3f73b
.SH ALGORITHM
Packit d3f73b
As the name implies, traffic is filtered based on the expenditure of
Packit d3f73b
.B tokens.
Packit d3f73b
Tokens roughly correspond to bytes, with the additional constraint
Packit d3f73b
that each packet consumes some tokens, no matter how small it is. This
Packit d3f73b
reflects the fact that even a zero-sized packet occupies the link for
Packit d3f73b
some time.
Packit d3f73b
Packit d3f73b
On creation, the TBF is stocked with tokens which correspond to the amount of traffic that can be burst
Packit d3f73b
in one go. Tokens arrive at a steady rate, until the bucket is full.
Packit d3f73b
Packit d3f73b
If no tokens are available, packets are queued, up to a configured limit. The TBF now
Packit d3f73b
calculates the token deficit, and throttles until the first packet in the queue can be sent.
Packit d3f73b
Packit d3f73b
If it is not acceptable to burst out packets at maximum speed, a peakrate can be configured
Packit d3f73b
to limit the speed at which the bucket empties. This peakrate is implemented as a second TBF
Packit d3f73b
with a very small bucket, so that it doesn't burst.
Packit d3f73b
Packit d3f73b
To achieve perfection, the second bucket may contain only a single packet, which leads to
Packit d3f73b
the earlier mentioned 1mbit/s limit.
Packit d3f73b
Packit d3f73b
This limit is caused by the fact that the kernel can only throttle for at minimum 1 'jiffy', which depends
Packit d3f73b
on HZ as 1/HZ. For perfect shaping, only a single packet can get sent per jiffy - for HZ=100, this means 100
Packit d3f73b
packets of on average 1000 bytes each, which roughly corresponds to 1mbit/s.
Packit d3f73b
Packit d3f73b
.SH PARAMETERS
Packit d3f73b
See
Packit d3f73b
.BR tc (8)
Packit d3f73b
for how to specify the units of these values.
Packit d3f73b
.TP
Packit d3f73b
limit or latency
Packit d3f73b
Limit is the number of bytes that can be queued waiting for tokens to become
Packit d3f73b
available. You can also specify this the other way around by setting the
Packit d3f73b
latency parameter, which specifies the maximum amount of time a packet can
Packit d3f73b
sit in the TBF. The latter calculation takes into account the size of the
Packit d3f73b
bucket, the rate and possibly the peakrate (if set). These two parameters
Packit d3f73b
are mutually exclusive.
Packit d3f73b
.TP
Packit d3f73b
burst
Packit d3f73b
Also known as buffer or maxburst.
Packit d3f73b
Size of the bucket, in bytes. This is the maximum amount of bytes that tokens can be available for instantaneously.
Packit d3f73b
In general, larger shaping rates require a larger buffer. For 10mbit/s on Intel, you need at least 10kbyte buffer
Packit d3f73b
if you want to reach your configured rate!
Packit d3f73b
Packit d3f73b
If your buffer is too small, packets may be dropped because more tokens arrive per timer tick than fit in your bucket.
Packit d3f73b
The minimum buffer size can be calculated by dividing the rate by HZ.
Packit d3f73b
Packit d3f73b
Token usage calculations are performed using a table which by default has a resolution of 8 packets.
Packit d3f73b
This resolution can be changed by specifying the
Packit d3f73b
.B cell
Packit d3f73b
size with the burst. For example, to specify a 6000 byte buffer with a 16
Packit d3f73b
byte cell size, set a burst of 6000/16. You will probably never have to set
Packit d3f73b
this. Must be an integral power of 2.
Packit d3f73b
.TP
Packit d3f73b
mpu
Packit d3f73b
A zero-sized packet does not use zero bandwidth. For ethernet, no packet uses less than 64 bytes. The Minimum Packet Unit
Packit d3f73b
determines the minimal token usage (specified in bytes) for a packet. Defaults to zero.
Packit d3f73b
.TP
Packit d3f73b
rate
Packit d3f73b
The speed knob. See remarks above about limits! See
Packit d3f73b
.BR tc (8)
Packit d3f73b
for units.
Packit d3f73b
.PP
Packit d3f73b
Furthermore, if a peakrate is desired, the following parameters are available:
Packit d3f73b
Packit d3f73b
.TP
Packit d3f73b
peakrate
Packit d3f73b
Maximum depletion rate of the bucket. The peakrate does not
Packit d3f73b
need to be set, it is only necessary if perfect millisecond timescale
Packit d3f73b
shaping is required.
Packit d3f73b
Packit d3f73b
.TP
Packit d3f73b
mtu/minburst
Packit d3f73b
Specifies the size of the peakrate bucket. For perfect accuracy, should be set to the MTU of the interface.
Packit d3f73b
If a peakrate is needed, but some burstiness is acceptable, this size can be raised. A 3000 byte minburst
Packit d3f73b
allows around 3mbit/s of peakrate, given 1000 byte packets.
Packit d3f73b
Packit d3f73b
Like the regular burstsize you can also specify a
Packit d3f73b
.B cell
Packit d3f73b
size.
Packit d3f73b
.SH EXAMPLE & USAGE
Packit d3f73b
Packit d3f73b
To attach a TBF with a sustained maximum rate of 0.5mbit/s, a peakrate of 1.0mbit/s,
Packit d3f73b
a 5kilobyte buffer, with a pre-bucket queue size limit calculated so the TBF causes
Packit d3f73b
at most 70ms of latency, with perfect peakrate behaviour, issue:
Packit d3f73b
.P
Packit d3f73b
# tc qdisc add dev eth0 handle 10: root tbf rate 0.5mbit \\
Packit d3f73b
  burst 5kb latency 70ms peakrate 1mbit       \\
Packit d3f73b
  minburst 1540
Packit d3f73b
.P
Packit d3f73b
To attach an inner qdisc, for example sfq, issue:
Packit d3f73b
.P
Packit d3f73b
# tc qdisc add dev eth0 parent 10:1 handle 100: sfq
Packit d3f73b
.P
Packit d3f73b
Without inner qdisc TBF queue acts as bfifo. If the inner qdisc is changed
Packit d3f73b
the limit/latency is not effective anymore.
Packit d3f73b
.P
Packit d3f73b
Packit d3f73b
.SH SEE ALSO
Packit d3f73b
.BR tc (8)
Packit d3f73b
Packit d3f73b
.SH AUTHOR
Packit d3f73b
Alexey N. Kuznetsov, <kuznet@ms2.inr.ac.ru>. This manpage maintained by
Packit d3f73b
bert hubert <ahu@ds9a.nl>