I am using Scapy
to forge random tcp and udp flows to test packet-in flooding in my SDN experiment. But I don't know how to control Scapy
sending packets speed. For example, if I want to set Scapy
sending packets 1000 pkt/s, what should I do ?
The most efficient way would be to use scapy’s sendpfast
together with tcpreplay
(it must be installed):
>>> pkt = Ether()/IP()/TCP()/"blobofdata". # must be layer 2
# let’s send 10000 packets at 1000 packets per seconds
>>> sendpfast(pkt, pps=1000, loop=10000, parse_results=1)
{'packets': 10000,
'bytes': 660000,
'time': 9.99,
'bps': 66006.1,
'mbps': 0.528,
'pps': 1000.09,
'flows': 1,
'fps': 0.1,
'flow_packets': 100000000,
'non_flow': 0,
'successful': 10000,
'failed': 0,
'truncated': 0,
'retried_enobufs': 0,
'retried_eagain': 0,
'command': 'tcpreplay --intf1=enp0s3 --pps=1000 --loop=10000 /tmp/scapyo6ilzjdk',
'warnings': []}
>>>
You even get some stats. This allows to workaround Python limitations that wouldn’t allow such a high rate of packets.
If you are aiming at lower rates, you could use inter
from send
>>> sendp(pkt, count=10000, inter=1./20) # 20 packets per second
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With