@@ -66,21 +66,21 @@ default spread flows with RSS-hashing over all available RX-queues. Thus,
6666traffic likely not hitting queue you expect.
6767
6868In order to fix that problem, you *MUST* configure the NIC to steer flow to a specific RX-queue.
69- This can be done via ethtool or TC HW offloading filter setup.
69+ This can be done via ethtool or TC HW offloading filter setup.
7070
7171The following example shows how to configure the NIC to steer all UDP ipv4 traffic
72- to /RX-queue id/ 42:
72+ to /RX-queue id/ 42:
7373
7474#+begin_example sh
7575ethtool -N <interface> flow-type udp4 action 42
7676#+end_example
7777
7878The parameter /action/ specifies the id of the target /RX-queue/.
7979
80- In general, a flow rule is composed of a matching criteria and an action.
80+ In general, a flow rule is composed of a matching criteria and an action.
8181L2, L3 and L4 header values can be used to specify the matching criteria.
82- For a comprehensive documentation, please check out the man page of ethtool.
83- It documents all available header values that can be used as part of the matching criteria.
82+ For a comprehensive documentation, please check out the man page of ethtool.
83+ It documents all available header values that can be used as part of the matching criteria.
8484
8585
8686Alternative work-arounds:
@@ -108,17 +108,85 @@ XDP_REDIRECT and XDP_PASS, then "copy-mode" can be relevant. As in
108108"zero-copy" mode doing XDP_PASS have a fairly high cost, which involves
109109allocating memory and copying over the frame.
110110
111- * Missing elements
111+ * Assignments
112+ The end goal of this lesson is to build an AF_XDP program that will send
113+ packets to userspace and if they are IPv6 ping packets reply.
112114
113- *Lesson incomplete*
115+ We will do using the automatically installed XDP program, but one of the
116+ assignments it to implement this manually.
114117
115- This lesson is missing some assignments, but first we need to provide an
116- AF_XDP sample program. The sample should use the libbpf API for AF_XDP
117- sockets. It also need to include an actual XDP bpf program that is more
118- robust, and demonstrate how to read the RXQ-info about the RX-queue number,
119- and only redirect if the RX-queue id match, and maybe give stats on redirect
120- vs. XDP_PASS (not matching RX-queue id) packets.
118+ ** Assignment 1: Run the example program to eat all packets
119+ First, you need to set up the test lab environment and start an infinite
120+ ping. You do this by running the following:
121+ #+begin_example sh
122+ $ eval $(../testenv/testenv.sh alias)
123+ $ t setup --name veth-adv03
124+ $ t ping
125+ #+end_example
126+
127+ Now you can start the af_xdp_user application and see all the pings being
128+ eaten by it:
129+
130+ #+begin_example sh
131+ $ sudo ./af_xdp_user -d veth-adv03
132+ [sudo] password for echaudro:
133+ AF_XDP RX: 2 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000185
134+ TX: 0 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000185
135+
136+ AF_XDP RX: 4 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000152
137+ TX: 0 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000152
138+ #+end_example
139+
140+ ** Assignment 2: Write an XDP program to process every other packet
141+ For this exercise, you need to write an eBPF program that will count the
142+ packets received, and use this value to determine if the packet needs to be
143+ sent down the AF_XDP socket. We want every other packet to be sent to the
144+ AF_XDP socket.
145+
146+ This should result in every other ping packet being replied too. Here is the
147+ expected output from the ping command, notice the icmp_seq numbers:
148+ #+begin_example sh
149+ $ t ping
150+ Running ping from inside test environment:
151+
152+ PING fc00:dead:cafe:1::1(fc00:dead:cafe:1::1) 56 data bytes
153+ 64 bytes from fc00:dead:cafe:1::1: icmp_seq=2 ttl=64 time=0.038 ms
154+ 64 bytes from fc00:dead:cafe:1::1: icmp_seq=4 ttl=64 time=0.047 ms
155+ 64 bytes from fc00:dead:cafe:1::1: icmp_seq=6 ttl=64 time=0.062 ms
156+ 64 bytes from fc00:dead:cafe:1::1: icmp_seq=8 ttl=64 time=0.083 ms
157+ #+end_example
158+
159+ If you have your custom program ready you can bind it using the --filename
160+ option:
161+
162+ #+begin_example sh
163+ $ sudo ./af_xdp_user -d veth-adv03 --filename af_xdp_kern.o
164+ AF_XDP RX: 1 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000171
165+ TX: 0 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000171
166+
167+ AF_XDP RX: 2 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000133
168+ TX: 0 pkts ( 0 pps) 0 Kbytes ( 0 Mbits/s) period:2.000133
169+ #+end_example
170+
171+ Note that the full solution is included in the af_xdp_kern.c file.
172+
173+
174+ ** Assignment 3: Write an userspace program to reply to IPv6 ping packets
175+ For the final exercise, you need to write some userspace code that will
176+ reply to the ping packets. This needs be done inside the process_packet()
177+ function.
178+
179+ Once you have done this all pings should receive a reply:
180+ #+begin_example sh
181+ $ sudo ./af_xdp_user -d veth-adv03
182+ AF_XDP RX: 2 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000175
183+ TX: 2 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000175
184+
185+ AF_XDP RX: 4 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000146
186+ TX: 4 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000146
187+
188+ AF_XDP RX: 6 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000118
189+ TX: 6 pkts ( 1 pps) 0 Kbytes ( 0 Mbits/s) period:2.000118
190+ #+end_example
121191
122- Note: One of the reasons for providing a BPF C-code example is that the
123- kernel removed =samples/bpf/xdpsock_kern.c=, when libbpf was extended with
124- static BPF-instructions for AF_XDP redirect.
192+ Note that the full solution is present in the ad_xdp_user.c file.
0 commit comments