2 Copyright(c) 2016 Intel Corporation. All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
15 * Neither the name of Intel Corporation nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 Live Migration of VM with SR-IOV VF
32 ===================================
37 It is not possible to migrate a Virtual Machine which has an SR-IOV Virtual Function (VF).
39 To get around this problem the bonding PMD is used.
41 The following sections show an example of how to do this.
46 A bonded device is created in the VM.
47 The virtio and VF PMD's are added as slaves to the bonded device.
48 The VF is set as the primary slave of the bonded device.
50 A bridge must be set up on the Host connecting the tap device, which is the
51 backend of the Virtio device and the Physical Function (PF) device.
53 To test the Live Migration two servers with identical operating systems installed are used.
54 KVM and Qemu 2.3 is also required on the servers.
56 In this example, the servers have Niantic and or Fortville NIC's installed.
57 The NIC's on both servers are connected to a switch
58 which is also connected to the traffic generator.
60 The switch is configured to broadcast traffic on all the NIC ports.
61 A :ref:`Sample switch configuration <lm_bond_virtio_sriov_switch_conf>`
62 can be found in this section.
64 The host is running the Kernel PF driver (ixgbe or i40e).
66 The ip address of host_server_1 is 10.237.212.46
68 The ip address of host_server_2 is 10.237.212.131
70 .. _figure_lm_bond_virtio_sriov:
72 .. figure:: img/lm_bond_virtio_sriov.*
77 The sample scripts mentioned in the steps below can be found in the
78 :ref:`Sample host scripts <lm_bond_virtio_sriov_host_scripts>` and
79 :ref:`Sample VM scripts <lm_bond_virtio_sriov_vm_scripts>` sections.
81 On host_server_1: Terminal 1
82 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84 .. code-block:: console
86 cd /root/dpdk/host_scripts
87 ./setup_vf_on_212_46.sh
91 .. code-block:: console
93 ./vm_virtio_vf_i40e_212_46.sh
97 .. code-block:: console
99 ./vm_virtio_vf_one_212_46.sh
101 On host_server_1: Terminal 2
102 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
104 .. code-block:: console
106 cd /root/dpdk/host_scripts
107 ./setup_bridge_on_212_46.sh
108 ./connect_to_qemu_mon_on_host.sh
111 On host_server_1: Terminal 1
112 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
114 **In VM on host_server_1:**
116 .. code-block:: console
118 cd /root/dpdk/vm_scripts
119 ./setup_dpdk_in_vm.sh
120 ./run_testpmd_bonding_in_vm.sh
122 testpmd> show port info all
124 The ``mac_addr`` command only works with kernel PF for Niantic
126 .. code-block:: console
128 testpmd> mac_addr add port 1 vf 0 AA:BB:CC:DD:EE:FF
130 The syntax of the ``testpmd`` command is:
132 Create bonded device (mode) (socket).
134 Mode 1 is active backup.
136 Virtio is port 0 (P0).
140 Bonding is port 2 (P2).
142 .. code-block:: console
144 testpmd> create bonded device 1 0
145 Created new bonded device net_bond_testpmd_0 on (port 2).
146 testpmd> add bonding slave 0 2
147 testpmd> add bonding slave 1 2
148 testpmd> show bonding config 2
150 The syntax of the ``testpmd`` command is:
152 set bonding primary (slave id) (port id)
154 Set primary to P1 before starting bonding port.
156 .. code-block:: console
158 testpmd> set bonding primary 1 2
159 testpmd> show bonding config 2
160 testpmd> port start 2
161 Port 2: 02:09:C0:68:99:A5
162 Checking link statuses...
163 Port 0 Link Up - speed 10000 Mbps - full-duplex
164 Port 1 Link Up - speed 10000 Mbps - full-duplex
165 Port 2 Link Up - speed 10000 Mbps - full-duplex
167 testpmd> show bonding config 2
169 Primary is now P1. There are 2 active slaves.
171 Use P2 only for forwarding.
173 .. code-block:: console
175 testpmd> set portlist 2
176 testpmd> show config fwd
179 testpmd> show bonding config 2
181 Primary is now P1. There are 2 active slaves.
183 .. code-block:: console
185 testpmd> show port stats all
187 VF traffic is seen at P1 and P2.
189 .. code-block:: console
191 testpmd> clear port stats all
192 testpmd> set bonding primary 0 2
193 testpmd> remove bonding slave 1 2
194 testpmd> show bonding config 2
196 Primary is now P0. There is 1 active slave.
198 .. code-block:: console
200 testpmd> clear port stats all
201 testpmd> show port stats all
203 No VF traffic is seen at P0 and P2, VF MAC address still present.
205 .. code-block:: console
208 testpmd> port close 1
210 Port close should remove VF MAC address, it does not remove perm_addr.
212 The ``mac_addr`` command only works with the kernel PF for Niantic.
214 .. code-block:: console
216 testpmd> mac_addr remove 1 AA:BB:CC:DD:EE:FF
217 testpmd> port detach 1
218 Port '0000:00:04.0' is detached. Now total ports is 2
219 testpmd> show port stats all
221 No VF traffic is seen at P0 and P2.
223 On host_server_1: Terminal 2
224 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
226 .. code-block:: console
228 (qemu) device_del vf1
231 On host_server_1: Terminal 1
232 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
234 **In VM on host_server_1:**
236 .. code-block:: console
238 testpmd> show bonding config 2
240 Primary is now P0. There is 1 active slave.
242 .. code-block:: console
244 testpmd> show port info all
245 testpmd> show port stats all
247 On host_server_2: Terminal 1
248 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
250 .. code-block:: console
252 cd /root/dpdk/host_scripts
253 ./setup_vf_on_212_131.sh
254 ./vm_virtio_one_migrate.sh
256 On host_server_2: Terminal 2
257 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
259 .. code-block:: console
261 ./setup_bridge_on_212_131.sh
262 ./connect_to_qemu_mon_on_host.sh
264 VM status: paused (inmigrate)
267 On host_server_1: Terminal 2
268 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270 Check that the switch is up before migrating.
272 .. code-block:: console
274 (qemu) migrate tcp:10.237.212.131:5555
276 VM status: paused (postmigrate)
280 .. code-block:: console
283 capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off
284 Migration status: completed
285 total time: 11834 milliseconds
286 downtime: 18 milliseconds
287 setup: 3 milliseconds
288 transferred ram: 389137 kbytes
289 throughput: 269.49 mbps
290 remaining ram: 0 kbytes
291 total ram: 1590088 kbytes
292 duplicate: 301620 pages
295 normal bytes: 385732 kbytes
299 For the Fortville NIC.
301 .. code-block:: console
304 capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off
305 Migration status: completed
306 total time: 11619 milliseconds
307 downtime: 5 milliseconds
308 setup: 7 milliseconds
309 transferred ram: 379699 kbytes
310 throughput: 267.82 mbps
311 remaining ram: 0 kbytes
312 total ram: 1590088 kbytes
313 duplicate: 303985 pages
316 normal bytes: 376292 kbytes
320 On host_server_2: Terminal 1
321 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
323 **In VM on host_server_2:**
325 Hit Enter key. This brings the user to the testpmd prompt.
327 .. code-block:: console
331 On host_server_2: Terminal 2
332 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
334 .. code-block:: console
341 .. code-block:: console
343 (qemu) device_add pci-assign,host=06:10.0,id=vf1
345 For the Fortville NIC.
347 .. code-block:: console
349 (qemu) device_add pci-assign,host=03:02.0,id=vf1
351 On host_server_2: Terminal 1
352 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
354 **In VM on host_server_2:**
356 .. code-block:: console
358 testomd> show port info all
359 testpmd> show port stats all
360 testpmd> show bonding config 2
361 testpmd> port attach 0000:00:04.0
366 testpmd> port start 1
368 The ``mac_addr`` command only works with the Kernel PF for Niantic.
370 .. code-block:: console
372 testpmd> mac_addr add port 1 vf 0 AA:BB:CC:DD:EE:FF
373 testpmd> show port stats all.
374 testpmd> show config fwd
375 testpmd> show bonding config 2
376 testpmd> add bonding slave 1 2
377 testpmd> set bonding primary 1 2
378 testpmd> show bonding config 2
379 testpmd> show port stats all
381 VF traffic is seen at P1 (VF) and P2 (Bonded device).
383 .. code-block:: console
385 testpmd> remove bonding slave 0 2
386 testpmd> show bonding config 2
388 testpmd> port close 0
389 testpmd> port detach 0
390 Port '0000:00:03.0' is detached. Now total ports is 2
392 testpmd> show port info all
393 testpmd> show config fwd
394 testpmd> show port stats all
396 VF traffic is seen at P1 (VF) and P2 (Bonded device).
398 .. _lm_bond_virtio_sriov_host_scripts:
403 setup_vf_on_212_46.sh
404 ~~~~~~~~~~~~~~~~~~~~~
405 Set up Virtual Functions on host_server_1
410 # This script is run on the host 10.237.212.46 to setup the VF
413 cat /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
414 echo 1 > /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
415 cat /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
418 # set up Fortville VF
419 cat /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
420 echo 1 > /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
421 cat /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
424 vm_virtio_vf_one_212_46.sh
425 ~~~~~~~~~~~~~~~~~~~~~~~~~~
427 Setup Virtual Machine on host_server_1
434 KVM_PATH="/usr/bin/qemu-system-x86_64"
437 DISK_IMG="/home/username/disk_image/virt1_sml.disk"
439 # Number of guest cpus
445 taskset -c 1-5 $KVM_PATH \
453 -vnc none -nographic \
455 -netdev type=tap,id=net1,script=no,downscript=no,ifname=tap1 \
456 -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB \
457 -device pci-assign,host=09:10.0,id=vf1 \
458 -monitor telnet::3333,server,nowait
460 setup_bridge_on_212_46.sh
461 ~~~~~~~~~~~~~~~~~~~~~~~~~
463 Setup bridge on host_server_1
468 # This script is run on the host 10.237.212.46 to setup the bridge
469 # for the Tap device and the PF device.
470 # This enables traffic to go from the PF to the Tap to the Virtio PMD in the VM.
472 # ens3f0 is the Niantic NIC
473 # ens6f0 is the Fortville NIC
481 brctl addif virbr0 ens3f0
482 brctl addif virbr0 ens6f0
483 brctl addif virbr0 tap1
491 connect_to_qemu_mon_on_host.sh
492 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
497 # This script is run on both hosts when the VM is up,
498 # to connect to the Qemu Monitor.
502 setup_vf_on_212_131.sh
503 ~~~~~~~~~~~~~~~~~~~~~~
505 Set up Virtual Functions on host_server_2
510 # This script is run on the host 10.237.212.131 to setup the VF
513 cat /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
514 echo 1 > /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
515 cat /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
518 # set up Fortville VF
519 cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
520 echo 1 > /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
521 cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
524 vm_virtio_one_migrate.sh
525 ~~~~~~~~~~~~~~~~~~~~~~~~
527 Setup Virtual Machine on host_server_2
532 # Start the VM on host_server_2 with the same parameters except without the VF
533 # parameters, as the VM on host_server_1, in migration-listen mode
534 # (-incoming tcp:0:5555)
537 KVM_PATH="/usr/bin/qemu-system-x86_64"
540 DISK_IMG="/home/username/disk_image/virt1_sml.disk"
542 # Number of guest cpus
548 taskset -c 1-5 $KVM_PATH \
556 -vnc none -nographic \
558 -netdev type=tap,id=net1,script=no,downscript=no,ifname=tap1 \
559 -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB \
560 -incoming tcp:0:5555 \
561 -monitor telnet::3333,server,nowait
563 setup_bridge_on_212_131.sh
564 ~~~~~~~~~~~~~~~~~~~~~~~~~~
566 Setup bridge on host_server_2
571 # This script is run on the host to setup the bridge
572 # for the Tap device and the PF device.
573 # This enables traffic to go from the PF to the Tap to the Virtio PMD in the VM.
575 # ens4f0 is the Niantic NIC
576 # ens5f0 is the Fortville NIC
584 brctl addif virbr0 ens4f0
585 brctl addif virbr0 ens5f0
586 brctl addif virbr0 tap1
594 .. _lm_bond_virtio_sriov_vm_scripts:
602 Set up DPDK in the Virtual Machine
607 # this script matches the vm_virtio_vf_one script
611 cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
612 echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
613 cat /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
616 /root/dpdk/usertools/dpdk-devbind.py --status
618 rmmod virtio-pci ixgbevf
621 insmod /root/dpdk/x86_64-default-linuxapp-gcc/kmod/igb_uio.ko
623 /root/dpdk/usertools/dpdk-devbind.py -b igb_uio 0000:00:03.0
624 /root/dpdk/usertools/dpdk-devbind.py -b igb_uio 0000:00:04.0
626 /root/dpdk/usertools/dpdk-devbind.py --status
628 run_testpmd_bonding_in_vm.sh
629 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
631 Run testpmd in the Virtual Machine.
636 # Run testpmd in the VM
638 # The test system has 8 cpus (0-7), use cpus 2-7 for VM
639 # Use taskset -pc <core number> <thread_id>
641 # use for bonding of virtio and vf tests in VM
643 /root/dpdk/x86_64-default-linuxapp-gcc/app/testpmd \
644 -l 0-3 -n 4 --socket-mem 350 -- --i --port-topology=chained
646 .. _lm_bond_virtio_sriov_switch_conf:
648 Sample switch configuration
649 ---------------------------
651 The Intel switch is used to connect the traffic generator to the
652 NIC's on host_server_1 and host_server_2.
654 In order to run the switch configuration two console windows are required.
656 Log in as root in both windows.
658 TestPointShared, run_switch.sh and load /root/switch_config must be executed
659 in the sequence below.
661 On Switch: Terminal 1
662 ~~~~~~~~~~~~~~~~~~~~~
666 .. code-block:: console
668 /usr/bin/TestPointShared
670 On Switch: Terminal 2
671 ~~~~~~~~~~~~~~~~~~~~~
673 execute run_switch.sh
675 .. code-block:: console
679 On Switch: Terminal 1
680 ~~~~~~~~~~~~~~~~~~~~~
682 load switch configuration
684 .. code-block:: console
686 load /root/switch_config
688 Sample switch configuration script
689 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
691 The ``/root/switch_config`` script:
696 show port 1,5,9,13,17,21,25
697 set port 1,5,9,13,17,21,25 up
698 show port 1,5,9,13,17,21,25
703 add port port-set 1 0
704 add port port-set 5,9,13,17,21,25 1
706 add acl-rule condition 1 1 port-set 1
707 add acl-rule action 1 1 redirect 1
710 add vlan port 1000 1,5,9,13,17,21,25
711 set vlan tagging 1000 1,5,9,13,17,21,25 tag
712 set switch config flood_ucast fwd
713 show port stats all 1,5,9,13,17,21,25