af_xdp: add option to claim all available rx queues
[vpp.git] / src / plugins / af_xdp / af_xdp_doc.md
1 # AF_XDP Ethernet driver {#af_xdp_doc}
2
3 This driver relies on Linux AF_XDP socket to rx/tx Ethernet packets.
4
5 ## Maturity level
6 Under development: it should work, but has not been thoroughly tested.
7
8 ## Features
9  - copy and zero-copy mode
10  - multiqueue
11  - API
12  - custom eBPF program
13  - polling, interrupt and adaptive mode
14
15 ## Limitations
16 Because of AF_XDP restrictions, the MTU is limited to below PAGE_SIZE
17 (4096-bytes on most systems) minus 256-bytes, and they are additional
18 limitations depending upon specific Linux device drivers.
19 As a rule of thumb, a MTU of 3000-bytes or less should be safe.
20 Furthermore, upon UMEM creation, the kernel allocates a
21 physically-contiguous structure, whose size is proportional to the number
22 of 4KB pages contained in the UMEM. That allocation might fail when
23 the number of buffers allocated by VPP is too high. That number can be
24 controlled with the `buffers { buffers-per-numa }` configuration option.
25 Finally, note that because of this limitation, this plugin is unlikely
26 to be compatible with the use of 1GB hugepages.
27
28 ## Requirements
29 The Linux kernel interface must be up and have enough queues before
30 creating the VPP AF_XDP interface, otherwise Linux will deny creating
31 the AF_XDP socket.
32 The AF_XDP interface will claim NIC RX queue starting from 0, up to the
33 requested number of RX queues (only 1 by default). It means all packets
34 destined to NIC RX queue `[0, num_rx_queues[` will be received by the
35 AF_XDP interface, and only them. Depending on your configuration, there
36 will usually be several RX queues (typically 1 per core) and packets are
37 spread accross queues by RSS. In order to receive consistent traffic,
38 you **must** program the NIC dispatching accordingly. The simplest way
39 to get all the packets is to specify `num-rx-queues all` to grab all
40 available queues or to reconfigure the Linux kernel driver to use only
41 `num_rx_queues` RX queues (ie all NIC queues will be associated with
42 the AF_XDP socket):
43 ```
44 ~# ethtool -L <iface> combined <num_rx_queues>
45 ```
46 Additionally, the VPP AF_XDP interface will use a MAC address generated at
47 creation time instead of the Linux kernel interface MAC. As Linux kernel
48 interface are not in promiscuous mode by default (see below) this will
49 results in a useless configuration where the VPP AF_XDP interface only
50 receives packets destined to the Linux kernel interface MAC just to drop
51 them because the destination MAC does not match VPP AF_XDP interface MAC.
52 If you want to use the Linux interface MAC for the VPP AF_XDP interface,
53 you can change it afterwards in VPP:
54 ```
55 ~# vppctl set int mac address <iface> <mac>
56 ```
57 Finally, if you wish to receive all packets and not only the packets
58 destined to the Linux kernel interface MAC you need to set the Linux
59 kernel interface in promiscuous mode:
60 ```
61 ~# ip link set dev <iface> promisc on
62 ```
63
64 ## Security considerations
65 When creating an AF_XDP interface, it will receive all packets arriving
66 to the NIC RX queue [0, num_rx_queues[`. You need to configure the Linux
67 kernel NIC driver properly to ensure that only intented packets will
68 arrive in this queue. There is no way to filter the packets after-the-fact
69 using eg. netfilter or eBPF.
70
71 ## Quickstart
72 1. Put the Linux kernel interface up and in promiscuous mode:
73 ```
74 ~# ip l set dev enp216s0f0 promisc on up
75 ```
76 2. Create the AF_XDP interface:
77 ```
78 ~# vppctl create int af_xdp host-if enp216s0f0 num-rx-queues all
79 ```
80 3. Use the interface as usual, eg.:
81 ```
82 ~# vppctl set int ip addr enp216s0f0/0 1.1.1.1/24
83 ~# vppctl set int st enp216s0f0/0 up
84 ~# vppctl ping 1.1.1.100`
85 ```
86
87 ## Custom eBPF XDP program
88 This driver relies on libbpf and as such relies on the `xsks_map` eBPF
89 map.  The default behavior is to use the XDP program already attached
90 to the interface if any, otherwise load the default one.
91 You can request to load a custom XDP program with the `prog` option when
92 creating the interface in VPP:
93 ```
94 ~# vppctl create int af_xdp host-if enp216s0f0 num-rx-queues 4 prog extras/bpf/af_xdp.bpf.o
95 ```
96 In that case it will replace any previously attached program.  A custom
97 XDP program example is provided in `extras/bpf/`.
98
99 ## Performance consideration
100 AF_XDP relies on the Linux kernel NIC driver to rx/tx packets. To reach
101 high-performance (10's MPPS), the Linux kernel NIC driver must support
102 zero-copy mode and its RX path must run on a dedicated core in the NUMA
103 where the NIC is physically connected.