aboutsummaryrefslogtreecommitdiffstats
path: root/doc/guides/howto/lm_bond_virtio_sriov.rst
blob: a47d6dbf8dec4b74ff566f2f1fa6de2fd76328c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
..  SPDX-License-Identifier: BSD-3-Clause
    Copyright(c) 2016 Intel Corporation.

Live Migration of VM with SR-IOV VF
===================================

Overview
--------

It is not possible to migrate a Virtual Machine which has an SR-IOV Virtual Function (VF).

To get around this problem the bonding PMD is used.

The following sections show an example of how to do this.

Test Setup
----------

A bonded device is created in the VM.
The virtio and VF PMD's are added as slaves to the bonded device.
The VF is set as the primary slave of the bonded device.

A bridge must be set up on the Host connecting the tap device, which is the
backend of the Virtio device and the Physical Function (PF) device.

To test the Live Migration two servers with identical operating systems installed are used.
KVM and Qemu 2.3 is also required on the servers.

In this example, the servers have Niantic and or Fortville NIC's installed.
The NIC's on both servers are connected to a switch
which is also connected to the traffic generator.

The switch is configured to broadcast traffic on all the NIC ports.
A :ref:`Sample switch configuration <lm_bond_virtio_sriov_switch_conf>`
can be found in this section.

The host is running the Kernel PF driver (ixgbe or i40e).

The ip address of host_server_1 is 10.237.212.46

The ip address of host_server_2 is 10.237.212.131

.. _figure_lm_bond_virtio_sriov:

.. figure:: img/lm_bond_virtio_sriov.*

Live Migration steps
--------------------

The sample scripts mentioned in the steps below can be found in the
:ref:`Sample host scripts <lm_bond_virtio_sriov_host_scripts>` and
:ref:`Sample VM scripts <lm_bond_virtio_sriov_vm_scripts>` sections.

On host_server_1: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   cd /root/dpdk/host_scripts
   ./setup_vf_on_212_46.sh

For Fortville NIC

.. code-block:: console

   ./vm_virtio_vf_i40e_212_46.sh

For Niantic NIC

.. code-block:: console

   ./vm_virtio_vf_one_212_46.sh

On host_server_1: Terminal 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   cd /root/dpdk/host_scripts
   ./setup_bridge_on_212_46.sh
   ./connect_to_qemu_mon_on_host.sh
   (qemu)

On host_server_1: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**In VM on host_server_1:**

.. code-block:: console

   cd /root/dpdk/vm_scripts
   ./setup_dpdk_in_vm.sh
   ./run_testpmd_bonding_in_vm.sh

   testpmd> show port info all

The ``mac_addr`` command only works with kernel PF for Niantic

.. code-block:: console

   testpmd> mac_addr add port 1 vf 0 AA:BB:CC:DD:EE:FF

The syntax of the ``testpmd`` command is:

Create bonded device (mode) (socket).

Mode 1 is active backup.

Virtio is port 0 (P0).

VF is port 1 (P1).

Bonding is port 2 (P2).

.. code-block:: console

   testpmd> create bonded device 1 0
   Created new bonded device net_bond_testpmd_0 on (port 2).
   testpmd> add bonding slave 0 2
   testpmd> add bonding slave 1 2
   testpmd> show bonding config 2

The syntax of the ``testpmd`` command is:

set bonding primary (slave id) (port id)

Set primary to P1 before starting bonding port.

.. code-block:: console

   testpmd> set bonding primary 1 2
   testpmd> show bonding config 2
   testpmd> port start 2
   Port 2: 02:09:C0:68:99:A5
   Checking link statuses...
   Port 0 Link Up - speed 10000 Mbps - full-duplex
   Port 1 Link Up - speed 10000 Mbps - full-duplex
   Port 2 Link Up - speed 10000 Mbps - full-duplex

   testpmd> show bonding config 2

Primary is now P1. There are 2 active slaves.

Use P2 only for forwarding.

.. code-block:: console

   testpmd> set portlist 2
   testpmd> show config fwd
   testpmd> set fwd mac
   testpmd> start
   testpmd> show bonding config 2

Primary is now P1. There are 2 active slaves.

.. code-block:: console

   testpmd> show port stats all

VF traffic is seen at P1 and P2.

.. code-block:: console

   testpmd> clear port stats all
   testpmd> set bonding primary 0 2
   testpmd> remove bonding slave 1 2
   testpmd> show bonding config 2

