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 reflects the configuration inside the kernel. The configuration is retrieved using the tc(8) command. This may be be performed upon object initialization, or at a later time.
QDiscConfigprovides methods for adding/removing queueing disciplines, queuing classes, and traffic filters from the kernel.QDiscConfigalso 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, so the new kernel configuration will need to be explicitly retrieved 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 interfaceallow_parsing_errors – if
True, count the parsing errors instead of raising an exception when processing the existing configuration
Raises a
TcParsingErrorif unable to parse the existing configuration.Raises a
TcConfigErrorif 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_filter –
TrafficFilterobject describing the filter to createparent_handle – handle of the owner
QDisc/QClassof the filter
- create_ingress_qdisc() QDisc[source]¶
Create the ingress queuing discipline.
- Return type:
the ingress queuing discipline
- 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_filter –
TrafficFilterobject describing the filter to delete; it must have a priority assigned to itparent_handle – handle of the owner
QDisc/QClassof the filter
Raises a
TcErroriftraffic_filterhas no priority.
- delete_qclass(qclass: QClass) None[source]¶
Delete the queuing class
qclassfrom the kernel.qclassshould have noQClasschildren, 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
qdiscfrom the kernel.If
qdiscis the root queuing discipline, the entire configuration will be deleted. In that case, a call toread_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_ingress_qdisc() Optional[QDisc][source]¶
Returns the ingress queuing discipline, or
Noneif there is no ingress queuing discipline (or if the interface configuration has not been read).
- get_qclass(handle: Handle) Optional[QClass][source]¶
Returns the
QClasswith the specifiedhandle, orNoneif there is no such qclass.
- get_qdisc(handle: Handle) Optional[QDisc][source]¶
Returns the
QDiscwith the specifiedhandle, orNoneif there is no such qdisc.
- get_root_qdisc() Optional[QDisc][source]¶
Returns the root queuing discipline, or
Noneif the root queuing discipline has not been discovered yet.
- read_interface_config(allow_parsing_errors: Optional[bool] = None) bool[source]¶
Read the queuing discipline configuration of the interface and initialize our internal state. This can only be performed once.
- Parameters:
allow_parsing_errors – if
False, aTcParsingErrorwill be raised upon a parsing error; ifTrue, noTcParsingErrorwill be raised; ifNone, the behavior depends on the value of theallow_parsing_errorsparameter when thisQDiscConfiginstance was created- Return type:
Trueif no parsing error is encountered;Falseifallow_parsing_errorsisTrueand there are parsing errors.
Raises a
TcConfigErrorif the interface configuration has already been discovered.
- retrieve_filters(qnode: QNode) List[TrafficFilter][source]¶
Returns a list of
TrafficFilterobjects.- Parameters:
qnode – a
QDiscorQClassobject
This method can be used to retrieve the filters of any queuing discipline or class using an actual
QDiscorQClassobject (not one of a subclass).