1 # Copyright 2015 Intel Corporation.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 """Automation of QEMU hypervisor for launching vhost-user enabled guests.
20 from conf import settings as S
21 from vnfs.qemu.qemu import IVnfQemu
23 class QemuDpdkVhostUser(IVnfQemu):
25 Control an instance of QEMU with vHost user guest communication.
29 Initialisation function.
31 super(QemuDpdkVhostUser, self).__init__()
32 self._logger = logging.getLogger(__name__)
35 if int(S.getValue('GUEST_NIC_QUEUES')[self._number]):
36 queue_str = ',queues={}'.format(S.getValue('GUEST_NIC_QUEUES')[self._number])
37 mq_vector_str = ',mq=on,vectors={}'.format(
38 int(S.getValue('GUEST_NIC_QUEUES')[self._number]) * 2 + 2)
40 queue_str, mq_vector_str = '', ''
42 # Guest merge buffer setting
43 if S.getValue('GUEST_NIC_MERGE_BUFFERS_DISABLE')[self._number]:
44 merge_buff = 'mrg_rxbuf=off,'
48 # calculate index of first interface, i.e. check how many
49 # interfaces has been created for previous VMs, where 1st NIC
50 # of 1st VM has index 0
51 start_index = sum(S.getValue('GUEST_NICS_NR')[:self._number])
53 # setup requested number of interfaces
54 for nic in range(len(self._nics)):
55 index = start_index + nic
57 net = 'net' + str(index + 1)
59 # In case of testpmd as switch, path to vhost netdev folder will be set
60 # to tmp location instead of default ovs_var_tmp folder.
61 if S.getValue('VSWITCH') == 'none':
62 vhost_folder = '/tmp/'
64 vhost_folder = S.getValue('TOOLS')['ovs_var_tmp']
66 self._cmd += ['-chardev',
67 'socket,id=char' + ifi +
68 ',path=' + vhost_folder +
69 'dpdkvhostuser' + ifi,
71 'type=vhost-user,id=' + net +
72 ',chardev=char' + ifi + ',vhostforce' + queue_str,
74 'virtio-net-pci,mac=' +
75 self._nics[nic]['mac'] +
76 ',netdev=' + net + ',csum=off,' + merge_buff +
78 'guest_tso4=off,guest_tso6=off,guest_ecn=off' +