1 2.. BSD LICENSE 3 Copyright(c) 2010-2016 Intel Corporation. All rights reserved. 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, are permitted provided that the following conditions 8 are met: 9 10 * Redistributions of source code must retain the above copyright 11 notice, this list of conditions and the following disclaimer. 12 * Redistributions in binary form must reproduce the above copyright 13 notice, this list of conditions and the following disclaimer in 14 the documentation and/or other materials provided with the 15 distribution. 16 * Neither the name of Intel Corporation nor the names of its 17 contributors may be used to endorse or promote products derived 18 from this software without specific prior written permission. 19 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 32 33Vhost Sample Application 34======================== 35 36The vhost sample application demonstrates integration of the Data Plane 37Development Kit (DPDK) with the Linux* KVM hypervisor by implementing the 38vhost-net offload API. The sample application performs simple packet 39switching between virtual machines based on Media Access Control (MAC) 40address or Virtual Local Area Network (VLAN) tag. The splitting of Ethernet 41traffic from an external switch is performed in hardware by the Virtual 42Machine Device Queues (VMDQ) and Data Center Bridging (DCB) features of 43the Intel® 82599 10 Gigabit Ethernet Controller. 44 45Testing steps 46------------- 47 48This section shows the steps how to test a typical PVP case with this 49vhost-switch sample, whereas packets are received from the physical NIC 50port first and enqueued to the VM's Rx queue. Through the guest testpmd's 51default forwarding mode (io forward), those packets will be put into 52the Tx queue. The vhost-switch example, in turn, gets the packets and 53puts back to the same physical NIC port. 54 55Build 56~~~~~ 57 58Follow the *Getting Started Guide for Linux* on generic info about 59environment setup and building DPDK from source. 60 61In this example, you need build DPDK both on the host and inside guest. 62Also, you need build this example. 63 64.. code-block:: console 65 66 export RTE_SDK=/path/to/dpdk_source 67 export RTE_TARGET=x86_64-native-linuxapp-gcc 68 69 cd ${RTE_SDK}/examples/vhost 70 make 71 72 73Start the vswitch example 74~~~~~~~~~~~~~~~~~~~~~~~~~ 75 76.. code-block:: console 77 78 ./vhost-switch -l 0-3 -n 4 --socket-mem 1024 \ 79 -- --socket-file /tmp/sock0 --client \ 80 ... 81 82Check the `Parameters`_ section for the explanations on what do those 83parameters mean. 84 85.. _vhost_app_run_vm: 86 87Start the VM 88~~~~~~~~~~~~ 89 90.. code-block:: console 91 92 qemu-system-x86_64 -machine accel=kvm -cpu host \ 93 -m $mem -object memory-backend-file,id=mem,size=$mem,mem-path=/dev/hugepages,share=on \ 94 -mem-prealloc -numa node,memdev=mem \ 95 \ 96 -chardev socket,id=char1,path=/tmp/sock0,server \ 97 -netdev type=vhost-user,id=hostnet1,chardev=char1 \ 98 -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:00:00:14 \ 99 ... 100 101.. note:: 102 For basic vhost-user support, QEMU 2.2 (or above) is required. For 103 some specific features, a higher version might be need. Such as 104 QEMU 2.7 (or above) for the reconnect feature. 105 106.. _vhost_app_run_dpdk_inside_guest: 107 108Run testpmd inside guest 109~~~~~~~~~~~~~~~~~~~~~~~~ 110 111Make sure you have DPDK built inside the guest. Also make sure the 112corresponding virtio-net PCI device is bond to a uio driver, which 113could be done by: 114 115.. code-block:: console 116 117 modprobe uio_pci_generic 118 $RTE_SDK/usertools/dpdk-devbind.py -b=uio_pci_generic 0000:00:04.0 119 120Then start testpmd for packet forwarding testing. 121 122.. code-block:: console 123 124 ./x86_64-native-gcc/app/testpmd -l 0-1 -- -i 125 > start tx_first 126 127Inject packets 128-------------- 129 130While a virtio-net is connected to vhost-switch, a VLAN tag starts with 1311000 is assigned to it. So make sure configure your packet generator 132with the right MAC and VLAN tag, you should be able to see following 133log from the vhost-switch console. It means you get it work:: 134 135 VHOST_DATA: (0) mac 52:54:00:00:00:14 and vlan 1000 registered 136 137 138.. _vhost_app_parameters: 139 140Parameters 141---------- 142 143**--socket-file path** 144Specifies the vhost-user socket file path. 145 146**--client** 147DPDK vhost-user will act as the client mode when such option is given. 148In the client mode, QEMU will create the socket file. Otherwise, DPDK 149will create it. Put simply, it's the server to create the socket file. 150 151 152**--vm2vm mode** 153The vm2vm parameter sets the mode of packet switching between guests in 154the host. 155 156- 0 disables vm2vm, impling that VM's packets will always go to the NIC port. 157- 1 means a normal mac lookup packet routing. 158- 2 means hardware mode packet forwarding between guests, it allows packets 159 go to the NIC port, hardware L2 switch will determine which guest the 160 packet should forward to or need send to external, which bases on the 161 packet destination MAC address and VLAN tag. 162 163**--mergeable 0|1** 164Set 0/1 to disable/enable the mergeable Rx feature. It's disabled by default. 165 166**--stats interval** 167The stats parameter controls the printing of virtio-net device statistics. 168The parameter specifies an interval (in unit of seconds) to print statistics, 169with an interval of 0 seconds disabling statistics. 170 171**--rx-retry 0|1** 172The rx-retry option enables/disables enqueue retries when the guests Rx queue 173is full. This feature resolves a packet loss that is observed at high data 174rates, by allowing it to delay and retry in the receive path. This option is 175enabled by default. 176 177**--rx-retry-num num** 178The rx-retry-num option specifies the number of retries on an Rx burst, it 179takes effect only when rx retry is enabled. The default value is 4. 180 181**--rx-retry-delay msec** 182The rx-retry-delay option specifies the timeout (in micro seconds) between 183retries on an RX burst, it takes effect only when rx retry is enabled. The 184default value is 15. 185 186**--dequeue-zero-copy** 187Dequeue zero copy will be enabled when this option is given. 188 189**--vlan-strip 0|1** 190VLAN strip option is removed, because different NICs have different behaviors 191when disabling VLAN strip. Such feature, which heavily depends on hardware, 192should be removed from this example to reduce confusion. Now, VLAN strip is 193enabled and cannot be disabled. 194 195Common Issues 196------------- 197 198* QEMU fails to allocate memory on hugetlbfs, with an error like the 199 following:: 200 201 file_ram_alloc: can't mmap RAM pages: Cannot allocate memory 202 203 When running QEMU the above error indicates that it has failed to allocate 204 memory for the Virtual Machine on the hugetlbfs. This is typically due to 205 insufficient hugepages being free to support the allocation request. The 206 number of free hugepages can be checked as follows: 207 208 .. code-block:: console 209 210 cat /sys/kernel/mm/hugepages/hugepages-<pagesize>/nr_hugepages 211 212 The command above indicates how many hugepages are free to support QEMU's 213 allocation request. 214 215* vhost-user will not work with QEMU without the ``-mem-prealloc`` option 216 217 The current implementation works properly only when the guest memory is 218 pre-allocated. 219 220* vhost-user will not work with a QEMU version without shared memory mapping: 221 222 Make sure ``share=on`` QEMU option is given. 223 224* Failed to build DPDK in VM 225 226 Make sure "-cpu host" QEMU option is given. 227