Primary is now P0. There is 1 active slave.

.. code-block:: console

   testpmd> clear port stats all
   testpmd> show port stats all

No VF traffic is seen at P0 and P2, VF MAC address still present.

.. code-block:: console

   testpmd> port stop 1
   testpmd> port close 1

Port close should remove VF MAC address, it does not remove perm_addr.

The ``mac_addr`` command only works with the kernel PF for Niantic.

.. code-block:: console

   testpmd> mac_addr remove 1 AA:BB:CC:DD:EE:FF
   testpmd> port detach 1
   Port '0000:00:04.0' is detached. Now total ports is 2
   testpmd> show port stats all

No VF traffic is seen at P0 and P2.

On host_server_1: Terminal 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   (qemu) device_del vf1


On host_server_1: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**In VM on host_server_1:**

.. code-block:: console

   testpmd> show bonding config 2

Primary is now P0. There is 1 active slave.

.. code-block:: console

   testpmd> show port info all
   testpmd> show port stats all

On host_server_2: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   cd /root/dpdk/host_scripts
   ./setup_vf_on_212_131.sh
   ./vm_virtio_one_migrate.sh

On host_server_2: Terminal 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   ./setup_bridge_on_212_131.sh
   ./connect_to_qemu_mon_on_host.sh
   (qemu) info status
   VM status: paused (inmigrate)
   (qemu)

On host_server_1: Terminal 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check that the switch is up before migrating.

.. code-block:: console

   (qemu) migrate tcp:10.237.212.131:5555
   (qemu) info status
   VM status: paused (postmigrate)

For the Niantic NIC.

.. code-block:: console

   (qemu) info migrate
   capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off
   Migration status: completed
   total time: 11834 milliseconds
   downtime: 18 milliseconds
   setup: 3 milliseconds
   transferred ram: 389137 kbytes
   throughput: 269.49 mbps
   remaining ram: 0 kbytes
   total ram: 1590088 kbytes
   duplicate: 301620 pages
   skipped: 0 pages
   normal: 96433 pages
   normal bytes: 385732 kbytes
   dirty sync count: 2
   (qemu) quit

For the Fortville NIC.

.. code-block:: console

   (qemu) info migrate
   capabilities: xbzrle: off rdma-pin-all: off auto-converge: off zero-blocks: off
   Migration status: completed
   total time: 11619 milliseconds
   downtime: 5 milliseconds
   setup: 7 milliseconds
   transferred ram: 379699 kbytes
   throughput: 267.82 mbps
   remaining ram: 0 kbytes
   total ram: 1590088 kbytes
   duplicate: 303985 pages
   skipped: 0 pages
   normal: 94073 pages
   normal bytes: 376292 kbytes
   dirty sync count: 2
   (qemu) quit

On host_server_2: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**In VM on host_server_2:**

   Hit Enter key. This brings the user to the testpmd prompt.

.. code-block:: console

   testpmd>

On host_server_2: Terminal 2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: console

   (qemu) info status
   VM status: running

For the Niantic NIC.

.. code-block:: console

   (qemu) device_add pci-assign,host=06:10.0,id=vf1

For the Fortville NIC.

.. code-block:: console

   (qemu) device_add pci-assign,host=03:02.0,id=vf1

On host_server_2: Terminal 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

**In VM on host_server_2:**

.. code-block:: console

   testomd> show port info all
   testpmd> show port stats all
   testpmd> show bonding config 2
   testpmd> port attach 0000:00:04.0
   Port 1 is attached.
   Now total ports is 3
   Done

   testpmd> port start 1

The ``mac_addr`` command only works with the Kernel PF for Niantic.

.. code-block:: console

   testpmd> mac_addr add port 1 vf 0 AA:BB:CC:DD:EE:FF
   testpmd> show port stats all.
   testpmd> show config fwd
   testpmd> show bonding config 2
   testpmd> add bonding slave 1 2
   testpmd> set bonding primary 1 2
   testpmd> show bonding config 2
   testpmd> show port stats all

VF traffic is seen at P1 (VF) and P2 (Bonded device).

.. code-block:: console

   testpmd> remove bonding slave 0 2
   testpmd> show bonding config 2
   testpmd> port stop 0
   testpmd> port close 0
   testpmd> port detach 0
   Port '0000:00:03.0' is detached. Now total ports is 2

   testpmd> show port info all
   testpmd> show config fwd
   testpmd> show port stats all

