MCPcopy Create free account
hub / github.com/F-Stack/f-stack / ScapyTrafficGenerator

Class ScapyTrafficGenerator

dpdk/dts/framework/testbed_model/scapy.py:165–281  ·  view source on GitHub ↗

Provides access to scapy functions via an RPC interface. The traffic generator first starts an XML-RPC on the remote TG node. Then it populates the server with functions which use the Scapy library to send/receive traffic. Any packets sent to the remote server are first converted t

Source from the content-addressed store, hash-verified

163
164
165class ScapyTrafficGenerator(CapturingTrafficGenerator):
166 """Provides access to scapy functions via an RPC interface.
167
168 The traffic generator first starts an XML-RPC on the remote TG node.
169 Then it populates the server with functions which use the Scapy library
170 to send/receive traffic.
171
172 Any packets sent to the remote server are first converted to bytes.
173 They are received as xmlrpc.client.Binary objects on the server side.
174 When the server sends the packets back, they are also received as
175 xmlrpc.client.Binary object on the client side, are converted back to Scapy
176 packets and only then returned from the methods.
177
178 Arguments:
179 tg_node: The node where the traffic generator resides.
180 config: The user configuration of the traffic generator.
181
182 Attributes:
183 session: The exclusive interactive remote session created by the Scapy
184 traffic generator where the XML-RPC server runs.
185 rpc_server_proxy: The object used by clients to execute functions
186 on the XML-RPC server.
187 """
188
189 session: PythonShell
190 rpc_server_proxy: xmlrpc.client.ServerProxy
191 _config: ScapyTrafficGeneratorConfig
192 _tg_node: TGNode
193 _logger: DTSLOG
194
195 def __init__(self, tg_node: TGNode, config: ScapyTrafficGeneratorConfig):
196 self._config = config
197 self._tg_node = tg_node
198 self._logger = getLogger(f"{self._tg_node.name} {self._config.traffic_generator_type}")
199
200 assert (
201 self._tg_node.config.os == OS.linux
202 ), "Linux is the only supported OS for scapy traffic generation"
203
204 self.session = self._tg_node.create_interactive_shell(
205 PythonShell, timeout=5, privileged=True
206 )
207
208 # import libs in remote python console
209 for import_statement in SCAPY_RPC_SERVER_IMPORTS:
210 self.session.send_command(import_statement)
211
212 # start the server
213 xmlrpc_server_listen_port = 8000
214 self._start_xmlrpc_server_in_remote_python(xmlrpc_server_listen_port)
215
216 # connect to the server
217 server_url = f"http://{self._tg_node.config.hostname}:{xmlrpc_server_listen_port}"
218 self.rpc_server_proxy = xmlrpc.client.ServerProxy(
219 server_url, allow_none=True, verbose=SETTINGS.verbose
220 )
221
222 # add functions to the server

Callers 1

create_traffic_generatorFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected