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

Function scapy_send_packets_and_capture

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

RPC function to send and capture packets. The function is meant to be executed on the remote TG node. Args: xmlrpc_packets: The packets to send. These need to be converted to xmlrpc.client.Binary before sending to the remote server. send_iface: The logical name

(
    xmlrpc_packets: list[xmlrpc.client.Binary],
    send_iface: str,
    recv_iface: str,
    duration: float,
)

Source from the content-addressed store, hash-verified

65
66
67def scapy_send_packets_and_capture(
68 xmlrpc_packets: list[xmlrpc.client.Binary],
69 send_iface: str,
70 recv_iface: str,
71 duration: float,
72) -> list[bytes]:
73 """RPC function to send and capture packets.
74
75 The function is meant to be executed on the remote TG node.
76
77 Args:
78 xmlrpc_packets: The packets to send. These need to be converted to
79 xmlrpc.client.Binary before sending to the remote server.
80 send_iface: The logical name of the egress interface.
81 recv_iface: The logical name of the ingress interface.
82 duration: Capture for this amount of time, in seconds.
83
84 Returns:
85 A list of bytes. Each item in the list represents one packet, which needs
86 to be converted back upon transfer from the remote node.
87 """
88 scapy_packets = [scapy.all.Packet(packet.data) for packet in xmlrpc_packets]
89 sniffer = scapy.all.AsyncSniffer(
90 iface=recv_iface,
91 store=True,
92 started_callback=lambda *args: scapy.all.sendp(scapy_packets, iface=send_iface),
93 )
94 sniffer.start()
95 time.sleep(duration)
96 return [scapy_packet.build() for scapy_packet in sniffer.stop(join=True)]
97
98
99def scapy_send_packets(xmlrpc_packets: list[xmlrpc.client.Binary], send_iface: str) -> None:

Callers

nothing calls this directly

Calls 1

sleepMethod · 0.80

Tested by

no test coverage detected