vnfs: configurable loopback application support inside VM
[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 vnfs.qemu.qemu import IVnfQemu
22
23 class QemuDpdkVhostUser(IVnfQemu):
24     """
25     Control an instance of QEMU with vHost user guest communication.
26     """
27     def __init__(self):
28         """
29         Initialisation function.
30         """
31         super(QemuDpdkVhostUser, self).__init__()
32         self._logger = logging.getLogger(__name__)
33
34         # calculate indexes of guest devices (e.g. charx, dpdkvhostuserx)
35         i = self._number * 2
36         if1 = str(i)
37         if2 = str(i + 1)
38         net1 = 'net' + str(i + 1)
39         net2 = 'net' + str(i + 2)
40
41         self._cmd += ['-chardev',
42                       'socket,id=char' + if1 +
43                       ',path=' + S.getValue('OVS_VAR_DIR') +
44                       'dpdkvhostuser' + if1,
45                       '-chardev',
46                       'socket,id=char' + if2 +
47                       ',path=' + S.getValue('OVS_VAR_DIR') +
48                       'dpdkvhostuser' + if2,
49                       '-netdev',
50                       'type=vhost-user,id=' + net1 +
51                       ',chardev=char' + if1 + ',vhostforce',
52                       '-device',
53                       'virtio-net-pci,mac=' +
54                       S.getValue('GUEST_NET1_MAC')[self._number] +
55                       ',netdev=' + net1 + ',csum=off,gso=off,' +
56                       'guest_tso4=off,guest_tso6=off,guest_ecn=off',
57                       '-netdev',
58                       'type=vhost-user,id=' + net2 +
59                       ',chardev=char' + if2 + ',vhostforce',
60                       '-device',
61                       'virtio-net-pci,mac=' +
62                       S.getValue('GUEST_NET2_MAC')[self._number] +
63                       ',netdev=' + net2 + ',csum=off,gso=off,' +
64                       'guest_tso4=off,guest_tso6=off,guest_ecn=off',
65                      ]
66