HTB

The following classes provide access to the htb (Hierarchy Token Bucket) queueing discipline and its statistics:


class HTBQDisc(qdisc_handle: Handle, parent_handle: Optional[Handle], *, default_class_minor: Optional[int] = None, r2q: Optional[int] = None)[source]

This class provides access to the Hierarchy Token Bucket queueing discipline of Linux (see tc-htb(8)).

Parameters:
  • qdisc_handle – handle of this queuing discipline

  • parent_handle – handle of parent, None if this is a root queuing discipline

  • default_class_minor – minor number of default class

  • r2q – when a queuing class of this queuing discipline has not an explicitly specified quantaum, its quantum is computed as rate/r2q

get_default_class_handle() Optional[Handle][source]

Get the handle of the default class

get_r2q() Optional[int][source]

Returns the rate-to-quantum divisor

qdisc_creation_args() List[str][source]

Returns the arguments expected by tc to create a HTB qdisc

get_description() str[source]

Returns a string describing the queuing discipline and its attributes

create_filter(traffic_filter: TrafficFilter) None

Create the filter traffic_filter.

delete_filter(traffic_filter: TrafficFilter) None

Delete the filter traffic_filter.

dump(outfile: TextIO, level=0, qclass_map: Optional[Mapping[Handle, QClass]] = None)

Recursively dump this Qdisc to outfile.

The qclass_map, if present, is used to determine the destination QClass objects of traffic filters.

get_child(handle: Handle) Optional[QClass]

Returns the QClass with the specified handle

get_child_count() int

Return number of children of this QDisc/QClass

get_child_iter() Iterator[QClass]

Returns an iterator for the QClass children of this QDisc/QClass.

get_children() List[QClass]

Returns the children of this QDisc/QClass.

get_config() QDiscConfig

Returns the QDiscConfig where this QDisc/QClass has been instantiated, or None if not instantiated.

get_filters(refresh=False) List[TrafficFilter]

Returns (a copy of) the list of filters at this QDisc/QClass

Parameters:

refresh – if True, a fresh copy of the filter list is obtained using the tc(8) command.

get_handle() Handle

Returns the QDisc/QClass handle

get_interface() Optional[str]

Returns the interface where this QDisc/QClass has been instantiated, or None if the QDisc/QClass is not instantiated.

get_parent_handle() Optional[Handle]

Returns the handle of the parent of this QDisc/QClass

get_stats() Optional[QStats]

Returns queuing stats.

is_default() bool

Returns True if this QDisc is the default qdisc used by the kernel.

static is_ingress() bool

Returns True if this QDisc is the ingress qdisc

is_root() bool

Returns True if this is a root QDisc


class HTBQClass(class_handle: Handle, parent_handle: Handle, *, rate: int, ceil: Optional[int] = None, prio: Optional[int] = None, burst: Optional[int] = None, cburst: Optional[int] = None, quantum: Optional[int] = None, class_name: Optional[str] = None)[source]

A class of the HTB qdisc

Parameters:
  • class_handle – handle of this HTBQClass

  • parent_handle – handle of parent HTBQClass or HTBQDisc

  • rate – guaranteed rate (unit: bits/sec)

  • ceil – max rate (unit: bits/sec)

  • prio – priority

  • burst – amount of bytes that can be sent at ceil speed

  • cburst – amount of bytes that can be sent at interface speed

  • quantum – transmission quantum (aka interface packet size) in bytes; the kernel computes this from the HTB queuing discipline r2q if not explicitly specified at HTB class creation time

get_description() str[source]

Returns a string describing the class and its attributes

qclass_creation_args() List[str][source]

Returns the tc arguments to create this HTB class

get_priority() int[source]

Returns the class priority, or -1 if the class has no priority specified

get_rate() int[source]

Returns the bandwidth guaranteed to this class

get_ceil() Optional[int][source]

Returns the maximum bandwidth that may be consumed by this class.

