How to set a loop forwarding using one NIC to TX packets and RX them itself in DPDK testpmd?

Viewed 433

I want to implement a scene like this:

  1. A packet received in NIC's RXQ 0
  2. NIC gets it and puts it in it's TXQ 0
  3. By some way(NIC's effort?), the packet will be sent to the NIC's RXQ 0, and back to step 1.

I think the forward mode tx_first is what I need.

NIC: PMD: MLX5 version: 5.0-1.0.0.0

DPDK Version: 20.11.1

full command line

./testpmd.sh 0 11-12 1 1 testpmd0 3b:00.0
#testpmd.sh
#if [ $# -ne 6 ]
#then
#       echo $0" <socket_id> <core_list> <core_num> <queue_num> <prefix>"
#       exit 255
#fi
        ./build/app/dpdk-testpmd -l $2 -n 4 \
        --socket-mem=2048,2048 \
        -a $6,txq_inline=200,txq_mpw
        --file-prefix=$5 \
        -- \
        -i \
        --mbcache=512 \
        --txonly-multi-flow \
        --rxd=2048 --txd=2048 \
        --rxq=$4 --txq=$4 \
        --nb-cores=$3 \
        --port-topology=loop \
        --numa --socket-num=$1 --port-numa-config=0,$1 --ring-numa-config=0,3,$1

But after I set command line arg --port-topology=loop and tried the start tx_first

The stream is:

testpmd> start tx_first
io packet forwarding - ports=1 - cores=1 - streams=1 - NUMA support enabled, MP allocation mode: native
Logical Core 12 (socket 0) forwards packets on 1 streams:
  RX P=0/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00

I got the stats:

testpmd> show fwd stats all

  ---------------------- Forward statistics for port 0  ----------------------
  RX-packets: 6              RX-dropped: 0             RX-total: 6
  TX-packets: 38             TX-dropped: 0             TX-total: 38
  ----------------------------------------------------------------------------

  +++++++++++++++ Accumulated forward statistics for all ports+++++++++++++++
  RX-packets: 6              RX-dropped: 0             RX-total: 6
  TX-packets: 38             TX-dropped: 0             TX-total: 38
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#32 same packets like this
restore info: - no tunnel info - no outer header - no miss group
  src=04:3F:72:CB:21:46 - dst=02:00:00:00:00:00 - type=0x0800 - length=64 - nb_segs=1 - sw ptype: L2_ETHER L3_IPV4 L4_UDP  - l2_len=14 - l3_len=20 - l4_len=8 - Send queue=0x0
  ol_flags: PKT_RX_L4_CKSUM_UNKNOWN PKT_RX_IP_CKSUM_UNKNOWN PKT_RX_OUTER_L4_CKSUM_UNKNOWN

# discrete but same packets received
testpmd> port 0/queue 0: received 1 packets
restore info: - no tunnel info - no outer header - no miss group
  src=F4:74:88:8C:11:86 - dst=01:80:C2:00:00:00 - type=0x0069 - length=119 - nb_segs=1 - hw ptype: L2_ETHER  - sw ptype: L2_ETHER  - l2_len=14 - Receive queue=0x0
  ol_flags: PKT_RX_L4_CKSUM_UNKNOWN PKT_RX_IP_CKSUM_UNKNOWN PKT_RX_OUTER_L4_CKSUM_UNKNOWN
port 0/queue 0: sent 1 packets
restore info: - no tunnel info - no outer header - no miss group
  src=F4:74:88:8C:11:86 - dst=01:80:C2:00:00:00 - type=0x0069 - length=119 - nb_segs=1 - hw ptype: L2_ETHER  - sw ptype: L2_ETHER  - l2_len=14 - Send queue=0x0
  ol_flags: PKT_RX_L4_CKSUM_UNKNOWN PKT_RX_IP_CKSUM_UNKNOWN PKT_RX_OUTER_L4_CKSUM_UNKNOWN
port 0/queue 0: received 1 packets
restore info: - no tunnel info - no outer header - no miss group
  src=F4:74:88:8C:11:86 - dst=01:80:C2:00:00:00 - type=0x0069 - length=119 - nb_segs=1 - hw ptype: L2_ETHER  - sw ptype: L2_ETHER  - l2_len=14 - Receive queue=0x0
  ol_flags: PKT_RX_L4_CKSUM_UNKNOWN PKT_RX_IP_CKSUM_UNKNOWN PKT_RX_OUTER_L4_CKSUM_UNKNOWN

The NIC didn't RX the Tx packets it sent, why?

1 Answers

In order to set DPDK application dpdk-tespmd in loopback mode it requires 2 DPDK ports and --port-topology=loop.

But if there is only 1 Physical NIC port there are a couple of options to set the DPDK interface in loopback mode

  1. Physical transreciever where TX and RX and cross-connected
  2. NIC with embedded switch configured in fabric loopback mode
  3. if connected to external switch enabling MAC|PHY loopback on switch.

Once configured in any of the above 3 modes, run the following commands

  1. set eth-peer 0 [desired DST MAC address]
  2. set fwd macswp
  3. start tx_first

to validate the same without physical NIC start testpmd as ./build/app/testpmd -l 2-3 --vdev=net_tap0,iface=testDpdk0 -- -i --rxq=1 --txq=1. Setting verbosity for RX packet set verbose 2

Related