summaryrefslogtreecommitdiffstats
path: root/vnfs/qemu
diff options
context:
space:
mode:
Diffstat (limited to 'vnfs/qemu')
-rw-r--r--vnfs/qemu/qemu.py127
1 files changed, 71 insertions, 56 deletions
diff --git a/vnfs/qemu/qemu.py b/vnfs/qemu/qemu.py
index 01c16a0f..997f93e0 100644
--- a/vnfs/qemu/qemu.py
+++ b/vnfs/qemu/qemu.py
@@ -24,7 +24,6 @@ import time
import pexpect
from conf import settings as S
-from conf import get_test_param
from vnfs.vnf.vnf import IVnf
class IVnfQemu(IVnf):
@@ -69,7 +68,6 @@ class IVnfQemu(IVnf):
self._nics = S.getValue('GUEST_NICS')[self._number][:nics_nr]
# set guest loopback application based on VNF configuration
- # cli option take precedence to config file values
self._guest_loopback = S.getValue('GUEST_LOOPBACK')[self._number]
self._testpmd_fwd_mode = S.getValue('GUEST_TESTPMD_FWD_MODE')[self._number]
@@ -83,9 +81,11 @@ class IVnfQemu(IVnf):
name = 'Client%d' % self._number
vnc = ':%d' % self._number
- # don't use taskset to affinize main qemu process; It causes hangup
- # of 2nd VM in case of DPDK. It also slows down VM responsivnes.
- self._cmd = ['sudo', '-E', S.getValue('TOOLS')['qemu-system'],
+ # NOTE: affinization of main qemu process can cause hangup of 2nd VM
+ # in case of DPDK usage. It can also slow down VM response time.
+ cpumask = ",".join(S.getValue('GUEST_CORE_BINDING')[self._number])
+ self._cmd = ['sudo', '-E', 'taskset', '-c', cpumask,
+ S.getValue('TOOLS')['qemu-system'],
'-m', S.getValue('GUEST_MEMORY')[self._number],
'-smp', str(S.getValue('GUEST_SMP')[self._number]),
'-cpu', 'host,migratable=off',
@@ -144,27 +144,28 @@ class IVnfQemu(IVnf):
"""
Stops VNF instance gracefully first.
"""
- try:
- # exit testpmd if needed
- if self._guest_loopback == 'testpmd':
- self.execute_and_wait('stop', 120, "Done")
- self.execute_and_wait('quit', 120, "[bB]ye")
+ if self.is_running():
+ try:
+ # exit testpmd if needed
+ if self._guest_loopback == 'testpmd':
+ self.execute_and_wait('stop', 120, "Done")
+ self.execute_and_wait('quit', 120, "[bB]ye")
- # turn off VM
- self.execute_and_wait('poweroff', 120, "Power down")
+ # turn off VM
+ self.execute_and_wait('poweroff', 120, "Power down")
- except pexpect.TIMEOUT:
- self.kill()
+ except pexpect.TIMEOUT:
+ self.kill()
- # wait until qemu shutdowns
- self._logger.debug('Wait for QEMU to terminate')
- for dummy in range(30):
- time.sleep(1)
- if not self.is_running():
- break
+ # wait until qemu shutdowns
+ self._logger.debug('Wait for QEMU to terminate')
+ for dummy in range(30):
+ time.sleep(1)
+ if not self.is_running():
+ break
- # just for case that graceful shutdown failed
- super(IVnfQemu, self).stop()
+ # just for case that graceful shutdown failed
+ super(IVnfQemu, self).stop()
# helper functions
@@ -340,7 +341,6 @@ class IVnfQemu(IVnf):
self.execute_and_wait("{} -t {} -F".format(iptables, table))
self.execute_and_wait("{} -t {} -X".format(iptables, table))
-
def _configure_testpmd(self):
"""
Configure VM to perform L2 forwarding between NICs by DPDK's testpmd
@@ -372,16 +372,11 @@ class IVnfQemu(IVnf):
for nic in self._nics:
self.execute_and_wait('ifdown ' + nic['device'])
- # build and insert igb_uio and rebind interfaces to it
- 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*bind.py --status')
pci_list = ' '.join([nic['pci'] for nic in self._nics])
self.execute_and_wait('./tools/dpdk*bind.py -u ' + pci_list)
- self.execute_and_wait('./tools/dpdk*bind.py -b igb_uio ' + pci_list)
+ self._bind_dpdk_driver(S.getValue(
+ 'GUEST_DPDK_BIND_DRIVER')[self._number], pci_list)
self.execute_and_wait('./tools/dpdk*bind.py --status')
# build and run 'test-pmd'
@@ -389,25 +384,13 @@ class IVnfQemu(IVnf):
'/DPDK/app/test-pmd')
self.execute_and_wait('make clean')
self.execute_and_wait('make')
- if int(S.getValue('GUEST_NIC_QUEUES')[self._number]):
- self.execute_and_wait(
- './testpmd {} -n4 --socket-mem 512 --'.format(
- S.getValue('GUEST_TESTPMD_CPU_MASK')[self._number]) +
- ' --burst=64 -i --txqflags=0xf00 ' +
- '--nb-cores={} --rxq={} --txq={} '.format(
- S.getValue('GUEST_TESTPMD_NB_CORES')[self._number],
- S.getValue('GUEST_TESTPMD_TXQ')[self._number],
- S.getValue('GUEST_TESTPMD_RXQ')[self._number]) +
- '--disable-hw-vlan', 60, "Done")
- else:
- self.execute_and_wait(
- './testpmd {} -n 4 --socket-mem 512 --'.format(
- S.getValue('GUEST_TESTPMD_CPU_MASK')[self._number]) +
- ' --burst=64 -i --txqflags=0xf00 ' +
- '--disable-hw-vlan', 60, "Done")
+
+ # get testpmd settings from CLI
+ testpmd_params = S.getValue('GUEST_TESTPMD_PARAMS')[self._number]
+
+ self.execute_and_wait('./testpmd {}'.format(testpmd_params), 60, "Done")
self.execute('set fwd ' + self._testpmd_fwd_mode, 1)
- self.execute_and_wait('start', 20,
- 'TX RS bit threshold=.+ - TXQ flags=0xf00')
+ self.execute_and_wait('start', 20, 'testpmd>')
def _configure_l2fwd(self):
"""
@@ -463,17 +446,13 @@ class IVnfQemu(IVnf):
# Add the arp entries for the IXIA ports and the bridge you are using.
# Use command line values if provided.
- trafficgen_mac = get_test_param('vanilla_tgen_port1_mac',
- S.getValue('VANILLA_TGEN_PORT1_MAC'))
- trafficgen_ip = get_test_param('vanilla_tgen_port1_ip',
- S.getValue('VANILLA_TGEN_PORT1_IP'))
+ trafficgen_mac = S.getValue('VANILLA_TGEN_PORT1_MAC')
+ trafficgen_ip = S.getValue('VANILLA_TGEN_PORT1_IP')
self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
- trafficgen_mac = get_test_param('vanilla_tgen_port2_mac',
- S.getValue('VANILLA_TGEN_PORT2_MAC'))
- trafficgen_ip = get_test_param('vanilla_tgen_port2_ip',
- S.getValue('VANILLA_TGEN_PORT2_IP'))
+ trafficgen_mac = S.getValue('VANILLA_TGEN_PORT2_MAC')
+ trafficgen_ip = S.getValue('VANILLA_TGEN_PORT2_IP')
self.execute('arp -s ' + trafficgen_ip + ' ' + trafficgen_mac)
@@ -486,6 +465,42 @@ class IVnfQemu(IVnf):
for nic in self._nics:
self.execute('sysctl -w net.ipv4.conf.' + nic['device'] + '.rp_filter=0')
+ def _bind_dpdk_driver(self, driver, pci_slots):
+ """
+ Bind the virtual nics to the driver specific in the conf file
+ :return: None
+ """
+ if driver == 'uio_pci_generic':
+ if S.getValue('VNF') == 'QemuPciPassthrough':
+ # unsupported config, bind to igb_uio instead and exit the
+ # outer function after completion.
+ self._logger.error('SR-IOV does not support uio_pci_generic. '
+ 'Igb_uio will be used instead.')
+ self._bind_dpdk_driver('igb_uio_from_src', pci_slots)
+ return
+ self.execute_and_wait('modprobe uio_pci_generic')
+ self.execute_and_wait('./tools/dpdk*bind.py -b uio_pci_generic '+
+ pci_slots)
+ elif driver == 'vfio_no_iommu':
+ self.execute_and_wait('modprobe -r vfio')
+ self.execute_and_wait('modprobe -r vfio_iommu_type1')
+ self.execute_and_wait('modprobe vfio enable_unsafe_noiommu_mode=Y')
+ self.execute_and_wait('modprobe vfio-pci')
+ self.execute_and_wait('./tools/dpdk*bind.py -b vfio-pci ' +
+ pci_slots)
+ elif driver == 'igb_uio_from_src':
+ # build and insert igb_uio and rebind interfaces to it
+ 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*bind.py -b igb_uio ' + pci_slots)
+ else:
+ self._logger.error(
+ 'Unknown driver for binding specified, defaulting to igb_uio')
+ self._bind_dpdk_driver('igb_uio_from_src', pci_slots)
+
def _set_multi_queue_nic(self):
"""
Enable multi-queue in guest kernel with ethool.