from robot.api import logger
from resources.libraries.python.ssh import exec_cmd, exec_cmd_no_error
from resources.libraries.python.Constants import Constants
+from resources.libraries.python.DpdkUtil import DpdkUtil
from resources.libraries.python.DUTSetup import DUTSetup
from resources.libraries.python.topology import NodeType, Topology
from resources.libraries.python.VppConfigGenerator import VppConfigGenerator
# Use one instance of class per tests.
ROBOT_LIBRARY_SCOPE = 'TEST CASE'
- def __init__(self, node=None, qemu_id=1, smp=1, mem=512, vnf=None,
- img='/var/lib/vm/vhost-nested.img', bin_path='/usr/bin'):
+ def __init__(self, node, qemu_id=1, smp=1, mem=512, vnf=None,
+ img=Constants.QEMU_VM_IMAGE):
"""Initialize QemuUtil class.
:param node: Node to run QEMU on.
:param mem: Amount of memory.
:param vnf: Network function workload.
:param img: QEMU disk image or kernel image path.
- :param bin_path: QEMU binary path.
:type node: dict
:type qemu_id: int
:type smp: int
:type mem: int
:type vnf: str
:type img: str
- :type bin_path: str
"""
self._vhost_id = 0
self._node = node
# Input Options.
self._opt = dict()
self._opt['qemu_id'] = qemu_id
- self._opt['bin_path'] = bin_path
self._opt['mem'] = int(mem)
self._opt['smp'] = int(smp)
self._opt['img'] = img
format(smp=self._opt.get('smp')-1))
vpp_config.add_dpdk_dev('0000:00:06.0', '0000:00:07.0')
vpp_config.add_dpdk_log_level('debug')
- vpp_config.add_dpdk_no_tx_checksum_offload()
- vpp_config.add_dpdk_no_multi_seg()
+ if not kwargs['jumbo_frames']:
+ vpp_config.add_dpdk_no_multi_seg()
+ vpp_config.add_dpdk_no_tx_checksum_offload()
vpp_config.add_plugin('disable', 'default')
vpp_config.add_plugin('enable', 'dpdk_plugin.so')
vpp_config.apply_config(startup, restart_vpp=False)
format(out=src.safe_substitute(**kwargs),
running=running))
+ def create_kernelvm_config_testpmd_io(self, **kwargs):
+ """Create QEMU testpmd-io command line.
+
+ :param kwargs: Key-value pairs to construct command line parameters.
+ :type kwargs: dict
+ """
+ testpmd_path = ('{path}/{arch}-native-linuxapp-gcc/app'.
+ format(path=Constants.QEMU_VM_DPDK,
+ arch=Topology.get_node_arch(self._node)))
+ testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
+ eal_corelist='0-{smp}'.format(smp=self._opt.get('smp') - 1),
+ eal_driver=False,
+ eal_in_memory=True,
+ pmd_num_mbufs=16384,
+ pmd_rxq=kwargs['queues'],
+ pmd_txq=kwargs['queues'],
+ pmd_tx_offloads=False,
+ pmd_disable_hw_vlan=False,
+ pmd_max_pkt_len=9200 if kwargs['jumbo_frames'] else None,
+ pmd_nb_cores=str(self._opt.get('smp') - 1))
+
+ self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
+ format(testpmd_path=testpmd_path,
+ testpmd_cmd=testpmd_cmd))
+
+ def create_kernelvm_config_testpmd_mac(self, **kwargs):
+ """Create QEMU testpmd-mac command line.
+
+ :param kwargs: Key-value pairs to construct command line parameters.
+ :type kwargs: dict
+ """
+ testpmd_path = ('{path}/{arch}-native-linuxapp-gcc/app'.
+ format(path=Constants.QEMU_VM_DPDK,
+ arch=Topology.get_node_arch(self._node)))
+ testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
+ eal_corelist='0-{smp}'.format(smp=self._opt.get('smp') - 1),
+ eal_driver=False,
+ eal_in_memory=True,
+ pmd_num_mbufs=16384,
+ pmd_fwd_mode='mac',
+ pmd_eth_peer_0='0,{mac}'.format(mac=kwargs['vif1_mac']),
+ pmd_eth_peer_1='1,{mac}'.format(mac=kwargs['vif2_mac']),
+ pmd_rxq=kwargs['queues'],
+ pmd_txq=kwargs['queues'],
+ pmd_tx_offloads=False,
+ pmd_disable_hw_vlan=False,
+ pmd_max_pkt_len=9200 if kwargs['jumbo_frames'] else None,
+ pmd_nb_cores=str(self._opt.get('smp') - 1))
+
+ self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
+ format(testpmd_path=testpmd_path,
+ testpmd_cmd=testpmd_cmd))
+
def create_kernelvm_init(self, **kwargs):
"""Create QEMU init script.
"""
if 'vpp' in self._opt.get('vnf'):
self.create_kernelvm_config_vpp(**kwargs)
+ elif 'testpmd_io' in self._opt.get('vnf'):
+ self.create_kernelvm_config_testpmd_io(**kwargs)
+ elif 'testpmd_mac' in self._opt.get('vnf'):
+ self.create_kernelvm_config_testpmd_mac(**kwargs)
else:
raise RuntimeError('QEMU: Unsupported VNF!')
self.create_kernelvm_init(vnf_bin=self._opt.get('vnf_bin'))
"""
command = ("grep -rwl 'CPU' /proc/$(sudo cat {pidfile})/task/*/comm ".
format(pidfile=self._temp.get('pidfile')))
- command += (r"| xargs dirname | sed -e 's/\/.*\///g'")
+ command += (r"| xargs dirname | sed -e 's/\/.*\///g' | uniq")
stdout, _ = exec_cmd_no_error(self._node, command)
return stdout.splitlines()
:param retries: Number of retries.
:type retries: int
"""
+ vpp_ver = VPPUtil.vpp_show_version(self._node)
+
for _ in range(retries):
command = ('tail -1 {log}'.format(log=self._temp.get('log')))
stdout = None
sleep(1)
except RuntimeError:
pass
- if VPPUtil.vpp_show_version(self._node) in stdout:
+ if vpp_ver in stdout or 'Press enter to exit' in stdout:
break
+ if 'reboot: Power down' in stdout:
+ raise RuntimeError('QEMU: NF failed to run on {host}!'.
+ format(host=self._node['host']))
else:
raise RuntimeError('QEMU: Timeout, VM not booted on {host}!'.
format(host=self._node['host']))
:rtype: dict
"""
command = ('{bin_path}/qemu-system-{arch} {params}'.
- format(bin_path=self._opt.get('bin_path'),
+ format(bin_path=Constants.QEMU_BIN_PATH,
arch=Topology.get_node_arch(self._node),
params=self._params))
message = ('QEMU: Start failed on {host}!'.
format(pidfile=self._temp.get('pidfile')), sudo=True)
for value in self._temp.values():
+ exec_cmd(self._node, 'cat {value}'.format(value=value), sudo=True)
exec_cmd(self._node, 'rm -f {value}'.format(value=value), sudo=True)
def qemu_kill_all(self):
exec_cmd(self._node, 'pkill -SIGKILL qemu', sudo=True)
for value in self._temp.values():
+ exec_cmd(self._node, 'cat {value}'.format(value=value), sudo=True)
exec_cmd(self._node, 'rm -f {value}'.format(value=value), sudo=True)
def qemu_version(self, version=None):
:rtype: str or bool
"""
command = ('{bin_path}/qemu-system-{arch} --version'.
- format(bin_path=self._opt.get('bin_path'),
+ format(bin_path=Constants.QEMU_BIN_PATH,
arch=Topology.get_node_arch(self._node)))
try:
stdout, _ = exec_cmd_no_error(self._node, command, sudo=True)
except RuntimeError:
self.qemu_kill_all()
raise
-
- @staticmethod
- def build_qemu(node, force_install=False, apply_patch=False):
- """Build QEMU from sources.
-
- :param node: Node to build QEMU on.
- :param force_install: If True, then remove previous build.
- :param apply_patch: If True, then apply patches from qemu_patches dir.
- :type node: dict
- :type force_install: bool
- :type apply_patch: bool
- :raises RuntimeError: If building QEMU failed.
- """
- directory = (' --directory={install_dir}{patch}'.
- format(install_dir=Constants.QEMU_INSTALL_DIR,
- patch='-patch' if apply_patch else '-base'))
- version = (' --version={install_version}'.
- format(install_version=Constants.QEMU_INSTALL_VERSION))
- force = ' --force' if force_install else ''
- patch = ' --patch' if apply_patch else ''
- target_list = (' --target-list={arch}-softmmu'.
- format(arch=Topology.get_node_arch(node)))
-
- command = ("sudo -E sh -c "
- "'{fw_dir}/{lib_sh}/qemu_build.sh{version}{directory}"
- "{force}{patch}{target_list}'".
- format(fw_dir=Constants.REMOTE_FW_DIR,
- lib_sh=Constants.RESOURCES_LIB_SH,
- version=version, directory=directory, force=force,
- patch=patch, target_list=target_list))
- message = ('QEMU: Build failed on {host}!'.format(host=node['host']))
- exec_cmd_no_error(node, command, sudo=False, message=message,
- timeout=1000)