+ startup = f"/etc/vpp/vm_startup_{self._opt.get(u'qemu_id')}.conf"
+ running = f"/etc/vpp/vm_running_{self._opt.get(u'qemu_id')}.exec"
+
+ self._temp[u"startup"] = startup
+ self._temp[u"running"] = running
+ self._opt[u"vnf_bin"] = f"/usr/bin/vpp -c {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(u"0")
+ if self._opt.get(u"smp") > 1:
+ vpp_config.add_cpu_corelist_workers(f"1-{self._opt.get(u'smp')-1}")
+ vpp_config.add_dpdk_dev(u"0000:00:06.0", u"0000:00:07.0")
+ vpp_config.add_dpdk_dev_default_rxq(kwargs[u"queues"])
+ vpp_config.add_dpdk_log_level(u"debug")
+ if not kwargs[u"jumbo_frames"]:
+ vpp_config.add_dpdk_no_multi_seg()
+ vpp_config.add_dpdk_no_tx_checksum_offload()
+ vpp_config.add_plugin(u"disable", [u"default"])
+ vpp_config.add_plugin(u"enable", [u"dpdk_plugin.so"])
+ vpp_config.write_config(startup)
+
+ # Create VPP running configuration.
+ template = f"{Constants.RESOURCES_TPL_VM}/{self._opt.get(u'vnf')}.exec"
+ exec_cmd_no_error(self._node, f"rm -f {running}", sudo=True)
+
+ with open(template, u"rt") as src_file:
+ src = Template(src_file.read())
+ exec_cmd_no_error(
+ self._node, f"echo '{src.safe_substitute(**kwargs)}' | "
+ f"sudo tee {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=f"0-{self._opt.get(u'smp') - 1}",
+ eal_driver=False,
+ eal_in_memory=True,
+ pmd_num_mbufs=16384,
+ pmd_rxq=kwargs[u"queues"],
+ pmd_txq=kwargs[u"queues"],
+ pmd_tx_offloads='0x0',
+ pmd_disable_hw_vlan=False,
+ pmd_nb_cores=str(self._opt.get(u"smp") - 1)
+ )
+
+ self._opt[u"vnf_bin"] = f"{self._testpmd_path}/{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=f"0-{self._opt.get(u'smp') - 1}",
+ eal_driver=False,
+ eal_in_memory=True,
+ pmd_num_mbufs=16384,
+ pmd_fwd_mode=u"mac",
+ pmd_eth_peer_0=f"0,{kwargs[u'vif1_mac']}",
+ pmd_eth_peer_1=f"1,{kwargs[u'vif2_mac']}",
+ pmd_rxq=kwargs[u"queues"],
+ pmd_txq=kwargs[u"queues"],
+ pmd_tx_offloads=u"0x0",
+ pmd_disable_hw_vlan=False,
+ pmd_nb_cores=str(self._opt.get(u"smp") - 1)
+ )
+
+ self._opt[u"vnf_bin"] = f"{self._testpmd_path}/{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 = f"{Constants.RESOURCES_TPL_VM}/init.sh"
+ init = self._temp.get(u"ini")
+ exec_cmd_no_error(self._node, f"rm -f {init}", sudo=True)
+
+ with open(template, u"rt") as src_file:
+ src = Template(src_file.read())
+ exec_cmd_no_error(
+ self._node, f"echo '{src.safe_substitute(**kwargs)}' | "
+ f"sudo tee {init}"
+ )
+ exec_cmd_no_error(self._node, f"chmod +x {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 u"vpp" in self._opt.get(u"vnf"):
+ self.create_kernelvm_config_vpp(**kwargs)
+ elif u"testpmd_io" in self._opt.get(u"vnf"):
+ self.create_kernelvm_config_testpmd_io(**kwargs)
+ elif u"testpmd_mac" in self._opt.get(u"vnf"):
+ self.create_kernelvm_config_testpmd_mac(**kwargs)
+ else:
+ raise RuntimeError(u"QEMU: Unsupported VNF!")
+ self.create_kernelvm_init(vnf_bin=self._opt[u"vnf_bin"])