Enable PVP and PVVP deployments for Vanilla OVS
[vswitchperf.git] / vnfs / qemu / qemu_dpdk.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-cuse enabled guests.
16 """
17
18 from vnfs.qemu.qemu import IVnfQemu
19 from conf import settings as S
20
21 class IVnfQemuDpdk(IVnfQemu):
22     """
23     An abstract class for controling an instance of QEMU with DPDK vHost support
24     """
25
26     def __init__(self):
27         """
28         Initialisation function.
29         """
30         super(IVnfQemuDpdk, self).__init__()
31         self._cmd += ['-drive',
32                       'if=scsi,file=fat:rw:%s,snapshot=off' %
33                       S.getValue('GUEST_SHARE_DIR')[self._number],
34                      ]
35
36     def _modify_dpdk_makefile(self):
37         """
38         Modifies DPDK makefile in Guest before compilation
39         """
40         pass
41
42     def _config_guest_loopback(self):
43         """
44         Configure VM to run testpmd
45
46         Configure performs the following:
47         * Mount hugepages
48         * mount shared directory for copying DPDK
49         * Disable firewall
50         * Compile DPDK
51         * DPDK NIC bind
52         * Run testpmd
53         """
54
55         # Guest images _should_ have 1024 hugepages by default,
56         # but just in case:'''
57         self.execute_and_wait('sysctl vm.nr_hugepages=1024')
58
59         # Mount hugepages
60         self.execute_and_wait('mkdir -p /dev/hugepages')
61         self.execute_and_wait(
62             'mount -t hugetlbfs hugetlbfs /dev/hugepages')
63
64         # mount shared directory
65         self.execute_and_wait('umount ' + S.getValue('OVS_DPDK_SHARE'))
66         self.execute_and_wait('rm -rf ' + S.getValue('GUEST_OVS_DPDK_DIR'))
67         self.execute_and_wait('mkdir -p ' + S.getValue('OVS_DPDK_SHARE'))
68         self.execute_and_wait('mount -o iocharset=utf8 /dev/sdb1 ' +
69                               S.getValue('OVS_DPDK_SHARE'))
70         self.execute_and_wait('mkdir -p ' + S.getValue('GUEST_OVS_DPDK_DIR'))
71         self.execute_and_wait('cp -a ' + S.getValue('OVS_DPDK_SHARE') + '/* ' +
72                               S.getValue('GUEST_OVS_DPDK_DIR'))
73         # Get VM info
74         self.execute_and_wait('cat /etc/default/grub')
75
76         # Disable services (F16)
77         self.execute_and_wait('systemctl status iptables.service')
78         self.execute_and_wait('systemctl stop iptables.service')
79
80         # build and configure system for dpdk
81         self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
82                               '/DPDK')
83         self.execute_and_wait('export CC=gcc')
84         self.execute_and_wait('export RTE_SDK=' +
85                               S.getValue('GUEST_OVS_DPDK_DIR') + '/DPDK')
86         self.execute_and_wait('export RTE_TARGET=%s' % S.getValue('RTE_TARGET'))
87
88         # modify makefile if needed
89         self._modify_dpdk_makefile()
90
91         self.execute_and_wait('make RTE_OUTPUT=$RTE_SDK/$RTE_TARGET -C '
92                               '$RTE_SDK/lib/librte_eal/linuxapp/igb_uio')
93         self.execute_and_wait('modprobe uio')
94         self.execute_and_wait('insmod %s/kmod/igb_uio.ko' %
95                               S.getValue('RTE_TARGET'))
96         self.execute_and_wait('./tools/dpdk_nic_bind.py --status')
97         self.execute_and_wait(
98             './tools/dpdk_nic_bind.py -b igb_uio' ' ' +
99             S.getValue('GUEST_NET1_PCI_ADDRESS')[self._number] + ' ' +
100             S.getValue('GUEST_NET2_PCI_ADDRESS')[self._number])
101
102         # build and run 'test-pmd'
103         self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
104                               '/DPDK/app/test-pmd')
105         self.execute_and_wait('make clean')
106         self.execute_and_wait('make')
107         self.execute_and_wait('./testpmd -c 0x3 -n 4 --socket-mem 512 --'
108                               ' --burst=64 -i --txqflags=0xf00 ' +
109                               '--disable-hw-vlan', 60, "Done")
110         self.execute('set fwd mac_retry', 1)
111         self.execute_and_wait('start', 20,
112                               'TX RS bit threshold=0 - TXQ flags=0xf00')