Base Class¶
pcapkit.foundation.traceflow.traceflow
contains
TraceFlow
only,
which is an abstract base class for all flow tracing classes.
- class pcapkit.foundation.traceflow.traceflow.TraceFlow(fout, format, byteorder='little', nanosecond=False)[source]¶
Bases:
TraceFlowBase
[_DT
,_BT
,_IT
,_PT
],Generic
[_DT
,_BT
,_IT
,_PT
]Base flow tracing class.
Example
Use keyword argument
protocol
to specify the protocol name at class definition:class MyProtocol(TraceFlow, protocol='my_protocol'): ...
- Parameters:
See also
For more information on customisation and extension, please refer to Customisation & Extensions.
- property name: str¶
Protocol name of current class.
Note
This property is also available as a class variable. Its value can be set by
__protocol_name__
class attribute.
- property protocol: Type[Protocol]¶
Protocol of current class.
Note
This property is also available as a class variable. Its value can be set by
__protocol_type__
class attribute.
- classmethod register_dumper(format, dumper, ext)¶
Register a new dumper class.
Notes
The full qualified class name of the new dumper class should be as
{dumper.module}.{dumper.name}
.- Parameters:
format (
str
) – format namedumper (
Union
[ModuleDescriptor
[Dumper
],Type
[Dumper
]]) – module descriptor or adictdumper.dumper.Dumper
subclassext (
str
) – file extension
- Return type:
- classmethod register_callback(callback, *, index=None)¶
Register callback function.
- classmethod make_fout(fout='./tmp', fmt='pcap')¶
Make root path for output.
- Parameters:
- Return type:
- Returns:
Dumper of specified format and file extension of output file.
- Warns:
FormatWarning – If
fmt
is not supported.FileWarning – If
fout
exists andfmt
isNone
.
- Raises:
FileExists – If
fout
exists andfmt
is NOTNone
.
- abstract dump(packet)¶
Dump frame to output files.
- Parameters:
packet (
TypeVar
(_PT
, bound= Info)) – a flow packet (trace.tcp.packet)- Return type:
- abstract trace(packet, *, output=False)¶
Trace packets.
- Parameters:
packet (
TypeVar
(_PT
, bound= Info)) – a flow packet (trace.tcp.packet)output (
bool
) – flag if has formatted dumper
- Return type:
- Returns:
If
output
isTrue
, returns the initiatedDumper
object, which will dump data to the output file named after the flow label; otherwise, returns the flow label itself.
- abstract submit()¶
Submit traced TCP flows.
- Return type:
- Returns:
Traced TCP flow (trace.tcp.index).
-
__output__:
DefaultDict
[str
,tuple
[Union
[ModuleDescriptor
[Dumper
],Type
[Dumper
]],str
|None
]]¶ DefaultDict[str, tuple[ModuleDescriptor[Dumper] | Type[Dumper], str | None]]: Format dumper mapping for writing output files. The values should be a tuple representing the module name and class name, or a
dictdumper.dumper.Dumper
subclass, and corresponding file extension.
-
__callback_fn__:
list
[Callable
[[TypeVar
(_IT
, bound= Info)],None
]]¶ List of callback functions upon reassembled datagram.
-
_buffer:
dict
[TypeVar
(_DT
),TypeVar
(_BT
, bound= Info)]¶ Buffer field (trace.tcp.buffer).
- Type:
dict[_DT, _BT]
-
_stream:
list
[TypeVar
(_IT
, bound= Info)]¶ Stream index (trace.tcp.index).
- Type:
list[_IT]
- __call__(packet)¶
Dump frame to output files.
- Parameters:
packet (
TypeVar
(_PT
, bound= Info)) – a flow packet (trace.tcp.packet)- Return type:
- classmethod __init_subclass__(protocol=None, *args, **kwargs)[source]¶
Initialise subclass.
This method is to be used for registering the engine class to
Extractor
class.- Parameters:
- Return type:
See also
For more details, please refer to
pcapkit.foundation.extraction.Extractor.register_traceflow()
.
-
__protocol_type__:
Type
[ProtocolBase
]¶ Protocol of current reassembly object.
Internal Definitions¶
- class pcapkit.foundation.traceflow.traceflow.TraceFlowBase(fout, format, byteorder='little', nanosecond=False)[source]¶
Bases:
Generic
[_DT
,_BT
,_IT
,_PT
]Base flow tracing class.
- Parameters:
Note
This class is for internal use only. For customisation, please use
TraceFlow
instead.
- class pcapkit.foundation.traceflow.traceflow.TraceFlowMeta(name, bases, namespace, /, **kwargs)[source]¶
Bases:
ABCMeta
Meta class to add dynamic support to
TraceFlow
.This meta class is used to generate necessary attributes for the
TraceFlow
class. It can be useful to reduce unnecessary registry calls and simplify the customisation process.
Type Variables¶
- pcapkit.foundation.traceflow.traceflow._BT: pcapkit.corekit.infoclass.Info¶
Buffer data structure.
- pcapkit.foundation.traceflow.traceflow._IT: pcapkit.corekit.infoclass.Info¶
Index data structure.
- pcapkit.foundation.traceflow.traceflow._PT: pcapkit.corekit.infoclass.Info¶
Packet data structure.