+ startup = ('/etc/vpp/vm_startup_{id}.conf'.
+ format(id=self._opt.get('qemu_id')))
+ running = ('/etc/vpp/vm_running_{id}.exec'.
+ format(id=self._opt.get('qemu_id')))
+
+ self._temp['startup'] = startup
+ self._temp['running'] = running
+ self._opt['vnf_bin'] = ('/usr/bin/vpp -c {startup}'.
+ format(startup=startup))
+
+ # Create VPP startup configuration.
+ vpp_config = VppConfigGenerator()
+ vpp_config.set_node(self._node)
+ vpp_config.add_unix_nodaemon()
+ vpp_config.add_unix_cli_listen()
+ vpp_config.add_unix_exec(running)
+ vpp_config.add_socksvr()
+ vpp_config.add_cpu_main_core('0')
+ if self._opt.get('smp') > 1:
+ vpp_config.add_cpu_corelist_workers('1-{smp}'.format(
+ smp=self._opt.get('smp')-1))
+ vpp_config.add_dpdk_dev('0000:00:06.0', '0000:00:07.0')
+ vpp_config.add_dpdk_dev_default_rxq(kwargs['queues'])
+ vpp_config.add_dpdk_log_level('debug')
+ 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.write_config(startup)
+
+ # Create VPP running configuration.
+ template = '{res}/{tpl}.exec'.format(res=Constants.RESOURCES_TPL_VM,
+ tpl=self._opt.get('vnf'))
+ exec_cmd_no_error(self._node, 'rm -f {running}'.format(running=running),
+ sudo=True)
+
+ with open(template, 'r') as src_file:
+ src = Template(src_file.read())
+ exec_cmd_no_error(
+ self._node, "echo '{out}' | sudo tee {running}".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_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='0x0',
+ pmd_disable_hw_vlan=False,
+ pmd_nb_cores=str(self._opt.get('smp') - 1))
+
+ self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
+ format(testpmd_path=self._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_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='0x0',
+ pmd_disable_hw_vlan=False,
+ pmd_nb_cores=str(self._opt.get('smp') - 1))
+
+ self._opt['vnf_bin'] = ('{testpmd_path}/{testpmd_cmd}'.
+ format(testpmd_path=self._testpmd_path,
+ testpmd_cmd=testpmd_cmd))
+
+ def create_kernelvm_init(self, **kwargs):
+ """Create QEMU init script.
+
+ :param kwargs: Key-value pairs to replace content of init startup file.
+ :type kwargs: dict
+ """
+ template = '{res}/init.sh'.format(res=Constants.RESOURCES_TPL_VM)
+ init = self._temp.get('ini')
+ exec_cmd_no_error(
+ self._node, 'rm -f {init}'.format(init=init), sudo=True)
+
+ with open(template, 'r') as src_file:
+ src = Template(src_file.read())
+ exec_cmd_no_error(
+ self._node, "echo '{out}' | sudo tee {init}".format(
+ out=src.safe_substitute(**kwargs), init=init))
+ exec_cmd_no_error(
+ self._node, "chmod +x {init}".format(init=init), sudo=True)
+
+ def configure_kernelvm_vnf(self, **kwargs):
+ """Create KernelVM VNF configurations.
+
+ :param kwargs: Key-value pairs for templating configs.
+ :type kwargs: dict
+ """
+ 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['vnf_bin'])