Flexible traffic generation with scapy

11,426

On my system I get much better performance sending ethernet frames with sendp compared to sending IP packets using send.

# this gives appox 500pps on my system
pe=Ether()/IP(dst="10.13.37.218")/ICMP()
sendp(pe, loop=True)

# this gives approx 100pps on my system
pi=IP(dst="10.13.37.218")/ICMP()
send(pi, loop=True)

But sending (precreated) packet on the socket manually is way faster:

s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
s.bind(("eth0", 0))
pe=Ether()/IP(dst="10.13.37.218")/ICMP()
data = pe.build()
while True:
    s.send(data)

But moving the pe.build() into the loop drastically reduces speed, hinting that it is the actual packet building that takes time.

Share:
11,426

Related videos on Youtube

DiscoTroy
Author by

DiscoTroy

Updated on June 28, 2022

Comments

  • DiscoTroy
    DiscoTroy almost 2 years

    I know questions like this have been asked plenty of times before, but I think this is subtley different.

    I am attempting to write a flexible traffic generator in Python using scapy. Producing the packet is fine, but when it comes to sending traffic at a sufficiently fast rate (for my needs, somewhere in the range of 500-700 packets per second), I seem to have hit a wall at around 20-30 pps.

    I believe that there may be some need for threading, or am I missing something easier?

  • stillanoob
    stillanoob about 6 years
    How do you compute (or estimate) PPS?