VF traffic is seen at P1 (VF) and P2 (Bonded device).

.. _lm_bond_virtio_sriov_host_scripts:

Sample host scripts
-------------------

setup_vf_on_212_46.sh
~~~~~~~~~~~~~~~~~~~~~
Set up Virtual Functions on host_server_1

.. code-block:: sh

   #!/bin/sh
   # This script is run on the host 10.237.212.46 to setup the VF

   # set up Niantic VF
   cat /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
   echo 1 > /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
   cat /sys/bus/pci/devices/0000\:09\:00.0/sriov_numvfs
   rmmod ixgbevf

   # set up Fortville VF
   cat /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
   echo 1 > /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
   cat /sys/bus/pci/devices/0000\:02\:00.0/sriov_numvfs
   rmmod i40evf

vm_virtio_vf_one_212_46.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~

Setup Virtual Machine on host_server_1

.. code-block:: sh

   #!/bin/sh

   # Path to KVM tool
   KVM_PATH="/usr/bin/qemu-system-x86_64"

   # Guest Disk image
   DISK_IMG="/home/username/disk_image/virt1_sml.disk"

   # Number of guest cpus
   VCPUS_NR="4"

   # Memory
   MEM=1536

   taskset -c 1-5 $KVM_PATH \
    -enable-kvm \
    -m $MEM \
    -smp $VCPUS_NR \
    -cpu host \
    -name VM1 \
    -no-reboot \
    -net none \
    -vnc none -nographic \
    -hda $DISK_IMG \
    -netdev type=tap,id=net1,script=no,downscript=no,ifname=tap1 \
    -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB \
    -device pci-assign,host=09:10.0,id=vf1 \
    -monitor telnet::3333,server,nowait

setup_bridge_on_212_46.sh
~~~~~~~~~~~~~~~~~~~~~~~~~

Setup bridge on host_server_1

.. code-block:: sh

   #!/bin/sh
   # This script is run on the host 10.237.212.46 to setup the bridge
   # for the Tap device and the PF device.
   # This enables traffic to go from the PF to the Tap to the Virtio PMD in the VM.

   # ens3f0 is the Niantic NIC
   # ens6f0 is the Fortville NIC

   ifconfig ens3f0 down
   ifconfig tap1 down
   ifconfig ens6f0 down
   ifconfig virbr0 down

   brctl show virbr0
   brctl addif virbr0 ens3f0
   brctl addif virbr0 ens6f0
   brctl addif virbr0 tap1
   brctl show virbr0

   ifconfig ens3f0 up
   ifconfig tap1 up
   ifconfig ens6f0 up
   ifconfig virbr0 up

connect_to_qemu_mon_on_host.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. code-block:: sh

   #!/bin/sh
   # This script is run on both hosts when the VM is up,
   # to connect to the Qemu Monitor.

   telnet 0 3333

setup_vf_on_212_131.sh
~~~~~~~~~~~~~~~~~~~~~~

Set up Virtual Functions on host_server_2

.. code-block:: sh

   #!/bin/sh
   # This script is run on the host 10.237.212.131 to setup the VF

   # set up Niantic VF
   cat /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
   echo 1 > /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
   cat /sys/bus/pci/devices/0000\:06\:00.0/sriov_numvfs
   rmmod ixgbevf

   # set up Fortville VF
   cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
   echo 1 > /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
   cat /sys/bus/pci/devices/0000\:03\:00.0/sriov_numvfs
   rmmod i40evf

vm_virtio_one_migrate.sh
~~~~~~~~~~~~~~~~~~~~~~~~

Setup Virtual Machine on host_server_2

.. code-block:: sh

   #!/bin/sh
   # Start the VM on host_server_2 with the same parameters except without the VF
   # parameters, as the VM on host_server_1, in migration-listen mode
   # (-incoming tcp:0:5555)

   # Path to KVM tool
   KVM_PATH="/usr/bin/qemu-system-x86_64"

   # Guest Disk image
   DISK_IMG="/home/username/disk_image/virt1_sml.disk"

   # Number of guest cpus
   VCPUS_NR="4"

   # Memory
   MEM=1536

   taskset -c 1-5 $KVM_PATH \
    -enable-kvm \
    -m $MEM \
    -smp $VCPUS_NR \
    -cpu host \
    -name VM1 \
    -no-reboot \
    -net none \
    -vnc none -nographic \
    -hda $DISK_IMG \
    -netdev type=tap,id=net1,script=no,downscript=no,ifname=tap1 \
    -device virtio-net-pci,netdev=net1,mac=CC:BB:BB:BB:BB:BB \
    -incoming tcp:0:5555 \
    -monitor telnet::3333,server,nowait