get_burst() Optional[int][source]

Returns the burst (bytes)

get_cburst() Optional[int][source]

Returns the cburst (bytes)

get_quantum() Optional[int][source]

Returns the quantum (bytes)

get_residual_rate() int[source]

Returns the residual rate, which is the guaranteed bandwidth left at this class after all its children have been allocated their guaranteed bandwidth.

get_stats() Optional[HTBQClassStats][source]

Returns class stats (an HTBQClassStats instance) or None if no stats are available.

child_admission_check(new_child_class: HTBQClass) None[source]

Perform sanity tests before adding a child class:

  • child is an HTBQClass

  • child ceil <= parent ceil

  • aggr children rate <= parent rate

Raises a TcBandwidthError if the check fails

create_filter(traffic_filter: TrafficFilter) None

Create the filter traffic_filter.

delete_filter(traffic_filter: TrafficFilter) None

Delete the filter traffic_filter.

dump(outfile: TextIO, level: int, qclass_map: Optional[Mapping[Handle, QClass]] = None)

Recursively dump this QClass to outfile.

The qclass_map, if present, is used to determine the destination QClass objects of traffic filters.

get_child(handle: Handle) Optional[QClass]

Returns the QClass with the specified handle

get_child_count() int

Return number of children of this QDisc/QClass

get_child_iter() Iterator[QClass]

Returns an iterator for the QClass children of this QDisc/QClass.

get_children() List[QClass]

Returns the children of this QDisc/QClass.

get_class_name() str

Returns the class name

get_config() QDiscConfig

Returns the QDiscConfig where this QDisc/QClass has been instantiated, or None if not instantiated.

get_filters(refresh=False) List[TrafficFilter]

Returns (a copy of) the list of filters at this QDisc/QClass

Parameters:

refresh – if True, a fresh copy of the filter list is obtained using the tc(8) command.

get_handle() Handle

Returns the QDisc/QClass handle

get_interface() Optional[str]

Returns the interface where this QDisc/QClass has been instantiated, or None if the QDisc/QClass is not instantiated.

get_parent_handle() Optional[Handle]

Returns the handle of the parent of this QDisc/QClass

get_qdisc() Optional[QDisc]

Returns the QDisc under with this QClass, or None if this is not a leaf queuing class.

is_leaf() bool

Returns True if this is a leaf queuing class

set_class_name(class_name: str) None

Sets the class name

set_qdisc(qdisc: QDisc) None

Set the QDisc under with this queuing class


class HTBQClassStats[source]

Bases: QStats

HTB-specific class stats (see QStats for inherited stats)

property packets_lent: int

Number of packets lent.

property packets_borrowed: int

Number of packets borrowed.

property overlimits: int

Number of times a rate limit was exceeded.

property giant_packets: int

Number of packets exceeding interface MTU

property tokens: int

Tokens available for transmitting at the guaranteed rate (measured in packet scheduler ticks).

This value is not a statistic; it reflects the class state at the time the stats were obtained.

property ctokens: int

Tokens available for transmitting at the maximum (ceil) rate (measured in packet scheduler ticks)

This value is not a statistic; it reflects the class state at the time the stats were obtained.

dump(outfile: TextIO, width: Optional[int] = None) None[source]

Dump stats to outfile. There is one stat per line output. Each line has the format:

header: value

The header: part occupies at least width characters.

property bitrate: int

Consumed bandwidth measured in bits/sec

property bytes_sent: int

Number of bytes sent.

property dropped_packets: int

Number of packets dropped.

get_byte_backlog() int

Queue backlog in bytes

get_overlimits() int

Number of times a packet was delayed due to rate limits.

get_packet_backlog() int

Queue backlog in packets

property packetrate: int

Consumed bandwidth measured in packets/sec

property packets_sent: int

Number of packets sent.

property requeued_packets: int

Number of packets that were requeued for some reason.