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

Method __init__

dpdk/dts/framework/testbed_model/scapy.py:195–230  ·  view source on GitHub ↗
(self, tg_node: TGNode, config: ScapyTrafficGeneratorConfig)

Source from the content-addressed store, hash-verified

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
223 for function in RPC_FUNCTIONS:
224 # A slightly hacky way to move a function to the remote server.
225 # It is constructed from the name and code on the other side.
226 # Pickle cannot handle functions, nor can any of the other serialization
227 # frameworks aside from the libraries used to generate pyc files, which
228 # are even more messy to work with.
229 function_bytes = marshal.dumps(function.__code__)
230 self.rpc_server_proxy.add_rpc_function(function.__name__, function_bytes)
231
232 def _start_xmlrpc_server_in_remote_python(self, listen_port: int):
233 # load the source of the function

Callers

nothing calls this directly

Calls 5

getLoggerFunction · 0.90
add_rpc_functionMethod · 0.80
send_commandMethod · 0.45

Tested by

no test coverage detected