Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AF_XDP socket extension using libxdp api #797

Conversation

plangarbalint
Copy link
Contributor

@plangarbalint plangarbalint commented May 2, 2023

The aim of this change is to extend existing packet sending methods with AF_XDP socket using libxdp api.

By using AF_XDP socket, the time needed for packet sending can be decreased substantially.

  • all the relevant changes are inside a #ifdef HAVE_LIBXDP guard
  • --batch-size flag is introduced to tcpreplay interface. AF_XDP socket is used typically with batch of packets, the default value is 25 however the user can set it using --batch-size flag, the maximum value is set to 4096 now (see my reasoning at the very end of this comment).
  • Due to batch processing feature tcpr_sleep will be called only in case --batch-size=1, since it doesn't make sense to sleep the relative time between two packets when batch-size is higher than 1.
  • Due to batch processing feature statistics calculated during packet processing are also updated (e.g. number of packets, sum of bytes sent etc.)
  • Due to the hierarchical nature of packet sending selection (if ... else if ... include guards in sendpacket.c), --enable-force-libxdp is introduced which can be used at the configuration step to force libxdp packet sending method
  • The dependencies of libxdp is checked at the configuration step and the output table of configuration step is also updated with libxdp information
  • The size of UMEM memory is set to nb_of_frames = 4096 * frame_size = 4096 as a result the current implementation assumes that a packet size is never larger than 4096 byte. The new implementation makes it possible to reuse memory, since packet sending is organized into batches. Each of the batches requires a fixed amount of memory, after each of the batches the program checks whether all the packets in the given batch have been sent, if yes, the program can start working on the next batch.
  • This implementation is also compatible with the existing tcpreplay interface e.g. -K (to cache packets), -topspeed, --loop flags are still available

Potential improvement suggestions which are not part of this PR:

  • Optimize reserved memory. The minimum reserved memory that is required equals to batch_size * frame_size, since user should copy the packet data to an umem frame as a first step of packet sending. As a result it would be an advantage to let users decide how much memory should be reserved by setting batch_size and frame_size on the interface. Batch size is introduced to the interface however it is not connected to umem creation. As mentioned before this implementation reserves 4096 * 4096 bytes, however it should be customized. In case batch-size is set to 25 then only the first 25 * 4096 bytes of memory is used.

@fklassen fklassen self-assigned this May 30, 2023
@fklassen
Copy link
Member

fklassen commented Jun 5, 2023

Thanks for the PR. I have wanted to build and AF_XDP implementation for years. Targetting version 4.5 which hopefully will happen soon.

configure.ac Outdated
@@ -826,7 +830,13 @@ fi

# libpcap can require libnl
AC_SEARCH_LIBS([nl_handle_alloc], [nl],
[AC_MSG_NOTICE([Unable to find nl library - may be needed by libpcap])])
[AC_MSG_NOTICE([Unable to find xdp library - may be needed by libpcap])])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a copy/paste error?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, its very likely copy-paste mistake/quick experiment left in the final PR.
This line should be unmodified, as in the original code.

@fklassen
Copy link
Member

fklassen commented Sep 3, 2023

Bringing into a development branch to resolve conficts and test, while maintaining history.

@fklassen fklassen changed the base branch from master to Feature_#822_AF_XDF_socket_extension September 3, 2023 23:57
#include <net/bpf.h>
#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1
#endif

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy/paste error

@fklassen fklassen merged commit 0f012c8 into appneta:Feature_#822_AF_XDF_socket_extension Sep 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants