Queuing Discipline Configuration

The QDiscConfig class can be used to access and modify the queuing discipline configuration of an interface. It provides the ability to create and delete arbitrary QDisc and QClass objects.

class QDiscConfig(interface: str, runner=None, read_interface_config=True, allow_parsing_errors=False)[source]

Objects of this class track and manage the queuing discipline configuration of a particular interface. The object internal state can reflect the configuration inside the kernel by reading the kernel configuration using the tc(8) command. This can optionally be performed upon object initialization.

QDiscConfig also provides the methods for adding/removing queueing disciplines, queuing classes, and traffic filters from the kernel.

QDiscConfig provides methods to delete the entire queuing discipline configuration from the kernel. After successful invocation of such a method, the internal state will not reflect the kernel configuration because the kernel automatically installs a default queuing discipline, and the new kernel configuration will need to be read again.

Parameters:
  • interface – network interface name

  • runner – optional callable used to invoke tc(8)

  • read_interface_config – if True, read and parse the existing queuing discipline configuration of the interface

  • allow_parsing_errors – if True, count the parsing errors instead of raising an exception when processing the existing configuration

Raises a TcParsingError if unable to parse the existing configuration.

Raises a TcConfigError if a logical error is encountered when processing the existing configuration.

create_filter(traffic_filter, parent_handle: Handle) None[source]

Create the specified traffic filter inside the kernel.

Parameters:
  • traffic_filterTrafficFilter object describing the filter to create

  • parent_handle – handle of the owner QDisc/QClass of the filter

create_ingress_qdisc() QDisc[source]

Create the ingress queuing discipline.

Return type:

the ingress queuing discipline

create_qclass(qclass: QClass) None[source]

Create the queuing class qclass inside the kernel.

create_qdisc(qdisc: QDisc) None[source]

Create the queuing discipline qdisc inside the kernel.

delete_config()[source]

Delete the existing configuration.

This method is a no-op before reading the interface qdisc configuration.

Since the kernel installs a default root queuing discipline when the queuing configuration is deleted, a call to read_interface_config() will be needed to rediscover the new root queuing discipline.

delete_filter(traffic_filter, parent_handle)[source]

Delete the specified traffic filter from the kernel.

Parameters:
  • traffic_filterTrafficFilter object describing the filter to delete; it must have a priority assigned to it

  • parent_handle – handle of the owner QDisc/QClass of the filter

Raises a TcError if traffic_filter has no priority.

delete_ingress_qdisc() None[source]

Delete the ingress queuing discipline.

delete_qclass(qclass: QClass) None[source]

Delete the queuing class qclass from the kernel.

qclass should have no QClass children, or the kernel will fail the operation.

If the queuing class has a queuing discipline, that queuing discipline will also be recursively deleted (this is the kernel behavior).

delete_qdisc(qdisc: QDisc) None[source]

Delete the queuing discipline qdisc from the kernel.

If qdisc is the root queuing discipline, the entire configuration will be deleted. In that case, a call to read_interface_config() will be needed to rediscover the new root queuing discipline.

delete_root_qdisc()[source]

Delete the interface root qdisc.

This method can be used even without reading the interface qdisc configuration.

dump(outfile=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]

Dump the queueing tree to outfile

get_error_count() int[source]

Returns number of parsing errors

get_ingress_qdisc() Optional[QDisc][source]

Returns the ingress queuing discipline, or None if there is no ingress queuing discipline (or if the interface configuration has not been read).

get_interface() str[source]

Returns the interface associated with this configuration

get_qclass(handle: Handle) Optional[QClass][source]

Returns the QClass with the specified handle, or None if there is no such qclass.

get_qdisc(handle: Handle) Optional[QDisc][source]

Returns the QDisc with the specified handle, or None if there is no such qdisc.

get_root_qdisc() Optional[QDisc][source]

Returns the root queuing discipline, or None if the root queuing discipline has not been discovered yet.

read_interface_config(allow_parsing_errors: Optional[bool] = None) bool[source]

Read the queuing discipling configuration of the interface and initialize our internal state. This can only be performed once.

Parameters:

allow_parsing_errors – if False, a TcParsingError will be raised upon a parsing error; if True, no TcParsingError will be raised; if None, the behavior depends on the value of the allow_parsing_errors parameter when this QDiscConfig instance was created

Return type:

True if no parsing error is encountered; False if allow_parsing_errors is True and there are parsing errors.

Raises a TcConfigError if the interface configuration has already been discovered.

retrieve_filters(qnode: QNode) List[TrafficFilter][source]

Returns a list of TrafficFilter objects.

Parameters:

qnode – a QDisc or QClass object

This method can be used to retrieve the filters of any queuing discipline or class using an actual QDisc or QClass object (not one of a subclass).