setup_bridge_on_212_131.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~

Setup bridge on host_server_2

.. code-block:: sh

   #!/bin/sh
   # This script is run on the host to setup the bridge
   # for the Tap device and the PF device.
   # This enables traffic to go from the PF to the Tap to the Virtio PMD in the VM.

   # ens4f0 is the Niantic NIC
   # ens5f0 is the Fortville NIC

   ifconfig ens4f0 down
   ifconfig tap1 down
   ifconfig ens5f0 down
   ifconfig virbr0 down

   brctl show virbr0
   brctl addif virbr0 ens4f0
   brctl addif virbr0 ens5f0
   brctl addif virbr0 tap1
   brctl show virbr0

   ifconfig ens4f0 up
   ifconfig tap1 up
   ifconfig ens5f0 up
   ifconfig virbr0 up

.. _lm_bond_virtio_sriov_vm_scripts:

Sample VM scripts
-----------------

setup_dpdk_in_vm.sh
~~~~~~~~~~~~~~~~~~~

Set up DPDK in the Virtual Machine

.. code-block:: sh

   #!/bin/sh
   # this script matches the vm_virtio_vf_one script
   # virtio port is 03
   # vf port is 04

   cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
   echo 1024 > /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages
   cat  /sys/kernel/mm/hugepages/hugepages-2048kB/nr_hugepages

   ifconfig -a
   /root/dpdk/usertools/dpdk-devbind.py --status

   rmmod virtio-pci ixgbevf

   modprobe uio
   insmod /root/dpdk/x86_64-default-linuxapp-gcc/kmod/igb_uio.ko

   /root/dpdk/usertools/dpdk-devbind.py -b igb_uio 0000:00:03.0
   /root/dpdk/usertools/dpdk-devbind.py -b igb_uio 0000:00:04.0

   /root/dpdk/usertools/dpdk-devbind.py --status

run_testpmd_bonding_in_vm.sh
~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Run testpmd in the Virtual Machine.

.. code-block:: sh

   #!/bin/sh
   # Run testpmd in the VM

   # The test system has 8 cpus (0-7), use cpus 2-7 for VM
   # Use taskset -pc <core number> <thread_id>

   # use for bonding of virtio and vf tests in VM

   /root/dpdk/x86_64-default-linuxapp-gcc/app/testpmd \
   -l 0-3 -n 4 --socket-mem 350 --  --i --port-topology=chained

.. _lm_bond_virtio_sriov_switch_conf:

Sample switch configuration
---------------------------

The Intel switch is used to connect the traffic generator to the
NIC's on host_server_1 and host_server_2.

In order to run the switch configuration two console windows are required.

Log in as root in both windows.

TestPointShared, run_switch.sh and load /root/switch_config must be executed
in the sequence below.

On Switch: Terminal 1
~~~~~~~~~~~~~~~~~~~~~

run TestPointShared

.. code-block:: console

   /usr/bin/TestPointShared

On Switch: Terminal 2
~~~~~~~~~~~~~~~~~~~~~

execute run_switch.sh

.. code-block:: console

   /root/run_switch.sh

On Switch: Terminal 1
~~~~~~~~~~~~~~~~~~~~~

load switch configuration

.. code-block:: console

   load /root/switch_config

Sample switch configuration script
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``/root/switch_config`` script:

.. code-block:: sh

   # TestPoint History
   show port 1,5,9,13,17,21,25
   set port 1,5,9,13,17,21,25 up
   show port 1,5,9,13,17,21,25
   del acl 1
   create acl 1
   create acl-port-set
   create acl-port-set
   add port port-set 1 0
   add port port-set 5,9,13,17,21,25 1
   create acl-rule 1 1
   add acl-rule condition 1 1 port-set 1
   add acl-rule action 1 1 redirect 1
   apply acl
   create vlan 1000
   add vlan port 1000 1,5,9,13,17,21,25
   set vlan tagging 1000 1,5,9,13,17,21,25 tag
   set switch config flood_ucast fwd
   show port stats all 1,5,9,13,17,21,25