New upstream version 17.11-rc3
[deb_dpdk.git] / doc / guides / sample_app_ug / vhost.rst
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
33 Vhost Sample Application
34 ========================
35
36 The vhost sample application demonstrates integration of the Data Plane
37 Development Kit (DPDK) with the Linux* KVM hypervisor by implementing the
38 vhost-net offload API. The sample application performs simple packet
39 switching between virtual machines based on Media Access Control (MAC)
40 address or Virtual Local Area Network (VLAN) tag. The splitting of Ethernet
41 traffic from an external switch is performed in hardware by the Virtual
42 Machine Device Queues (VMDQ) and Data Center Bridging (DCB) features of
43 the IntelĀ® 82599 10 Gigabit Ethernet Controller.
44
45 Testing steps
46 -------------
47
48 This section shows the steps how to test a typical PVP case with this
49 vhost-switch sample, whereas packets are received from the physical NIC
50 port first and enqueued to the VM's Rx queue. Through the guest testpmd's
51 default forwarding mode (io forward), those packets will be put into
52 the Tx queue. The vhost-switch example, in turn, gets the packets and
53 puts back to the same physical NIC port.
54
55 Build
56 ~~~~~
57
58 To compile the sample application see :doc:`compiling`.
59
60 The application is located in the ``vhost`` sub-directory.
61
62 .. note::
63    In this example, you need build DPDK both on the host and inside guest.
64
65 Start the vswitch example
66 ~~~~~~~~~~~~~~~~~~~~~~~~~
67
68 .. code-block:: console
69
70         ./vhost-switch -l 0-3 -n 4 --socket-mem 1024  \
71              -- --socket-file /tmp/sock0 --client \
72              ...
73
74 Check the `Parameters`_ section for the explanations on what do those
75 parameters mean.
76
77 .. _vhost_app_run_vm:
78
79 Start the VM
80 ~~~~~~~~~~~~
81
82 .. code-block:: console
83
84     qemu-system-x86_64 -machine accel=kvm -cpu host \
85         -m $mem -object memory-backend-file,id=mem,size=$mem,mem-path=/dev/hugepages,share=on \
86                 -mem-prealloc -numa node,memdev=mem \
87         \
88         -chardev socket,id=char1,path=/tmp/sock0,server \
89         -netdev type=vhost-user,id=hostnet1,chardev=char1  \
90         -device virtio-net-pci,netdev=hostnet1,id=net1,mac=52:54:00:00:00:14 \
91         ...
92
93 .. note::
94     For basic vhost-user support, QEMU 2.2 (or above) is required. For
95     some specific features, a higher version might be need. Such as
96     QEMU 2.7 (or above) for the reconnect feature.
97
98 .. _vhost_app_run_dpdk_inside_guest:
99
100 Run testpmd inside guest
101 ~~~~~~~~~~~~~~~~~~~~~~~~
102
103 Make sure you have DPDK built inside the guest. Also make sure the
104 corresponding virtio-net PCI device is bond to a uio driver, which
105 could be done by:
106
107 .. code-block:: console
108
109    modprobe uio_pci_generic
110    $RTE_SDK/usertools/dpdk-devbind.py -b=uio_pci_generic 0000:00:04.0
111
112 Then start testpmd for packet forwarding testing.
113
114 .. code-block:: console
115
116     ./x86_64-native-gcc/app/testpmd -l 0-1 -- -i
117     > start tx_first
118
119 Inject packets
120 --------------
121
122 While a virtio-net is connected to vhost-switch, a VLAN tag starts with
123 1000 is assigned to it. So make sure configure your packet generator
124 with the right MAC and VLAN tag, you should be able to see following
125 log from the vhost-switch console. It means you get it work::
126
127     VHOST_DATA: (0) mac 52:54:00:00:00:14 and vlan 1000 registered
128
129
130 .. _vhost_app_parameters:
131
132 Parameters
133 ----------
134
135 **--socket-file path**
136 Specifies the vhost-user socket file path.
137
138 **--client**
139 DPDK vhost-user will act as the client mode when such option is given.
140 In the client mode, QEMU will create the socket file. Otherwise, DPDK
141 will create it. Put simply, it's the server to create the socket file.
142
143
144 **--vm2vm mode**
145 The vm2vm parameter sets the mode of packet switching between guests in
146 the host.
147
148 - 0 disables vm2vm, impling that VM's packets will always go to the NIC port.
149 - 1 means a normal mac lookup packet routing.
150 - 2 means hardware mode packet forwarding between guests, it allows packets
151   go to the NIC port, hardware L2 switch will determine which guest the
152   packet should forward to or need send to external, which bases on the
153   packet destination MAC address and VLAN tag.
154
155 **--mergeable 0|1**
156 Set 0/1 to disable/enable the mergeable Rx feature. It's disabled by default.
157
158 **--stats interval**
159 The stats parameter controls the printing of virtio-net device statistics.
160 The parameter specifies an interval (in unit of seconds) to print statistics,
161 with an interval of 0 seconds disabling statistics.
162
163 **--rx-retry 0|1**
164 The rx-retry option enables/disables enqueue retries when the guests Rx queue
165 is full. This feature resolves a packet loss that is observed at high data
166 rates, by allowing it to delay and retry in the receive path. This option is
167 enabled by default.
168
169 **--rx-retry-num num**
170 The rx-retry-num option specifies the number of retries on an Rx burst, it
171 takes effect only when rx retry is enabled.  The default value is 4.
172
173 **--rx-retry-delay msec**
174 The rx-retry-delay option specifies the timeout (in micro seconds) between
175 retries on an RX burst, it takes effect only when rx retry is enabled. The
176 default value is 15.
177
178 **--dequeue-zero-copy**
179 Dequeue zero copy will be enabled when this option is given.
180
181 **--vlan-strip 0|1**
182 VLAN strip option is removed, because different NICs have different behaviors
183 when disabling VLAN strip. Such feature, which heavily depends on hardware,
184 should be removed from this example to reduce confusion. Now, VLAN strip is
185 enabled and cannot be disabled.
186
187 Common Issues
188 -------------
189
190 * QEMU fails to allocate memory on hugetlbfs, with an error like the
191   following::
192
193       file_ram_alloc: can't mmap RAM pages: Cannot allocate memory
194
195   When running QEMU the above error indicates that it has failed to allocate
196   memory for the Virtual Machine on the hugetlbfs. This is typically due to
197   insufficient hugepages being free to support the allocation request. The
198   number of free hugepages can be checked as follows:
199
200   .. code-block:: console
201
202       cat /sys/kernel/mm/hugepages/hugepages-<pagesize>/nr_hugepages
203
204   The command above indicates how many hugepages are free to support QEMU's
205   allocation request.
206
207 * vhost-user will not work with QEMU without the ``-mem-prealloc`` option
208
209   The current implementation works properly only when the guest memory is
210   pre-allocated.
211
212 * vhost-user will not work with a QEMU version without shared memory mapping:
213
214   Make sure ``share=on`` QEMU option is given.
215
216 * Failed to build DPDK in VM
217
218   Make sure "-cpu host" QEMU option is given.