Parsers¶
linuxnet.qos uses a number of parser classes to parse the output of the tc(8) command:
The following classes are also used in parsing:
Queuing discipline parsing¶
The QDiscParser class is responsible for parsing the output of
tc -s qdisc ls dev <interface>.
The QDiscParser.register_qdisc() method must be invoked
to register queueing discipline classes.
- class QDiscParser(allow_parsing_errors: bool)[source]¶
Helper class that creates
QDiscobjects from the output of the tc(8) command.- classmethod register_qdisc(ident: str, klass) None[source]¶
Register the given class (which should be a subclass of the
QDiscclass).This method is intended to be used for adding support for new queuing disciplines.
- Parameters:
ident – the qdisc name that appears in the
tc -s qdisc lsoutput.klass – the Python class for this queuing discipline
- class QDiscOutput(line_group: List[str])[source]¶
Helper class used for parsing
tc qdisc lsoutput for a single qdisc- Parameters:
line_group – list of lines, guaranteed not to be empty
- get_parent_handle() Optional[Handle][source]¶
Returns the (parsed)
Handleof the parent of this queueing discipline, orNoneif this is a root qdisc
Queuing class parsing¶
The QClassParser class is responsible for parsing the output of
tc -s class ls dev <interface>.
The QClassParser.register_qclass() method must be invoked
to register Python classes providing support for classes of
classful queueing disciplines.
- class QClassParser(allow_parsing_errors: bool)[source]¶
Helper class that creates
QClassobjects from the output of the tc(8) command.- classmethod register_qclass(ident: str, klass) None[source]¶
Register the given class (which should be a subclass of the
QClassclass).This method is intended to be used for adding support for new queuing discipline classes.
- Parameters:
ident – the queuing class name that appears in the
tc -s class lsoutput.klass – the Python class for this queuing class
- class QClassOutput(line_group: List[str])[source]¶
Helper class used for parsing
tc class lsoutput for a single qclass- Parameters:
line_group – list of lines, guaranteed not to be empty
Traffic filter parsing¶
The TrafficFilterParser class is responsible for parsing the output of
tc filter ls dev <interface>.
The TrafficFilterParser.register_filter() method must be invoked
to register classes traffic filter classes.
- class TrafficFilterParser(allow_parsing_errors: bool)[source]¶
Helper class that creates
TrafficFilterobjects from the output of the tc(8) command.- classmethod register_filter(*, filter_type: str, protocol: str, klass) None[source]¶
Register the given class (which should be a subclass of the
TrafficFilterclass).This method is intended to be used for adding support for new traffic filter types.
- Parameters:
filter_type – a tc(8) filter type, e.g.
u32protocol – a tc(8) protocol name, e.g.
ipklass – the Python class for this
(filter_type, protocol)
- classmethod register_action(*, action_name: str, klass) None[source]¶
Register the given class (which should be a subclass of the
TrafficActionclass).This method is intended to be used for adding support for new traffic actions.
- Parameters:
action_name – tc(8) action, e.g.
policeklass – the Python class for this action
- classmethod parse_action(fields: List[str], nfl_iter: Iterator[str]) TrafficAction[source]¶
Parse the tc(8) output for a traffic action.
- Parameters:
fields – fields of the output line identifying the action and its arguments;
fields[0]is the action typenfl_iter – iterator returning the lines after the lines that start with ‘filter’
- Return type:
a
TrafficActioninstance
Raises a
TcParsingErrorif unable to parse the action
- class FilterOutput(proto: str, prio: int, filter_type: str, owner: QNode)[source]¶
An instance of this class contains the tc(8) output for a single filter.
- Parameters:
- has_nonfilter_lines() bool[source]¶
Returns
Trueif the filter output has any lines not starting with the wordfilter
- filter_lines_iter() Iterator[FilterOutputLine][source]¶
Returns an iterator that returns
FilterOutputLineinstances.
- class FilterOutputLine(line: str, fields: List[str])[source]¶
A class that holds a line of filter output.
One can iterate over the fields of the line:
def parse_fields(fline: FilterOutputLine): for field in fline: if field == 'xxx': ...
The entire line can be returned by using the
str()builtin function.- Parameters:
line – the complete tc(8) filter line
fields – list of fields of the line after the filter type