scapy - Capturing Traffic Generator
The Scapy traffic generator.
A traffic generator used for functional testing, implemented with the Scapy library. The traffic generator uses an interactive shell to run Scapy on the remote TG node.
The traffic generator extends framework.remote_session.python_shell.PythonShell
to
implement the methods for handling packets by sending commands into the interactive shell.
- class ScapyTrafficGenerator
Bases:
PythonShell
,CapturingTrafficGenerator
Provides access to scapy functions on a traffic generator node.
This class extends the base with remote execution of scapy functions. All methods for processing packets are implemented using an underlying
framework.remote_session.python_shell.PythonShell
which imports the Scapy library. This class also extendscapturing_traffic_generator.CapturingTrafficGenerator
to expose methods that utilize said packet processing functionality to test suites.Because of the double inheritance, this class has both methods that wrap scapy commands sent into the shell (running on the TG node) and methods that run locally to fulfill traffic generation needs. To help make a clear distinction between the two, the names of the methods that wrap the logic of the underlying shell should be prepended with “shell”.
Note that the order of inheritance is important for this class. In order to instantiate this class, the abstract methods of
CapturingTrafficGenerator
must be implemented. Since some of these methods are implemented in the underlying interactive shell, according to Python’s Method Resolution Order (MRO), the interactive shell must come first.- __init__(tg_node: Node, config: ScapyTrafficGeneratorConfig, **kwargs)
Extend the constructor with Scapy TG specifics.
Initializes both the traffic generator and the interactive shell used to handle Scapy functions. The interactive shell will be started on tg_node. The additional keyword arguments in kwargs are used to pass into the constructor for the interactive shell.
- Parameters:
tg_node (Node) – The node where the traffic generator resides.
config (ScapyTrafficGeneratorConfig) – The traffic generator’s test run configuration.
kwargs – Additional keyword arguments. Supported arguments correspond to the parameters of
PythonShell.__init__()
in this case.
- start_application() None
Extends
framework.remote_session.interactive_shell.start_application()
.Adds a command that imports everything from the scapy library immediately after starting the shell for usage in later calls to the methods of this class.