1 .. SPDX-License-Identifier: BSD-3-Clause
2 Copyright(c) 2010-2016 Intel Corporation.
4 Vhost Sample Application
5 ========================
7 The vhost sample application demonstrates integration of the Data Plane
8 Development Kit (DPDK) with the Linux* KVM hypervisor by implementing the
9 vhost-net offload API. The sample application performs simple packet
10 switching between virtual machines based on Media Access Control (MAC)
11 address or Virtual Local Area Network (VLAN) tag. The splitting of Ethernet
12 traffic from an external switch is performed in hardware by the Virtual
13 Machine Device Queues (VMDQ) and Data Center Bridging (DCB) features of
14 the IntelĀ® 82599 10 Gigabit Ethernet Controller.
19 This section shows the steps how to test a typical PVP case with this
20 vhost-switch sample, whereas packets are received from the physical NIC
21 port first and enqueued to the VM's Rx queue. Through the guest testpmd's
22 default forwarding mode (io forward), those packets will be put into
23 the Tx queue. The vhost-switch example, in turn, gets the packets and
24 puts back to the same physical NIC port.
29 To compile the sample application see :doc:`compiling`.
31 The application is located in the ``vhost`` sub-directory.
34 In this example, you need build DPDK both on the host and inside guest.
36 Start the vswitch example
37 ~~~~~~~~~~~~~~~~~~~~~~~~~
39 .. code-block:: console
41 ./vhost-switch -l 0-3 -n 4 --socket-mem 1024 \
42 -- --socket-file /tmp/sock0 --client \
45 Check the `Parameters`_ section for the explanations on what do those
53 .. code-block:: console
55 qemu-system-x86_64 -machine accel=kvm -cpu host \
56 -m $mem -object memory-backend-file,id=mem,size=$mem,mem-path=/dev/hugepages,share=on \
57 -mem-prealloc -numa node,memdev=mem \
59 -chardev socket,id=char1,path=/tmp/sock0,server \
60 -netdev type=vhost-user,id=hostnet1,chardev=char1 \
61 -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:00:00:14 \
65 For basic vhost-user support, QEMU 2.2 (or above) is required. For
66 some specific features, a higher version might be need. Such as
67 QEMU 2.7 (or above) for the reconnect feature.
69 .. _vhost_app_run_dpdk_inside_guest:
71 Run testpmd inside guest
72 ~~~~~~~~~~~~~~~~~~~~~~~~
74 Make sure you have DPDK built inside the guest. Also make sure the
75 corresponding virtio-net PCI device is bond to a uio driver, which
78 .. code-block:: console
80 modprobe uio_pci_generic
81 $RTE_SDK/usertools/dpdk-devbind.py -b=uio_pci_generic 0000:00:04.0
83 Then start testpmd for packet forwarding testing.
85 .. code-block:: console
87 ./x86_64-native-gcc/app/testpmd -l 0-1 -- -i
93 While a virtio-net is connected to vhost-switch, a VLAN tag starts with
94 1000 is assigned to it. So make sure configure your packet generator
95 with the right MAC and VLAN tag, you should be able to see following
96 log from the vhost-switch console. It means you get it work::
98 VHOST_DATA: (0) mac 52:54:00:00:00:14 and vlan 1000 registered
101 .. _vhost_app_parameters:
106 **--socket-file path**
107 Specifies the vhost-user socket file path.
110 DPDK vhost-user will act as the client mode when such option is given.
111 In the client mode, QEMU will create the socket file. Otherwise, DPDK
112 will create it. Put simply, it's the server to create the socket file.
116 The vm2vm parameter sets the mode of packet switching between guests in
119 - 0 disables vm2vm, impling that VM's packets will always go to the NIC port.
120 - 1 means a normal mac lookup packet routing.
121 - 2 means hardware mode packet forwarding between guests, it allows packets
122 go to the NIC port, hardware L2 switch will determine which guest the
123 packet should forward to or need send to external, which bases on the
124 packet destination MAC address and VLAN tag.
127 Set 0/1 to disable/enable the mergeable Rx feature. It's disabled by default.
130 The stats parameter controls the printing of virtio-net device statistics.
131 The parameter specifies an interval (in unit of seconds) to print statistics,
132 with an interval of 0 seconds disabling statistics.
135 The rx-retry option enables/disables enqueue retries when the guests Rx queue
136 is full. This feature resolves a packet loss that is observed at high data
137 rates, by allowing it to delay and retry in the receive path. This option is
140 **--rx-retry-num num**
141 The rx-retry-num option specifies the number of retries on an Rx burst, it
142 takes effect only when rx retry is enabled. The default value is 4.
144 **--rx-retry-delay msec**
145 The rx-retry-delay option specifies the timeout (in micro seconds) between
146 retries on an RX burst, it takes effect only when rx retry is enabled. The
149 **--dequeue-zero-copy**
150 Dequeue zero copy will be enabled when this option is given. it is worth to
151 note that if NIC is binded to driver with iommu enabled, dequeue zero copy
152 cannot work at VM2NIC mode (vm2vm=0) due to currently we don't setup iommu
153 dma mapping for guest memory.
156 VLAN strip option is removed, because different NICs have different behaviors
157 when disabling VLAN strip. Such feature, which heavily depends on hardware,
158 should be removed from this example to reduce confusion. Now, VLAN strip is
159 enabled and cannot be disabled.
164 * QEMU fails to allocate memory on hugetlbfs, with an error like the
167 file_ram_alloc: can't mmap RAM pages: Cannot allocate memory
169 When running QEMU the above error indicates that it has failed to allocate
170 memory for the Virtual Machine on the hugetlbfs. This is typically due to
171 insufficient hugepages being free to support the allocation request. The
172 number of free hugepages can be checked as follows:
174 .. code-block:: console
176 cat /sys/kernel/mm/hugepages/hugepages-<pagesize>/nr_hugepages
178 The command above indicates how many hugepages are free to support QEMU's
181 * Failed to build DPDK in VM
183 Make sure "-cpu host" QEMU option is given.
185 * Device start fails if NIC's max queues > the default number of 128
187 mbuf pool size is dependent on the MAX_QUEUES configuration, if NIC's
188 max queue number is larger than 128, device start will fail due to
191 Change the default number to make it work as below, just set the number
192 according to the NIC's property. ::
194 make EXTRA_CFLAGS="-DMAX_QUEUES=320"