summaryrefslogtreecommitdiffstats
path: root/vnfs/qemu/qemu_dpdk.py
blob: 0b8f90a090529f7b9a88797c614fb5c7113580d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# Copyright 2015 Intel Corporation.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Automation of QEMU hypervisor for launching vhost-cuse enabled guests.
"""

from vnfs.qemu.qemu import IVnfQemu
from conf import settings as S

class IVnfQemuDpdk(IVnfQemu):
    """
    An abstract class for controling an instance of QEMU with DPDK vHost support
    """

    def __init__(self):
        """
        :param timeout: Time to wait for login prompt. If set to
            0 do not wait.
        :param number: Number of QEMU instance, used when multiple QEMU
            instances are started at once.
        :param args: Arguments to pass to QEMU.

        :returns: None
        """
        super(IVnfQemuDpdk, self).__init__()
        self._cmd += []

    def _modify_dpdk_makefile(self):
        """
        Modifies DPDK makefile in Guest before compilation
        """
        pass

    def _config_guest_loopback(self):
        """
        Configure VM to run testpmd

        Configure performs the following:
        * Mount hugepages
        * mount shared directory for copying DPDK
        * Disable firewall
        * Compile DPDK
        * DPDK NIC bind
        * Run testpmd
        """

        # Guest images _should_ have 1024 hugepages by default,
        # but just in case:'''
        self.execute_and_wait('sysctl vm.nr_hugepages=1024')

        # Mount hugepages
        self.execute_and_wait('mkdir -p /dev/hugepages')
        self.execute_and_wait(
            'mount -t hugetlbfs hugetlbfs /dev/hugepages')

        # mount shared directory
        self.execute_and_wait('umount ' + S.getValue('OVS_DPDK_SHARE'))
        self.execute_and_wait('rm -rf ' + S.getValue('GUEST_OVS_DPDK_DIR'))
        self.execute_and_wait('mkdir -p ' + S.getValue('OVS_DPDK_SHARE'))
        self.execute_and_wait('mount -o iocharset=utf8 /dev/sdb1 ' +
                              S.getValue('OVS_DPDK_SHARE'))
        self.execute_and_wait('mkdir -p ' + S.getValue('GUEST_OVS_DPDK_DIR'))
        self.execute_and_wait('cp -a ' + S.getValue('OVS_DPDK_SHARE') + '/* ' +
                              S.getValue('GUEST_OVS_DPDK_DIR'))
        # Get VM info
        self.execute_and_wait('cat /etc/default/grub')

        # Disable services (F16)
        self.execute_and_wait('systemctl status iptables.service')
        self.execute_and_wait('systemctl stop iptables.service')

        # build and configure system for dpdk
        self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
                              '/DPDK')
        self.execute_and_wait('export CC=gcc')
        self.execute_and_wait('export RTE_SDK=' +
                              S.getValue('GUEST_OVS_DPDK_DIR') + '/DPDK')
        self.execute_and_wait('export RTE_TARGET=%s' % S.getValue('RTE_TARGET'))

        # modify makefile if needed
        self._modify_dpdk_makefile()

        self.execute_and_wait('make RTE_OUTPUT=$RTE_SDK/$RTE_TARGET -C '
                              '$RTE_SDK/lib/librte_eal/linuxapp/igb_uio')
        self.execute_and_wait('modprobe uio')
        self.execute_and_wait('insmod %s/kmod/igb_uio.ko' %
                              S.getValue('RTE_TARGET'))
        self.execute_and_wait('./tools/dpdk_nic_bind.py --status')
        self.execute_and_wait(
            './tools/dpdk_nic_bind.py -b igb_uio' ' ' +
            S.getValue('GUEST_NET1_PCI_ADDRESS')[self._number] + ' ' +
            S.getValue('GUEST_NET2_PCI_ADDRESS')[self._number])

        # build and run 'test-pmd'
        self.execute_and_wait('cd ' + S.getValue('GUEST_OVS_DPDK_DIR') +
                              '/DPDK/app/test-pmd')
        self.execute_and_wait('make clean')
        self.execute_and_wait('make')
        self.execute_and_wait('./testpmd -c 0x3 -n 4 --socket-mem 512 --'
                              ' --burst=64 -i --txqflags=0xf00 ' +
                              '--disable-hw-vlan', 60, "Done")
        self.execute('set fwd mac_retry', 1)
        self.execute_and_wait('start', 20,
                              'TX RS bit threshold=0 - TXQ flags=0xf00')