Sa1ka's Shelter

DPDK Pktgen和Testpmd验证试验

Word count: 338Reading time: 2 min
2019/08/27 Share

Ref:
Version: DPDK 19.08 / Pktgen 3.7.2

1
2
3
4
5
6
7
+--------+---------------+               +-------------------+---------------+
| | socket file 1 | <-------> | vhost-user port 1 | |
| +---------------+ +-------------------+ Docker |
| host | pktgen | | testpmd | container |
| +---------------+ +-------------------+ |
| | socket file 0 | <-------> | vhost-user port 0 | |
+--------+---------------+ +-------------------+---------------+

Compile DPDK and Pktgen

DPDK

1
2
3
4
5
6
export RTE_SDK=~/dpdk/dpdk-19.08
export RTE_TARGET=x86_64-native-linuxapp-gcc
sed -ri 's,(CONFIG_RTE_LIBRTE_VHOST).*,\1y' config/common_base
make config T=$RTE_TARGET
sed -ri 's,(PMD_PCAP).*,\1y' build/.config
make

Pktgen

1
2
3
export RTE_SDK=~/dpdk/dpdk-19.08
export RTE_TARGET=build
make

Build a Docker image

Create a dockerfile in the directory contains DPDK_SDK.

1
2
3
4
5
6
7
FROM ubuntu:16.04
WORKDIR /root/dpdk
COPY dpdk-19.08 /root/dpdk/.
ENV PATH "$PATH:/root/dpdk/$RTE_TARGET/app/"
RUN sed -i 's/archive.ubuntu.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && \
apt update && apt install -y libnuma-dev libpcap-dev
ENTRYPOINT ["/bin/bash"]

Allocate HugePage

Modify /etc/default/grub.

1
GRUB_CMDLINE_LINUX_DEFAULT="default_hugepagesz=1GB hugepagesz=1G hugepages=8"

Update the grub file and reboot to take effect.

1
2
3
4
sudo update-grub
reboot
mkdir -p /dev/hugepages
sudo mount -t hugetlbfs none /dev/hugepages

Run the Testpmd container

1
2
3
4
sudo docker run -ti --rm --name=test \
-v /dev/hugepages:/dev/hugepages \
-v /tmp/virtio/:/tmp/virtio/ \
--privileged dpdk

Type the commands below inside the container shell

1
2
3
4
testpmd -l 0-1 -n 1 --socket-mem 1024,1024 \
--vdev 'eth_vhost0,iface=/tmp/virtio/sock0' --vdev 'eth_vhost1,iface=/tmp/virtio/sock1' \
--file-prefix=test --no-pci \
-- -i --forward-mode=io --auto-start

Some usefule runtime functions

1
show port stats all

Generate the packets

1
sudo pktgen -l 2,3,4 -n 2 --vdev=virtio_user0,path=/tmp/virtio/sock0 --vdev=virtio_user1,path=/tmp/virtio/sock1 -- -P -m "3.0,4.1"

Some useful runtime functions

1
2
3
set all rate 10 # set the sending rate at 10%
set 0 count 100 # request the channel 0 to send 100 packets in total
str # start
CATALOG
  1. 1. Compile DPDK and Pktgen
  2. 2. Build a Docker image
  3. 3. Allocate HugePage
  4. 4. Run the Testpmd container
  5. 5. Generate the packets