summaryrefslogtreecommitdiffstats
path: root/vnfs/qemu
diff options
context:
space:
mode:
Diffstat (limited to 'vnfs/qemu')
-rw-r--r--vnfs/qemu/qemu.py116
-rw-r--r--vnfs/qemu/qemu_dpdk_vhost_cuse.py10
-rw-r--r--vnfs/qemu/qemu_dpdk_vhost_user.py19
-rw-r--r--vnfs/qemu/qemu_pci_passthrough.py87
4 files changed, 192 insertions, 40 deletions
diff --git a/vnfs/qemu/qemu.py b/vnfs/qemu/qemu.py
index cb6d9ecc..9382edef 100644
--- a/vnfs/qemu/qemu.py
+++ b/vnfs/qemu/qemu.py
@@ -20,6 +20,8 @@ import logging
import locale
import re
import subprocess
+import time
+import pexpect
from conf import settings as S
from conf import get_test_param
@@ -62,6 +64,18 @@ class IVnfQemu(IVnf):
else:
self._net2 = self._net2.split(',')[self._number]
+ # 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')
+ # in case of SRIOV we must ensure, that MAC addresses are not swapped
+ if S.getValue('SRIOV_ENABLED') and self._testpmd_fwd_mode.startswith('mac') and \
+ not S.getValue('VNF').endswith('PciPassthrough'):
+
+ self._logger.info("SRIOV detected, forwarding mode of testpmd was changed from '%s' to '%s'",
+ self._testpmd_fwd_mode, 'io')
+ self._testpmd_fwd_mode = 'io'
name = 'Client%d' % self._number
vnc = ':%d' % self._number
@@ -116,6 +130,32 @@ class IVnfQemu(IVnf):
if self._timeout:
self._config_guest_loopback()
+ def stop(self):
+ """
+ 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")
+
+ # turn off VM
+ self.execute_and_wait('poweroff', 120, "Power down")
+
+ 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
+
+ # just for case that graceful shutdown failed
+ super(IVnfQemu, self).stop()
+
# helper functions
def _login(self, timeout=120):
@@ -196,24 +236,20 @@ class IVnfQemu(IVnf):
def _config_guest_loopback(self):
"""
- Configure VM to run VNF (e.g. port forwarding application)
+ Configure VM to run VNF, e.g. port forwarding application based on the configuration
"""
- # set guest loopback application based on VNF configuration
- # cli option take precedence to config file values
- guest_loopback = S.getValue('GUEST_LOOPBACK')[self._number]
-
- if guest_loopback == 'testpmd':
+ if self._guest_loopback == 'testpmd':
self._login()
self._configure_testpmd()
- elif guest_loopback == 'l2fwd':
+ elif self._guest_loopback == 'l2fwd':
self._login()
self._configure_l2fwd()
- elif guest_loopback == 'linux_bridge':
+ elif self._guest_loopback == 'linux_bridge':
self._login()
self._configure_linux_bridge()
- elif guest_loopback != 'buildin':
+ elif self._guest_loopback != 'buildin':
self._logger.error('Unsupported guest loopback method "%s" was specified. Option'
- ' "buildin" will be used as a fallback.', guest_loopback)
+ ' "buildin" will be used as a fallback.', self._guest_loopback)
def wait(self, prompt=S.getValue('GUEST_PROMPT'), timeout=30):
super(IVnfQemu, self).wait(prompt=prompt, timeout=timeout)
@@ -225,7 +261,7 @@ class IVnfQemu(IVnf):
def _modify_dpdk_makefile(self):
"""
- Modifies DPDK makefile in Guest before compilation
+ Modifies DPDK makefile in Guest before compilation if needed
"""
pass
@@ -234,14 +270,15 @@ class IVnfQemu(IVnf):
Mount shared directory and copy DPDK and l2fwd sources
"""
# mount shared directory
- self.execute_and_wait('umount ' + S.getValue('OVS_DPDK_SHARE'))
+ self.execute_and_wait('umount /dev/sdb1')
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 ' +
+ self.execute_and_wait('mount -o ro,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 -ra ' + os.path.join(S.getValue('OVS_DPDK_SHARE'), dirname) +
+ self.execute_and_wait('cp -r ' + os.path.join(S.getValue('OVS_DPDK_SHARE'), dirname) +
' ' + S.getValue('GUEST_OVS_DPDK_DIR'))
+ self.execute_and_wait('umount /dev/sdb1')
def _configure_disable_firewall(self):
"""
@@ -291,6 +328,11 @@ class IVnfQemu(IVnf):
# modify makefile if needed
self._modify_dpdk_makefile()
+ # disable network interfaces, so DPDK can take care of them
+ self.execute_and_wait('ifdown ' + self._net1)
+ self.execute_and_wait('ifdown ' + self._net2)
+
+ # 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')
@@ -298,21 +340,39 @@ class IVnfQemu(IVnf):
S.getValue('RTE_TARGET'))
self.execute_and_wait('./tools/dpdk_nic_bind.py --status')
self.execute_and_wait(
+ './tools/dpdk_nic_bind.py -u' ' ' +
+ S.getValue('GUEST_NET1_PCI_ADDRESS')[self._number] + ' ' +
+ S.getValue('GUEST_NET2_PCI_ADDRESS')[self._number])
+ 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])
+ self.execute_and_wait('./tools/dpdk_nic_bind.py --status')
# 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)
+ if int(S.getValue('GUEST_NIC_QUEUES')):
+ self.execute_and_wait(
+ './testpmd {} -n4 --socket-mem 512 --'.format(
+ S.getValue('GUEST_TESTPMD_CPU_MASK')) +
+ ' --burst=64 -i --txqflags=0xf00 ' +
+ '--nb-cores={} --rxq={} --txq={} '.format(
+ S.getValue('GUEST_TESTPMD_NB_CORES'),
+ S.getValue('GUEST_TESTPMD_TXQ'),
+ S.getValue('GUEST_TESTPMD_RXQ')) +
+ '--disable-hw-vlan', 60, "Done")
+ else:
+ self.execute_and_wait(
+ './testpmd {} -n 4 --socket-mem 512 --'.format(
+ S.getValue('GUEST_TESTPMD_CPU_MASK')) +
+ ' --burst=64 -i --txqflags=0xf00 ' +
+ '--disable-hw-vlan', 60, "Done")
+ self.execute('set fwd ' + self._testpmd_fwd_mode, 1)
self.execute_and_wait('start', 20,
- 'TX RS bit threshold=0 - TXQ flags=0xf00')
+ 'TX RS bit threshold=.+ - TXQ flags=0xf00')
def _configure_l2fwd(self):
"""
@@ -337,17 +397,23 @@ class IVnfQemu(IVnf):
"""
self._configure_disable_firewall()
- self.execute('ifconfig ' + self._net1 + ' ' +
- S.getValue('VANILLA_NIC1_IP_CIDR')[self._number])
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_NIC1_IP_CIDR')[self._number] +
+ ' dev ' + self._net1)
+ self.execute('ip link set dev ' + self._net1 + ' up')
- self.execute('ifconfig ' + self._net2 + ' ' +
- S.getValue('VANILLA_NIC2_IP_CIDR')[self._number])
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_NIC2_IP_CIDR')[self._number] +
+ ' dev ' + self._net2)
+ self.execute('ip link set dev ' + self._net2 + ' up')
# configure linux bridge
self.execute('brctl addbr br0')
self.execute('brctl addif br0 ' + self._net1 + ' ' + self._net2)
- self.execute('ifconfig br0 ' +
- S.getValue('VANILLA_BRIDGE_IP')[self._number])
+ self.execute('ip addr add ' +
+ S.getValue('VANILLA_BRIDGE_IP')[self._number] +
+ ' dev br0')
+ self.execute('ip link set dev br0 up')
# Add the arp entries for the IXIA ports and the bridge you are using.
# Use command line values if provided.
diff --git a/vnfs/qemu/qemu_dpdk_vhost_cuse.py b/vnfs/qemu/qemu_dpdk_vhost_cuse.py
index e5a5e823..ab4fec84 100644
--- a/vnfs/qemu/qemu_dpdk_vhost_cuse.py
+++ b/vnfs/qemu/qemu_dpdk_vhost_cuse.py
@@ -56,13 +56,3 @@ class QemuDpdkVhostCuse(IVnfQemu):
',netdev=' + net2 + ',csum=off,gso=off,' +
'guest_tso4=off,guest_tso6=off,guest_ecn=off',
]
-
- # helper functions
-
- def _modify_dpdk_makefile(self):
- """
- Modifies DPDK makefile in Guest before compilation
- """
- self.execute_and_wait("sed -i -e 's/CONFIG_RTE_LIBRTE_VHOST_USER=n/" +
- "CONFIG_RTE_LIBRTE_VHOST_USER=y/g'" +
- "config/common_linuxapp")
diff --git a/vnfs/qemu/qemu_dpdk_vhost_user.py b/vnfs/qemu/qemu_dpdk_vhost_user.py
index f0f97d8a..49131423 100644
--- a/vnfs/qemu/qemu_dpdk_vhost_user.py
+++ b/vnfs/qemu/qemu_dpdk_vhost_user.py
@@ -38,6 +38,14 @@ class QemuDpdkVhostUser(IVnfQemu):
net1 = 'net' + str(i + 1)
net2 = 'net' + str(i + 2)
+ # multi-queue values
+ if int(S.getValue('GUEST_NIC_QUEUES')):
+ queue_str = ',queues={}'.format(S.getValue('GUEST_NIC_QUEUES'))
+ mq_vector_str = ',mq=on,vectors={}'.format(
+ int(S.getValue('GUEST_NIC_QUEUES')) * 2 + 2)
+ else:
+ queue_str, mq_vector_str = '', ''
+
self._cmd += ['-chardev',
'socket,id=char' + if1 +
',path=' + S.getValue('OVS_VAR_DIR') +
@@ -48,19 +56,20 @@ class QemuDpdkVhostUser(IVnfQemu):
'dpdkvhostuser' + if2,
'-netdev',
'type=vhost-user,id=' + net1 +
- ',chardev=char' + if1 + ',vhostforce',
+ ',chardev=char' + if1 + ',vhostforce' + queue_str,
'-device',
'virtio-net-pci,mac=' +
S.getValue('GUEST_NET1_MAC')[self._number] +
',netdev=' + net1 + ',csum=off,gso=off,' +
- 'guest_tso4=off,guest_tso6=off,guest_ecn=off',
+ 'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
+ mq_vector_str,
'-netdev',
'type=vhost-user,id=' + net2 +
- ',chardev=char' + if2 + ',vhostforce',
+ ',chardev=char' + if2 + ',vhostforce' + queue_str,
'-device',
'virtio-net-pci,mac=' +
S.getValue('GUEST_NET2_MAC')[self._number] +
',netdev=' + net2 + ',csum=off,gso=off,' +
- 'guest_tso4=off,guest_tso6=off,guest_ecn=off',
+ 'guest_tso4=off,guest_tso6=off,guest_ecn=off' +
+ mq_vector_str,
]
-
diff --git a/vnfs/qemu/qemu_pci_passthrough.py b/vnfs/qemu/qemu_pci_passthrough.py
new file mode 100644
index 00000000..1b55fdf2
--- /dev/null
+++ b/vnfs/qemu/qemu_pci_passthrough.py
@@ -0,0 +1,87 @@
+# 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 with direct access to host NICs via
+ PCI passthrough.
+"""
+
+import logging
+import subprocess
+import os
+
+from conf import settings as S
+from vnfs.qemu.qemu import IVnfQemu
+from tools import tasks
+from tools.module_manager import ModuleManager
+
+_MODULE_MANAGER = ModuleManager()
+_RTE_PCI_TOOL = os.path.join(S.getValue('RTE_SDK'), 'tools', 'dpdk_nic_bind.py')
+
+class QemuPciPassthrough(IVnfQemu):
+ """
+ Control an instance of QEMU with direct access to the host network devices
+ """
+ def __init__(self):
+ """
+ Initialization function.
+ """
+ super(QemuPciPassthrough, self).__init__()
+ self._logger = logging.getLogger(__name__)
+ self._nics = S.getValue('NICS')
+
+ # in case of SRIOV and PCI passthrough we must ensure, that MAC addresses are swapped
+ if S.getValue('SRIOV_ENABLED') and not self._testpmd_fwd_mode.startswith('mac'):
+ self._logger.info("SRIOV detected, forwarding mode of testpmd was changed from '%s' to '%s'",
+ self._testpmd_fwd_mode, 'mac_retry')
+ self._testpmd_fwd_mode = 'mac_retry'
+
+ for nic in self._nics:
+ self._cmd += ['-device', 'vfio-pci,host=' + nic['pci']]
+
+ def start(self):
+ """
+ Start QEMU instance, bind host NICs to vfio-pci driver
+ """
+ # load vfio-pci
+ _MODULE_MANAGER.insert_modules(['vfio-pci'])
+
+ # bind every interface to vfio-pci driver
+ try:
+ nics_list = list(tmp_nic['pci'] for tmp_nic in self._nics)
+ tasks.run_task(['sudo', _RTE_PCI_TOOL, '--bind=vfio-pci'] + nics_list,
+ self._logger, 'Binding NICs %s...' % nics_list, True)
+
+ except subprocess.CalledProcessError:
+ self._logger.error('Unable to bind NICs %s', self._nics)
+
+ super(QemuPciPassthrough, self).start()
+
+ def stop(self):
+ """
+ Stop QEMU instance, bind host NICs to the original driver
+ """
+ super(QemuPciPassthrough, self).stop()
+
+ # bind original driver to every interface
+ for nic in self._nics:
+ if nic['driver']:
+ try:
+ tasks.run_task(['sudo', _RTE_PCI_TOOL, '--bind=' + nic['driver'], nic['pci']],
+ self._logger, 'Binding NIC %s...' % nic['pci'], True)
+
+ except subprocess.CalledProcessError:
+ self._logger.error('Unable to bind NIC %s to driver %s', nic['pci'], nic['driver'])
+
+ # unload vfio-pci driver
+ _MODULE_MANAGER.remove_modules()