15aa9abcaSCathy Zhang# How to test Vhost-user net with OpenVSwitch/DPDK 25aa9abcaSCathy Zhang 3ac246907SBo ChenThe purpose of this document is to illustrate how to test vhost-user-net 4ac246907SBo Chenin cloud-hypervisor with OVS/DPDK as the backend. This document was 5*33a05c72SRavi kumar Veeramallytested with Open vSwitch v2.17.8, DPDK v21.11.4, and Cloud Hypervisor 6*33a05c72SRavi kumar Veeramallyv37.0 on Ubuntu 22.04.3 (host kernel v5.15.0). 75aa9abcaSCathy Zhang 85aa9abcaSCathy Zhang## Framework 95aa9abcaSCathy Zhang 105aa9abcaSCathy ZhangIt's a simple test to validate the communication between two virtual machine, connecting them to vhost-user ports respectively provided by `OVS/DPDK`. 115aa9abcaSCathy Zhang``` 125aa9abcaSCathy Zhang +----+----------+ +-------------+-----------+-------------+ +----------+----+ 135aa9abcaSCathy Zhang | | | | | | | | | | 145aa9abcaSCathy Zhang | |vhost-user|----------| vhost-user | ovs | vhost-user |----------|vhost-user| | 155aa9abcaSCathy Zhang | |net device| | port 1 | | port 2 | |net device| | 165aa9abcaSCathy Zhang | | | | | | | | | | 175aa9abcaSCathy Zhang | +----------+ +-------------+-----------+-------------+ +----------+ | 185aa9abcaSCathy Zhang | | | | | | 195aa9abcaSCathy Zhang |vm1 | | dpdk | | vm2 | 205aa9abcaSCathy Zhang | | | | | | 215aa9abcaSCathy Zhang +--+---------------------------------------------------------------------------------------------+--+ 225aa9abcaSCathy Zhang | | hugepages | | 235aa9abcaSCathy Zhang | +---------------------------------------------------------------------------------------------+ | 245aa9abcaSCathy Zhang | | 255aa9abcaSCathy Zhang | host | 265aa9abcaSCathy Zhang | | 275aa9abcaSCathy Zhang +---------------------------------------------------------------------------------------------------+ 285aa9abcaSCathy Zhang``` 295aa9abcaSCathy Zhang## Prerequisites 305aa9abcaSCathy Zhang 315aa9abcaSCathy ZhangPrior to running the test, the following steps need to be performed. 325aa9abcaSCathy Zhang- Enable hugepages 335aa9abcaSCathy Zhang- Install DPDK 345aa9abcaSCathy Zhang- Install OVS 355aa9abcaSCathy Zhang 36ac246907SBo ChenHere is a good reference for setting up OVS with DPDK from scratch: 37ac246907SBo Chenhttps://docs.openvswitch.org/en/latest/intro/install/dpdk/. 385aa9abcaSCathy Zhang 39ac246907SBo ChenOn Ubuntu systems (18.04 or newer), the OpenVswitch-DPDK package can be 40ac246907SBo Cheneasily installed with: 41ac246907SBo Chen```bash 42ac246907SBo Chensudo apt-get update 43ac246907SBo Chensudo apt-get install openvswitch-switch-dpdk 44ac246907SBo Chensudo update-alternatives --set ovs-vswitchd /usr/lib/openvswitch-switch-dpdk/ovs-vswitchd-dpdk 45ac246907SBo Chen``` 465aa9abcaSCathy Zhang## Test 47ac246907SBo ChenThe test runs with multiple queue (MQ) support enabled, using 2 pairs of 48ac246907SBo ChenTX/RX queues defined for both OVS and the virtual machine. Here are the 49ac246907SBo Chendetailed instructions. 505aa9abcaSCathy Zhang 515aa9abcaSCathy Zhang_Setup OVS_ 525aa9abcaSCathy Zhang 53ac246907SBo ChenHere is an example how to configure a basic OpenVswitch using DPDK: 545aa9abcaSCathy Zhang```bash 55ac246907SBo Chen# load the ovs kernel module 565aa9abcaSCathy Zhangmodprobe openvswitch 57ac246907SBo Chensudo service openvswitch-switch start 58ac246907SBo Chenovs-vsctl init 59ac246907SBo Chenovs-vsctl set Open_vSwitch . other_config:dpdk-init=true 60ac246907SBo Chen# run on core 0-3 only 61ac246907SBo Chenovs-vsctl set Open_vSwitch . other_config:dpdk-lcore-mask=0xf 62ac246907SBo Chen# allocate 2G huge pages (to NUMA 0 only) 63ac246907SBo Chenovs-vsctl set Open_vSwitch . other_config:dpdk-socket-mem=1024 64ac246907SBo Chen# run PMD (Pull Mode Driver) threads on core 0-3 only 65ac246907SBo Chenovs-vsctl set Open_vSwitch . other_config:pmd-cpu-mask=0xf 66ac246907SBo Chensudo service openvswitch-switch restart 67ac246907SBo Chen# double check the configurations 68ac246907SBo Chenovs-vsctl list Open_vSwitch 69ac246907SBo Chen``` 70ac246907SBo Chen 71ac246907SBo ChenHere is an example how to create a bridge and add two DPDK ports to it 72ac246907SBo Chen(for later use via Cloud Hypervisor): 73ac246907SBo Chen```bash 74ac246907SBo Chen# create a bridge 755aa9abcaSCathy Zhangovs-vsctl add-br ovsbr0 -- set bridge ovsbr0 datapath_type=netdev 76ac246907SBo Chen# create two DPDK ports and add them to the bridge 77*33a05c72SRavi kumar Veeramallyovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost-user1 78*33a05c72SRavi kumar Veeramallyovs-vsctl add-port ovsbr0 vhost-user2 -- set Interface vhost-user2 type=dpdkvhostuserclient options:vhost-server-path=/tmp/vhost-user2 79ac246907SBo Chen# set the number of rx queues 805aa9abcaSCathy Zhangovs-vsctl set Interface vhost-user1 options:n_rxq=2 815aa9abcaSCathy Zhangovs-vsctl set Interface vhost-user2 options:n_rxq=2 825aa9abcaSCathy Zhang``` 835aa9abcaSCathy Zhang 845aa9abcaSCathy Zhang_Launch the VMs_ 855aa9abcaSCathy Zhang 865aa9abcaSCathy ZhangVMs run in client mode. They connect to the socket created by the `dpdkvhostuser` backend. 875aa9abcaSCathy Zhang```bash 885aa9abcaSCathy Zhang# From one terminal. We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host. 895aa9abcaSCathy Zhang./cloud-hypervisor \ 905aa9abcaSCathy Zhang --cpus boot=2 \ 9117ad86afSAlyssa Ross --memory size=512M,hugepages=on,shared=true \ 925aa9abcaSCathy Zhang --kernel vmlinux \ 93a3342bdbSSebastien Boeuf --cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \ 94a3342bdbSSebastien Boeuf --disk path=focal-server-cloudimg-amd64.raw \ 95*33a05c72SRavi kumar Veeramally --net mac=52:54:00:02:d9:01,vhost_user=true,socket=/tmp/vhost-user1,num_queues=4,vhost_mode=server 965aa9abcaSCathy Zhang 975aa9abcaSCathy Zhang# From another terminal. We need to give the cloud-hypervisor binary the NET_ADMIN capabilities for it to set TAP interfaces up on the host. 985aa9abcaSCathy Zhang./cloud-hypervisor \ 995aa9abcaSCathy Zhang --cpus boot=2 \ 10017ad86afSAlyssa Ross --memory size=512M,hugepages=on,shared=true \ 1015aa9abcaSCathy Zhang --kernel vmlinux \ 102a3342bdbSSebastien Boeuf --cmdline "console=ttyS0 console=hvc0 root=/dev/vda1 rw" \ 103a3342bdbSSebastien Boeuf --disk path=focal-server-cloudimg-amd64.raw \ 104*33a05c72SRavi kumar Veeramally --net mac=52:54:20:11:C5:02,vhost_user=true,socket=/tmp/vhost-user2,num_queues=4,vhost_mode=server 1055aa9abcaSCathy Zhang``` 1065aa9abcaSCathy Zhang 1075aa9abcaSCathy Zhang_Setup VM1_ 1085aa9abcaSCathy Zhang```bash 1095aa9abcaSCathy Zhang# From inside the guest 110*33a05c72SRavi kumar Veeramallysudo ip addr add 172.100.0.1/24 dev ens3 111*33a05c72SRavi kumar Veeramallysudo ip link set up dev ens3 1125aa9abcaSCathy Zhang``` 1135aa9abcaSCathy Zhang 1145aa9abcaSCathy Zhang_Setup VM2_ 1155aa9abcaSCathy Zhang```bash 1165aa9abcaSCathy Zhang# From inside the guest 117*33a05c72SRavi kumar Veeramallysudo ip addr add 172.100.0.2/24 dev ens3 118*33a05c72SRavi kumar Veeramallysudo ip link set up dev ens3 1195aa9abcaSCathy Zhang``` 1205aa9abcaSCathy Zhang 1215aa9abcaSCathy Zhang_Ping VM1 from VM2_ 1225aa9abcaSCathy Zhang```bash 1235aa9abcaSCathy Zhang# From inside the guest 1245aa9abcaSCathy Zhangsudo ping 172.100.0.1 1255aa9abcaSCathy Zhang``` 1265aa9abcaSCathy Zhang 1275aa9abcaSCathy Zhang_Ping VM2 from VM1_ 1285aa9abcaSCathy Zhang```bash 1295aa9abcaSCathy Zhang# From inside the guest 1305aa9abcaSCathy Zhangsudo ping 172.100.0.2 1315aa9abcaSCathy Zhang``` 1325aa9abcaSCathy Zhang 1335aa9abcaSCathy Zhang__Result:__ At this point, VM1 and VM2 can ping each other successfully. We can now run `iperf3` test. 1345aa9abcaSCathy Zhang 1355aa9abcaSCathy Zhang_Run VM1 as server_ 1365aa9abcaSCathy Zhang```bash 1375aa9abcaSCathy Zhang# From inside the guest 1385aa9abcaSCathy Zhangiperf3 -s -p 4444 1395aa9abcaSCathy Zhang``` 1405aa9abcaSCathy Zhang 1415aa9abcaSCathy Zhang_Run VM2 as client_ 1425aa9abcaSCathy Zhang```bash 1435aa9abcaSCathy Zhang# From inside the guest 1445aa9abcaSCathy Zhangiperf3 -c 172.100.0.1 -t 30 -p 4444 & 1455aa9abcaSCathy Zhang``` 146