3 ##############################################################################
4 ##Copyright (c) 2015 Intel Corp.
6 ## All rights reserved. This program and the accompanying materials
7 ## are made available under the terms of the Apache License, Version 2.0
8 ## which accompanies this distribution, and is available at
9 ## http://www.apache.org/licenses/LICENSE-2.0
10 ###############################################################################
15 HOST_IP=$( getHostIP )
16 #source qmp-sock for conmunication with qemu
17 qmp_sock_src="/tmp/qmp-sock-src"
18 #destination qmp-sock for conmunication with qemu, only for local live migration
19 qmp_sock_dst="/tmp/qmp-sock-dst"
21 VHOSTPATH1='/usr/local/var/run/openvswitch/vhost-user1'
22 VHOSTPATH2='/usr/local/var/run/openvswitch/vhost-user2'
24 VHOSTPATH3='/usr/local/var/run/openvswitch/vhost-user3'
25 VHOSTPATH4='/usr/local/var/run/openvswitch/vhost-user4'
27 MACADDRESS1='52:54:00:12:34:56'
28 MACADDRESS2='54:54:00:12:34:56'
30 #destination host ip address
36 OVSLOGFILE='/var/log/openvswitch/ovs-vswitchd.log'
38 function run_qemusrc() {
39 $qemu -enable-kvm -cpu host -smp ${guest_cpus} -chardev socket,id=char1,path=$VHOSTPATH1 \
40 -netdev type=vhost-user,id=net1,chardev=char1,vhostforce \
41 -device virtio-net-pci,netdev=net1,mac=$MACADDRESS1 \
42 -chardev socket,id=char2,path=$VHOSTPATH2 \
43 -netdev type=vhost-user,id=net2,chardev=char2,vhostforce \
44 -device virtio-net-pci,netdev=net2,mac=$MACADDRESS2 -m 2048 -mem-path /dev/hugepages \
45 -mem-prealloc -realtime mlock=on -monitor unix:${qmp_sock_src},server,nowait \
46 -balloon virtio -drive file=/root/guest1.qcow2 -vnc :1 &
47 if [ ${?} -ne 0 ] ; then
48 echo "Qemu Source not started"
53 function run_qemulisten() {
54 $qemu -enable-kvm -cpu host -smp ${guest_cpus} -chardev socket,id=char1,path=$VHOSTPATH3 \
55 -netdev type=vhost-user,id=net1,chardev=char1,vhostforce \
56 -device virtio-net-pci,netdev=net1,mac=$MACADDRESS1 \
57 -chardev socket,id=char2,path=$VHOSTPATH4 \
58 -netdev type=vhost-user,id=net2,chardev=char2,vhostforce \
59 -device virtio-net-pci,netdev=net2,mac=$MACADDRESS2 -m 2048 -mem-path /dev/hugepages \
60 -mem-prealloc -realtime mlock=on -monitor unix:${qmp_sock_dst},server,nowait \
61 -balloon virtio -drive file=/root/guest1.qcow2 -incoming tcp:${incoming_ip}:${migrate_port} -vnc :3 &
62 if [ ${?} -ne 0 ] ; then
63 echo "Qemu Standby not started"
68 function do_migration() {
73 echo "migrate_set_speed 0" |nc -U $src
74 #set the expected max downtime
75 echo "migrate_set_downtime ${max_down_time}" |nc -U $src
77 echo "migrate -d tcp:${incoming_ip}:${migrate_port}" |nc -U $src
78 #wait until live migration completed
80 while [ "${status}" == "" ]
82 status=`echo "info migrate" | nc -U $src |grep completed | cut -d: -f2`
87 status=`echo "info migrate" | nc -U $src |grep completed | cut -d: -f2`
88 total_time=`echo "info migrate" | nc -U $src |grep "total time" | cut -d: -f2`
89 down_time=`echo "info migrate" | nc -U $src |grep "downtime" | cut -d: -f2`
91 #print detail information
92 echo "info migrate" | nc -U $src
93 echo "quit" | nc -U $src
94 echo "quit" | nc -U $dst
96 echo "Migration executed successfully"
98 echo "Running Qemu Source"
101 echo "Running Qemu listen"
104 echo "To check qemu src and dst are created"
105 ls -la /tmp/ | grep qmp-sock-*
106 echo "End of host-run-livemigration"
107 #do_migration $qmp_sock_src $qmp_sock_dst
108 #if [ ${?} -ne 0 ] ; then
109 #echo "Migration Failed"