multi VM: Multi VMs in serial or parallel
[vswitchperf.git] / vnfs / qemu / qemu_virtio_net.py
1 # Copyright 2016 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 virtio-net enabled guests.
16 """
17
18 import logging
19 from vnfs.qemu.qemu import IVnfQemu
20 from conf import settings as S
21 from tools import tasks
22
23 class QemuVirtioNet(IVnfQemu):
24     """
25     Control an instance of QEMU with virtio-net guest communication.
26     """
27
28     def __init__(self):
29         """
30         Initialisation function.
31         """
32         super(QemuVirtioNet, self).__init__()
33         self._logger = logging.getLogger(__name__)
34
35         # insert vanilla ovs specific modules
36         tasks.run_task(['sudo', 'modprobe', 'vhost_net'], self._logger,
37                        'Loading vhost_net module...', True)
38
39         # calculate index of first interface, i.e. check how many
40         # interfaces has been created for previous VMs, where 1st NIC
41         # of 1st VM has index 0
42         start_index = sum(S.getValue('GUEST_NICS_NR')[:self._number])
43
44         # multi-queue values
45         if int(S.getValue('GUEST_NIC_QUEUES')[self._number]):
46             queue_str = ',queues={}'.format(
47                 S.getValue('GUEST_NIC_QUEUES')[self._number])
48             mq_vector_str = ',mq=on,vectors={}'.format(
49                 int(S.getValue('GUEST_NIC_QUEUES')[self._number]) * 2 + 2)
50         else:
51             queue_str, mq_vector_str = '', ''
52
53         # setup requested number of interfaces
54         for nic in range(len(self._nics)):
55             index = start_index + nic
56             ifi = str(index)
57             self._cmd += ['-netdev', 'type=tap,id=' +
58                           self._nics[nic]['device'] + queue_str +
59                           ',script=no,downscript=no,' +
60                           'ifname=tap' + ifi + ',vhost=on',
61                           '-device',
62                           'virtio-net-pci,mac=' +
63                           self._nics[nic]['mac'] + ',netdev=' +
64                           self._nics[nic]['device'] +
65                           ',csum=off,gso=off,' +
66                           'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
67                           mq_vector_str,
68                          ]