《DPDK Testpmd 应用》
《DPDK Testpmd 应用》
《DPDK Testpmd 应用》
Release 2.0.0
1 Introduction 2
1.1 Documentation Roadmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 Overview 3
i
Testpmd Application User Guide, Release 2.0.0
CONTENTS 1
CHAPTER
ONE
INTRODUCTION
This document is a user guide for the testpmd example application that is shipped as part of
the Data Plane Development Kit.
The testpmd application can be used to test the DPDK in a packet forwarding mode and also
to access NIC hardware features such as Flow Director. It also serves as a example of how to
build a more fully-featured application using the DPDK SDK.
Note: These documents are available for download as a separate documentation package at
the same location as the DPDK code package.
2
CHAPTER
TWO
OVERVIEW
The following sections show how to build and run the testpmd application and how to configure
the application from the command line and the run-time environment.
3
CHAPTER
THREE
The testpmd application is compiled as part of the main compilation of the DPDK libraries and
tools. Refer to the DPDK Getting Started Guide for details. The basic compilation steps are:
1. Set the required environmental variables and go to the source directory:
export RTE_SDK=/path/to/rte_sdk
cd $RTE_SDK
4
CHAPTER
FOUR
The following are the EAL command-line options that can be used in conjunction with the
testpmd, or any other DPDK application. See the DPDK Getting Started Guide for more infor-
mation on these options.
• -c COREMASK
Set the hexadecimal bitmask of the cores to run on.
• -l CORELIST
List of cores to run on
The argument format is <c1>[-c2][,c3[-c4],...] where c1, c2, etc are core indexes between
0 and 128
• –lcores COREMAP
Map lcore set to physical cpu set
The argument format is ‘<lcores[@cpus]>[<,lcores[@cpus]>...]’
lcores and cpus list are grouped by ‘(‘ and ‘)’ Within the group, ‘-‘ is used for range
separator, ‘,’ is used for single number separator. ‘( )’ can be omitted for single element
group, ‘@’ can be omitted if cpus and lcores have the same value
• –master-lcore ID
Core ID that is used as master
• -n NUM
Set the number of memory channels to use.
• -b, –pci-blacklist domain:bus:devid.func
Blacklist a PCI devise to prevent EAL from using it. Multiple -b options are allowed.
• -d LIB.so
Load an external driver. Multiple -d options are allowed.
• -w, –pci-whitelist domain:bus:devid:func
Add a PCI device in white list.
5
Testpmd Application User Guide, Release 2.0.0
• -m MB
Memory to allocate. See also –socket-mem.
• -r NUM
Set the number of memory ranks (auto-detected by default).
• -v
Display the version information on startup.
• –xen-dom0
Support application running on Xen Domain0 without hugetlbfs.
• –syslog
Set the syslog facility.
• –socket-mem
Set the memory to allocate on specific sockets (use comma separated values).
• –huge-dir
Specify the directory where the hugetlbfs is mounted.
• –proc-type
Set the type of the current process.
• –file-prefix
Prefix for hugepage filenames.
• -vmware-tsc-map
Use VMware TSC map instead of native RDTSC.
• –vdev
Add a virtual device, with format “<driver><id>[,key=val, ...]”, e.g. –
vdev=eth_pcap0,iface=eth2.
• –base-virtaddr
Specify base virtual address.
• –create-uio-dev
Create /dev/uioX (usually done by hotplug).
• –no-shconf
No shared config (mmap’d files).
• –no-pci
Disable pci.
• –no-hpet
Disable hpet.
• –no-huge
Use malloc instead of hugetlbfs.
The following are the command-line options for the testpmd applications. They must be sepa-
rated from the EAL options, shown in the previous section, with a – separator:
sudo ./testpmd -c 0xF -n 4 -- -i --portmask=0x1 --nb-cores=2
• -i, –interactive
Run testpmd in interactive mode. In this mode, the testpmd starts with a prompt that
can be used to start and stop forwarding, configure the application and display stats on
the current packet processing session. See the Section Testpmd Runtime Functions for
more details.
In non-interactive mode, the application starts with the configuration specified on the
command-line and immediately enters forwarding mode.
• -h, –help
Display a help message and quit.
• -a, –auto-start
Start forwarding on init.
• –nb-cores=N
Set the number of forwarding cores, where 1 <= N <= number of cores or
RTE_MAX_LCORE from the configuration file. The default value is 1.
• –nb-ports=N
Set the number of forwarding ports, where 1 <= N <= number of ports on the board or
RTE_MAX_ETHPORTS from the configuration file. The default value is the number of
ports on the board.
• –coremask=0xXX
Set the hexadecimal bitmask of the cores running the packet forwarding test. The master
lcore is reserved for command line parsing only and cannot be masked on for packet
forwarding.
• –portmask=0xXX
Set the hexadecimal bitmask of the ports used by the packet forwarding test.
• –numa
Enable NUMA-aware allocation of RX/TX rings and of RX memory buffers (mbufs).
• –port-numa-config=(port,socket)[,(port,socket)]
Specify the socket on which the memory pool to be used by the port will be allocated.
• –ring-numa-config=(port,flag,socket)[,(port,flag,socket)]
Specify the socket on which the TX/RX rings for the port will be allocated. Where flag is
1 for RX, 2 for TX, and 3 for RX and TX.
• –socket-num=N
Set the socket from which all memory is allocated in NUMA mode, where 0 <= N <
number of sockets on the board.
• –mbuf-size=N
Set the data size of the mbufs used to N bytes, where N < 65536. The default value is
2048.
• –total-num-mbufs=N
Set the number of mbufs to be allocated in the mbuf pools, where N > 1024.
• –max-pkt-len=N
Set the maximum packet size to N bytes, where N >= 64. The default value is 1518.
• –eth-peers-configfile=name
Use a configuration file containing the Ethernet addresses of the peer ports. The config-
uration file should contain the Ethernet addresses on separate lines:
XX:XX:XX:XX:XX:01
XX:XX:XX:XX:XX:02
...
• –eth-peer=N,XX:XX:XX:XX:XX:XX
Set the MAC address XX:XX:XX:XX:XX:XX of the peer port N, where 0 <= N <
RTE_MAX_ETHPORTS from the configuration file.
• –pkt-filter-mode=mode
Set Flow Director mode where mode is either none (the default), signature or perfect.
See the Section flow_director_filter for more detail.
• –pkt-filter-report-hash=mode
Set Flow Director hash match reporting mode where mode is none, match (the default)
or always.
• –pkt-filter-size=N
Set Flow Director allocated memory size, where N is 64K, 128K or 256K. Sizes are in
kilobytes. The default is 64.
• –pkt-filter-flexbytes-offset=N
Set the flexbytes offset. The offset is defined in words (not bytes) counted from the first
byte of the destination Ethernet MAC address, where N is 0 <= N <= 32. The default
value is 0x6.
• –pkt-filter-drop-queue=N
Set the drop-queue. In perfect filter mode, when a rule is added with queue = -1, the
packet will be enqueued into the RX drop-queue. If the drop-queue does not exist, the
packet is dropped. The default value is N=127.
• –crc-strip
Enable hardware CRC stripping.
• –enable-rx-cksum
Enable hardware RX checksum offload.
• –disable-hw-vlan
Disable hardware VLAN.
• –disable-hw-vlan-filter
Disable hardware VLAN filter.
• –disable-hw-vlan-strip
Disable hardware VLAN strip.
• –disable-hw-vlan-extend
Disable hardware VLAN extend.
• –enable-drop-en
Enable per-queue packet drop for packets with no descriptors.
• –disable-rss
Disable RSS (Receive Side Scaling).
• –port-topology=mode
Set port topology, where mode is paired(the default) or chained. In paired mode, the
forwarding is between pairs of ports, for example: (0,1), (2,3), (4,5). In chained mode,
the forwarding is to the next available port in the port mask, for example: (0,1), (1,2), (2,0).
The ordering of the ports can be changed using the portlist testpmd runtime function.
• –forward-mode=N
Set forwarding mode. (N: io|mac|mac_retry|mac_swap|flowgen|rxonly|txonly|csum|icmpecho)
• –rss-ip
Set RSS functions for IPv4/IPv6 only.
• –rss-udp
Set RSS functions for IPv4/IPv6 and UDP.
• –rxq=N
Set the number of RX queues per port to N, where 1 <= N <= 65535. The default value
is 1.
• –rxd=N
Set the number of descriptors in the RX rings to N, where N > 0. The default value is
128.
• –txq=N
Set the number of TX queues per port to N, where 1 <= N <= 65535. The default value
is 1.
• –txd=N
Set the number of descriptors in the TX rings to N, where N > 0. The default value is 512.
• –burst=N
Set the number of packets per burst to N, where 1 <= N <= 512. The default value is 16.
• –mbcache=N
Set the cache of mbuf memory pools to N, where 0 <= N <= 512. The default value is 16.
• –rxpt=N
Set the prefetch threshold register of RX rings to N, where N >= 0. The default value is
8.
• –rxht=N
Set the host threshold register of RX rings to N, where N >= 0. The default value is 8.
• –rxfreet=N
Set the free threshold of RX descriptors to N, where 0 <= N < value of –rxd. The default
value is 0.
• –rxwt=N
Set the write-back threshold register of RX rings to N, where N >= 0. The default value
is 4.
• –txpt=N
Set the prefetch threshold register of TX rings to N, where N >= 0. The default value is
36.
• –txht=N
Set the host threshold register of TX rings to N, where N >= 0. The default value is 0.
• –txwt=N
Set the write-back threshold register of TX rings to N, where N >= 0. The default value is
0.
• –txfreet=N
Set the transmit free threshold of TX rings to N, where 0 <= N <= value of –txd. The
default value is 0.
• –txrst=N
Set the transmit RS bit threshold of TX rings to N, where 0 <= N <= value of –txd. The
default value is 0.
• –txqflags=0xXXXXXXXX
Set the hexadecimal bitmask of TX queue flags, where 0 <= N <= 0x7FFFFFFF. The
default value is 0.
Note:
When using hardware offload functions such as vlan, checksum...,
add txqflags=0, since depending on the PMD,
txqflags might be set to a non-zero value.
• –rx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping)]
Set the RX queues statistics counters mapping 0 <= mapping <= 15.
• –tx-queue-stats-mapping=(port,queue,mapping)[,(port,queue,mapping)]
Set the TX queues statistics counters mapping 0 <= mapping <= 15.
• –no-flush-rx
Don’t flush the RX streams before starting forwarding. Used mainly with PCAP drivers.
• –txpkts=X[,Y]
Set TX segment sizes.
• –disable-link-check
Disable check on link status when starting/stopping ports.
FIVE
The testpmd prompt has some, limited, readline support. Common bash command- line func-
tions such as Ctrl+a and Ctrl+e to go to the start and end of the prompt line are supported as
well as access to the command history via the up-arrow.
There is also support for tab completion. If you type a partial command and hit <TAB> you get
a list of the available completions:
testpmd> show port <TAB>
The testpmd has on-line help for the functions that are available at runtime. These are divided
into sections and can be accessed using help, help section or help all:
testpmd> help
12
Testpmd Application User Guide, Release 2.0.0
5.2.1 start
Start packet forwarding with current configuration after sending one burst of packets:
start tx_first
5.2.3 stop
5.2.4 quit
Quit to prompt:
quit
The functions in the following sections are used to display information about the testpmd con-
figuration or the NIC status.
Display the RSS hash functions and RSS hash key of a port:
show port (port_id) rss-hash [key]
Clear the port statistics for a given port or for all ports:
clear port (info|stats|fdir|stat_qmap) (port_id|all)
For example:
testpmd> clear port stats all
Displays the configuration of the application. The configuration comes from the command-line,
the runtime or the application defaults:
The testpmd application can be configured from the runtime as well as from the command-line.
This section details the available configuration functions that are available.
Note: The number of cores used must not be greater than number of ports used multiplied by
the number of queues per port.
Note: The master lcore is reserved for command line parsing only and cannot be masked on
for packet forwarding.
Note: The cores are used in the same order as specified on the command line.
Add a VLAN ID, or all identifiers, to the set of VLAN identifiers filtered by port ID:
rx_vlan add (vlan_id|all) (port_id)
Note: VLAN filter must be set on that port. VLAN ID < 4096. Depending on the NIC used,
number of vlan_ids may be limited to the maximum entries in VFTA table. This is important if
enabling all vlan_ids.
5.4.17 rx_vlan rm
Remove a VLAN ID, or all identifiers, from the set of VLAN identifiers filtered by port ID:
rx_vlan rm (vlan_id|all) (port_id)
Add a VLAN ID, to the set of VLAN identifiers filtered for VF(s) for port ID:
rx_vlan add (vlan_id) port (port_id) vf (vf_mask)
Remove a VLAN ID, from the set of VLAN identifiers filtered for VF(s) for port ID:
rx_vlan rm (vlan_id) port (port_id) vf (vf_mask)
Select hardware or software calculation of the checksum when transmitting a packet using the
csum forward engine:
csum set (ip|udp|tcp|sctp|outer-ip) (hw|sw) (port_id)
• ip|udp|tcp|sctp always concern the inner layer.
• outer-ip concerns the outer IP layer in case the packet is recognized as a tunnel packet
by the forward engine (vxlan, gre and ipip are supported). See “csum parse-tunnel”
command.
Define how tunneled packets should be handled by the csum forward engine.
csum parse-tunnel (on|off) (tx_port_id)
If enabled, the csum forward engine will try to recognize supported tunnel headers (vxlan, gre,
ipip).
If disabled, treat tunnel packets as non-tunneled packets (a inner header is handled as a packet
payload).
Note: The port argument is the TX port like in the “csum set” command.
Example:
Consider a packet as following: “eth_out/ipv4_out/udp_out/vxlan/eth_in/ipv4_in/tcp_in”
• If parse-tunnel is enabled, the ip|udp|tcp|sctp parameters of “csum set” command are
about inner headers (here ipv4_in and tcp_in), and the outer-ip parameter is about outer
headers (here ipv4_out).
• If parse-tunnel is disabled, the ip|udp|tcp|sctp parameters of “csum set” command are
about outer headers, here ipv4_out and udp_out.
Set the promiscuous mode on for a port or for all ports. In promiscuous mode packets are not
dropped if they aren’t for the specified MAC address:
set promisc (port_id|all) (on|off)
Flush (default) or don’t flush RX streams before forwarding. Mainly used with PCAP drivers to
avoid the default behavior of flushing the first 512 packets on RX streams.
set flush_rx off
Set the bypass mode for the lowest port on bypass enabled NIC.
set bypass mode (normal|bypass|isolate) (port_id)
Set the event required to initiate specified bypass mode for the lowest port on a bypass enabled
NIC where:
• timeout: enable bypass after watchdog timeout.
Show the bypass configuration for a bypass enabled NIC using the lowest port on the NIC.
show bypass config (port_id)
Note: Port configuration changes only become active when forwarding is started/restarted.
In this case, identifier is “eth_pcap0,iface=eth0”. This identifier format is the same as “–vdev”
format of DPDK applications.
Set the speed and duplex mode for all ports or a specific port:
port config (port_id|all) speed (10|100|1000|10000|auto) duplex (half|full|auto)
Set packet drop for packets with no descriptors on or off for all ports:
port config all drop-en (on|off)
Packet dropping for packets with no descriptors is off by default.
The on option is equivalent to the –enable-drop-en command-line option.
The Link Bonding functions make it possible to dynamically create and manage link bonding
devices from within testpmd interactive prompt.
Set an Ethernet slave device as the primary device on a Link Bonding device:
set bonding primary (slave id) (port id)
For example, to set the Ethernet slave device (port 6) as the primary port of a Link Bonding
device (port 10).
testpmd> set bonding primary 6 10
Set the transmission policy for a Link Bonding device when it is in Balance XOR mode:
set bonding xmit_balance_policy (port_id) (l2|l23|l34)
For example, set a Link Bonding device (port 10) to use a balance policy of layer 3+4 (IP
addresses & UDP ports )
testpmd> set bonding xmit_balance_policy 10 l34
Set the link status monitoring polling period in milliseconds for a bonding device.
This adds support for PMD slave devices which do not support link status interrupts. When the
mon_period is set to a value greater than 0 then all PMD’s which do not support link status ISR
will be queried every polling interval to check if their link status has changed.
set bonding mon_period (port_id) (value)
For example, to set the link status monitoring polling period of bonded device (port 5) to 150ms
testpmd> set bonding mon_period 5 150
The Register functions can be used to read from and write to registers on the network card
referenced by a port number. This is mainly useful for debugging purposes. Reference should
be made to the appropriate datasheet for the network card for details on the register addresses
and fields that can be accessed.
This section details the available filter functions that are available.
5.8.1 ethertype_filter
Add or delete a L2 Ethertype filter, which identify packets by their L2 Ethertype mainly assign
them to a receive queue.
ethertype_filter (port_id) (add|del) (mac_addr|mac_ignr) (mac_address) ethertype
(ether_type) (drop|fwd) queue (queue_id)
The available information parameters are:
• port_id: the port which the Ethertype filter assigned on.
• mac_addr: compare destination mac address.
• mac_ignr: ignore destination mac address match.
• mac_address: destination mac address to match.
• ether_type: the EtherType value want to match, for example 0x0806 for ARP packet.
0x0800 (IPv4) and 0x86DD (IPv6) are invalid.
• queue_id : The receive queue associated with this EtherType filter. It is meaningless
when deleting or dropping.
Example, to add/remove an ethertype filter rule:
testpmd> ethertype_filter 0 add mac_ignr ethertype 0x0806 fwd queue 3
testpmd> ethertype_filter 0 del mac_ignr ethertype 0x0806 fwd queue 3
5.8.2 2tuple_filter
Add or delete a 2-tuple filter, which identify packets by specific protocol and destination
TCP/UDP port and forwards packets into one of the receive queues.
2tuple_filter (port_id) (add|del) dst_port (dst_port_value) protocol (protocol_value) mask
(mask_value) tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id)
The available information parameters are:
• port_id: the port which the 2-tuple filter assigned on.
• dst_port_value: destination port in L4.
• protocol_value: IP L4 protocol.
• mask_value: participates in the match or not by bit for field above, 1b means participate.
• tcp_flags_value: TCP control bits. The non-zero value is invalid, when the pro_value is
not set to 0x06 (TCP).
• prio_value: priority of this filter.
• queue_id: The receive queue associated with this 2-tuple filter.
Example, to add/remove an 2tuple filter rule:
testpmd> 2tuple_filter 0 add dst_port 32 protocol 0x06 mask 0x03 tcp_flags 0x02 priority 3 que
testpmd> 2tuple_filter 0 del dst_port 32 protocol 0x06 mask 0x03 tcp_flags 0x02 priority 3 que
5.8.3 5tuple_filter
Add or delete a 5-tuple filter, which consists of a 5-tuple (protocol, source and destination IP
addresses, source and destination TCP/UDP/SCTP port) and routes packets into one of the
receive queues.
5tuple_filter (port_id) (add|del) dst_ip (dst_address) src_ip (src_address) dst_port
(dst_port_value) src_port (src_port_value) protocol (protocol_value) mask (mask_value)
tcp_flags (tcp_flags_value) priority (prio_value) queue (queue_id)
The available information parameters are:
• port_id: the port which the 5-tuple filter assigned on.
• dst_address: destination IP address.
• src_address: source IP address.
5.8.4 syn_filter
By SYN filter, TCP packets whose SYN flag is set can be forwarded to a separate queue.
syn_filter (port_id) (add|del) priority (high|low) queue (queue_id)
The available information parameters are:
• port_id: the port which the SYN filter assigned on.
• high: this SYN filter has higher priority than other filters.
• low: this SYN filter has lower priority than other filters.
• queue_id: The receive queue associated with this SYN filter
Example:
testpmd> syn_filter 0 add priority high queue 3
5.8.5 flex_filter
With flex filter, packets can be recognized by any arbitrary pattern within the first 128 bytes of
the packet and routes packets into one of the receive queues.
flex_filter (port_id) (add|del) len (len_value) bytes (bytes_value) mask (mask_value) priority
(prio_value) queue (queue_id)
The available information parameters are:
• port_id: the port which the Flex filter is assigned on.
• len_value: filter length in bytes, no greater than 128.
• bytes_value: a string in hexadecimal, means the value the flex filter needs to match.
• mask_value: a string in hexadecimal, bit 1 means corresponding byte participates in the
match.
• prio_value: the priority of this filter.
5.8.6 flow_director_filter
The Flow Director works in receive mode to identify specific flows or sets of flows and route
them to specific queues.
Two types of filtering are supported which are referred to as Perfect Match and Signature filters,
the match mode is set by the –pkt-filter-mode command-line parameter:
• Perfect match filters. The hardware checks a match between the masked fields of the
received packets and the programmed filters.
• Signature filters. The hardware checks a match between a hash-based signature of the
masked fields of the received packet.
The Flow Director filters can match the different fields for different type of packet: flow type,
specific input set per flow type and the flexible payload. The Flow Director can also mask out
parts of all of these fields so that filters are only applied to certain fields or parts of the fields.
Different NICs may have different capabilities, command show port fdir (port_id) can be used
to acquire the information.
# Commands to add flow director filters of different flow types.
flow_director_filter (port_id) (add|del|update) flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag) src
(src_ip_address) dst (dst_ip_address) vlan (vlan_value) flexbytes (flexbytes_value) (drop|fwd)
queue (queue_id) fd_id (fd_id_value)
flow_director_filter (port_id) (add|del|update) flow (ipv4-tcp|ipv4-udp|ipv6-tcp|ipv6-udp) src
(src_ip_address) (src_port) dst (dst_ip_address) (dst_port) vlan (vlan_value) flexbytes
(flexbytes_value) (drop|fwd) queue (queue_id) fd_id (fd_id_value)
flow_director_filter (port_id) (add|del|update) flow (ipv4-sctp|ipv6-sctp) src (src_ip_address)
(src_port) dst (dst_ip_address) (dst_port) tag (verification_tag) vlan (vlan_value) flexbytes
(flexbytes_value) (drop|fwd) queue (queue_id) fd_id (fd_id_value)
For example, to add an ipv4-udp flow type filter:
testpmd> flow_director_filter 0 add flow ipv4-udp src 2.2.2.3 32 dst 2.2.2.5 33 vlan 0x1 flexb
5.8.7 flush_flow_director
flush_flow_director (port_id)
Example, to flush all flow director filter on port 0:
testpmd> flush_flow_director 0
5.8.8 flow_director_mask
5.8.9 flow_director_flex_mask
set masks of flow director’s flexible payload based on certain flow type:
flow_director_flex_mask (port_id) flow (none|ipv4-other|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|
ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|all) (mask)
Example, to set flow director’s flex mask for all flow type on port 0:
testpmd> flow_director_flex_mask 0 flow all (0xff,0xff,0,0,0,0,0,0,0,0,0,0,0,0,0,0)
5.8.10 flow_director_flex_payload
5.8.11 get_sym_hash_ena_per_port
5.8.12 set_sym_hash_ena_per_port
5.8.13 get_hash_global_config
5.8.14 set_hash_global_config