vhost_affin_fixup: Change vhost thread from regex to pgrep usage
[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 indexes of guest devices (e.g. charx, dpdkvhostuserx)
40         i = self._number * 2
41         if1 = str(i)
42         if2 = str(i + 1)
43
44         # multi-queue values
45         if int(S.getValue('GUEST_NIC_QUEUES')):
46             queue_str = ',queues={}'.format(S.getValue('GUEST_NIC_QUEUES'))
47             mq_vector_str = ',mq=on,vectors={}'.format(
48                 int(S.getValue('GUEST_NIC_QUEUES')) * 2 + 2)
49         else:
50             queue_str, mq_vector_str = '', ''
51
52         self._cmd += ['-netdev',
53                       'tap,id=' + self._net1 + queue_str +
54                       ',script=no,downscript=no,' +
55                       'ifname=tap' + if1 + ',vhost=on',
56                       '-device',
57                       'virtio-net-pci,mac=' +
58                       S.getValue('GUEST_NET1_MAC')[self._number] +
59                       ',netdev=' + self._net1 +
60                       ',csum=off,gso=off,' +
61                       'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
62                       mq_vector_str,
63                       '-netdev',
64                       'tap,id=' + self._net2 + queue_str +
65                       ',script=no,downscript=no,' +
66                       'ifname=tap' + if2 + ',vhost=on',
67                       '-device',
68                       'virtio-net-pci,mac=' +
69                       S.getValue('GUEST_NET2_MAC')[self._number] +
70                       ',netdev=' + self._net2 +
71                       ',csum=off,gso=off,' +
72                       'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
73                       mq_vector_str,
74         ]