Reputation: 79
i am experiencing the following situation:
I open with pcap_open_live()
one of my network-interfaces. Then i am compiling a filter for pcap for only capturing a specified ethernet-type (ether proto 0x1234
). Now i am starting the pcap_loop()
. The only thing, that the callback-function executes, is to send a frame via pcap_inject()
. (The frame is hard-coded as a global char array).
When i compare now the timestamps of the received and the sent frame (e.g. on wireshark on a third non-involved computer) the delay is around 3 milliseconds (minumum 1 millisecond, but also up to 10 milliseconds). So pcap needs in average around 3 milliseconds to proceed with the received frame and calling the callback-function for sending the new frame. I want/have to decrease that delay.
Following things i already tried:
pcap_open_live()
: even a read-timout of -1, which should be to my knowledge a polling, generates a delay of around 3 millisecondsInterrupThrottleRate=0
and other parameters of the e1000
/e1000e
-kernel module to force the hardware sending an interrupt for every single frameBut i never decreased the delay under the average of 3 milliseconds.
For my planned application it is necessary to react to incoming packets in a time unter 100 microseconds. Is this even generally doable with libpcap?! Or are there any other suggestions for realizing such a application?
Thanks for all your replies, i hope anyone can help me!
Notes: I am deploying under Linux/Ubuntu in C/C++.
Upvotes: 4
Views: 2568
Reputation:
For my planned application it is necessary to react to incoming packets in a time under 100 microseconds.
Then the buffering that many of the capture mechanisms atop which libpcap runs (BPF except on AIX, TPACKET_V3 on Linux with newer libpcap and kernel, DLPI on Solaris 10 and earlier, etc.) provide in order to reduce per-packet overhead would get in your way.
If the libpcap on your system has the pcap_set_immediate_mode()
function, then:
pcap_create()
and pcap_activate()
, rather than pcap_open_live()
, to open the capture device;pcap_set_immediate_mode()
between the pcap_create()
and pcap_activate()
calls.In "immediate mode", packets should be delivered to the application by the capture mechanism as soon as the capture mechanism receives them.
Upvotes: 6