[PATCH v2] dts: add time delay to async sniffer callback function
Nicholas Pratte
npratte at iol.unh.edu
Wed Nov 13 19:56:29 CET 2024
There exists a bug within i40e NICs in which the async sniffer does not
catch send packets as a result of the callback function sending packets
too quickly before the NICs are ready to start capturing.
There could be a multitude of reasons why this happens on these NICs, but
for the time being, inserting a one second delay in the callback function
will suffice.
Bugzilla ID: 1573
Signed-off-by: Nicholas Pratte <npratte at iol.unh.edu>
---
.../testbed_model/traffic_generator/scapy.py | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/dts/framework/testbed_model/traffic_generator/scapy.py b/dts/framework/testbed_model/traffic_generator/scapy.py
index be5ae3b895..434c0a231f 100644
--- a/dts/framework/testbed_model/traffic_generator/scapy.py
+++ b/dts/framework/testbed_model/traffic_generator/scapy.py
@@ -188,22 +188,24 @@ def _shell_create_sniffer(
when set to an empty string.
"""
self._shell_set_packet_list(packets_to_send)
+ # We need to introduce a short delay in the sniffer sendp() for i40e NICs.
+ self.send_command("import time")
sniffer_commands = [
f"{self._sniffer_name} = AsyncSniffer(",
f"iface='{recv_port.logical_name}',",
"store=True,",
# *args is used in the arguments of the lambda since Scapy sends parameters to the
# callback function which we do not need for our purposes.
- "started_callback=lambda *args: sendp(",
+ "started_callback=lambda *args: (time.sleep(1), sendp(",
(
# Additional indentation is added to this line only for readability of the logs.
f"{self._python_indentation}{self._send_packet_list_name},"
- f" iface='{send_port.logical_name}'),"
+ f" iface='{send_port.logical_name}')),"
),
")",
]
if filter_config:
- sniffer_commands.insert(-1, f"filter='{filter_config}'")
+ sniffer_commands.insert(-2, f"filter='{filter_config}'")
self.send_command(f"\n{self._python_indentation}".join(sniffer_commands))
@@ -223,7 +225,8 @@ def _shell_start_and_stop_sniffing(self, duration: float) -> list[Packet]:
"""
sniffed_packets_name = "gathered_packets"
self.send_command(f"{self._sniffer_name}.start()")
- time.sleep(duration)
+ # Insert a one second delay to prevent timeout errors from occurring
+ time.sleep(duration + 1)
self.send_command(f"{sniffed_packets_name} = {self._sniffer_name}.stop(join=True)")
# An extra newline is required here due to the nature of interactive Python shells
packet_strs = self.send_command(
--
2.44.0
More information about the dev
mailing list