LinuxCommandLibrary

tc-htb

Shape network traffic using a hierarchical token bucket

SYNOPSIS

tc qdisc add ... htb default r2q quantum burst mtu pfifo_plimit
tc class add ... htb rate ceil prio burst cburst quantum

PARAMETERS

default
    Specifies the default class for unmatched packets.

r2q
    Rate at which tokens are refilled. Controls the minimum bandwidth guarantee.

quantum
    Amount of bytes that can be sent per token. Should be set to MTU size of interface for maximum performance

burst
    Maximum burst size allowed. Influences the shaping precision.

mtu
    Sets the maximum transmission unit size for packets in the qdisc.

pfifo_plimit
    Sets the packet limit for the packet First-In, First-Out (PFIFO) queue associated with the qdisc.

rate
    Guaranteed bandwidth for the class.

ceil
    Maximum bandwidth the class can use. Can be higher than the `rate` if bandwidth is available.

prio
    Priority of the class. Lower values mean higher priority.

burst
    Maximum burst size allowed. Influences the shaping precision for the rate.

cburst
    Maximum burst size allowed. Influences the shaping precision for the ceil.

quantum
    Amount of bytes that can be sent per token.

DESCRIPTION

The `tc-htb` command is a traffic control (tc) classifier that uses the Hierarchical Token Bucket (HTB) queuing discipline to shape network traffic. It allows you to create a hierarchical structure of classes and assign bandwidth limits to each class. HTB is designed to provide fair sharing of bandwidth among different traffic flows while also allowing you to prioritize certain types of traffic over others. It works by dividing available bandwidth into classes and assigning tokens to these classes. Traffic is allowed to flow as long as there are sufficient tokens available. If a class exceeds its token limit, traffic is shaped to conform to the configured rate. This makes it possible to create complex traffic shaping configurations that prioritize critical applications while ensuring that other traffic flows don't starve. Using `tc-htb` effectively requires a solid understanding of networking concepts, particularly QoS (Quality of Service), bandwidth shaping, and queuing disciplines.

CAVEATS

Configuration can be complex and requires a deep understanding of traffic shaping concepts. Incorrect configuration can lead to unexpected network behavior or performance degradation.

Root privileges are required to use `tc` command.

UNITS OF MEASUREMENT

Rates are typically expressed in bits per second (bps), kilobits per second (kbps), or megabits per second (mbps). Bytes are typically expressed as bytes (b), kilobytes (k), or megabytes (m). Pay attention to the units used in the command line, as incorrect units can significantly affect traffic shaping behavior.
For example, 10mbit is not equal 10mbits.

HTB ALGORITHM

HTB organizes classes in a tree-like structure. Each class has a parent and potentially multiple children. Tokens are passed down from parent classes to child classes, enabling hierarchical bandwidth allocation. Each class is treated as a queue, and packets are placed into the queue based on configured rules. HTB's hierarchical structure allows for fine-grained control over bandwidth distribution. When configuring HTB, it's crucial to plan the hierarchy carefully to ensure that traffic is shaped according to the desired priorities. carefull planning is recommended

HISTORY

HTB (Hierarchical Token Bucket) was developed to address limitations in earlier traffic shaping techniques like CBQ (Class-Based Queuing). It aimed to provide a more intuitive and efficient way to manage bandwidth allocation in complex networks. The `tc-htb` command is the user interface to configure the HTB queuing discipline in the Linux kernel's traffic control system. Over time, it has become a widely used tool for network administrators to prioritize different types of traffic and ensure fair bandwidth sharing.

SEE ALSO

tc(8), tc-prio(8), tc-tbf(8), ip(8)

Copied to clipboard