Merge "integration: Test vHost User numa awareness"
[vswitchperf.git] / vnfs / qemu / qemu_dpdk_vhost_user.py
1 # Copyright 2015 Intel Corporation.
2 #
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
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 """Automation of QEMU hypervisor for launching vhost-user enabled guests.
16 """
17
18 import logging
19
20 from conf import settings as S
21 from conf import get_test_param
22 from vnfs.qemu.qemu import IVnfQemu
23
24 class QemuDpdkVhostUser(IVnfQemu):
25     """
26     Control an instance of QEMU with vHost user guest communication.
27     """
28     def __init__(self):
29         """
30         Initialisation function.
31         """
32         super(QemuDpdkVhostUser, self).__init__()
33         self._logger = logging.getLogger(__name__)
34
35         # multi-queue values
36         guest_nic_queues = int(get_test_param('guest_nic_queues', 0))
37         if guest_nic_queues:
38             override_list = [guest_nic_queues] * (self._number + 1)
39             S.setValue('GUEST_NIC_QUEUES', override_list)
40         if int(S.getValue('GUEST_NIC_QUEUES')[self._number]):
41             queue_str = ',queues={}'.format(S.getValue('GUEST_NIC_QUEUES')[self._number])
42             mq_vector_str = ',mq=on,vectors={}'.format(
43                 int(S.getValue('GUEST_NIC_QUEUES')[self._number]) * 2 + 2)
44         else:
45             queue_str, mq_vector_str = '', ''
46
47         # Guest merge buffer setting
48         if S.getValue('GUEST_NIC_MERGE_BUFFERS_DISABLE')[self._number]:
49             merge_buff = 'mrg_rxbuf=off,'
50         else:
51             merge_buff = ''
52
53         # calculate index of first interface, i.e. check how many
54         # interfaces has been created for previous VMs, where 1st NIC
55         # of 1st VM has index 0
56         start_index = sum(S.getValue('GUEST_NICS_NR')[:self._number])
57
58         # setup requested number of interfaces
59         for nic in range(len(self._nics)):
60             index = start_index + nic
61             ifi = str(index)
62             net = 'net' + str(index + 1)
63
64             self._cmd += ['-chardev',
65                           'socket,id=char' + ifi +
66                           ',path=' + S.getValue('TOOLS')['ovs_var_tmp'] +
67                           'dpdkvhostuser' + ifi,
68                           '-netdev',
69                           'type=vhost-user,id=' + net +
70                           ',chardev=char' + ifi + ',vhostforce' + queue_str,
71                           '-device',
72                           'virtio-net-pci,mac=' +
73                           self._nics[nic]['mac'] +
74                           ',netdev=' + net + ',csum=off,' + merge_buff +
75                           'gso=off,' +
76                           'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
77                           mq_vector_str,
78                          ]