+ 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_main_heap_size(u"512M")
+ vpp_config.add_main_heap_page_size(u"2M")
+ vpp_config.add_statseg_size(u"512M")
+ vpp_config.add_statseg_page_size(u"2M")
+ vpp_config.add_statseg_per_node_counters(u"on")
+ vpp_config.add_buffers_per_numa(107520)
+ 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_plugin(u"disable", u"default")
+ vpp_config.add_plugin(u"enable", u"ping_plugin.so")
+ if "2vfpt" in self._opt.get(u'vnf'):
+ vpp_config.add_plugin(u"enable", u"avf_plugin.so")
+ if "vhost" in self._opt.get(u'vnf'):
+ vpp_config.add_plugin(u"enable", u"dpdk_plugin.so")
+ 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()
+ if "ipsec" in self._opt.get(u'vnf'):
+ vpp_config.add_plugin(u"enable", u"crypto_native_plugin.so")
+ vpp_config.add_plugin(u"enable", u"crypto_ipsecmb_plugin.so")
+ vpp_config.add_plugin(u"enable", u"crypto_openssl_plugin.so")
+ if "nat" in self._opt.get(u'vnf'):
+ vpp_config.add_nat(value=u"endpoint-dependent")
+ vpp_config.add_plugin(u"enable", u"nat_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
+ """
+ pmd_max_pkt_len = u"9200" if kwargs[u"jumbo_frames"] else u"1518"
+ testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
+ eal_corelist=f"0-{self._opt.get(u'smp') - 1}",
+ eal_driver=False,
+ eal_pci_whitelist0=u"0000:00:06.0",
+ eal_pci_whitelist1=u"0000:00:07.0",
+ eal_in_memory=True,
+ pmd_num_mbufs=32768,
+ pmd_fwd_mode=u"io",
+ pmd_nb_ports=u"2",
+ pmd_portmask=u"0x3",
+ pmd_max_pkt_len=pmd_max_pkt_len,
+ pmd_mbuf_size=u"16384",
+ pmd_rxq=kwargs[u"queues"],
+ pmd_txq=kwargs[u"queues"],
+ pmd_tx_offloads='0x0',
+ 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
+ """
+ pmd_max_pkt_len = u"9200" if kwargs[u"jumbo_frames"] else u"1518"
+ testpmd_cmd = DpdkUtil.get_testpmd_cmdline(
+ eal_corelist=f"0-{self._opt.get(u'smp') - 1}",
+ eal_driver=False,
+ eal_pci_whitelist0=u"0000:00:06.0",
+ eal_pci_whitelist1=u"0000:00:07.0",
+ eal_in_memory=True,
+ pmd_num_mbufs=32768,
+ pmd_fwd_mode=u"mac",
+ pmd_nb_ports=u"2",
+ pmd_portmask=u"0x3",
+ pmd_max_pkt_len=pmd_max_pkt_len,
+ pmd_mbuf_size=u"16384",
+ 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_nb_cores=str(self._opt.get(u"smp") - 1)
+ )
+
+ self._opt[u"vnf_bin"] = f"{self._testpmd_path}/{testpmd_cmd}"
+
+ def create_kernelvm_config_iperf3(self):
+ """Create QEMU iperf3 command line."""
+ self._opt[u"vnf_bin"] = f"mkdir /run/sshd; /usr/sbin/sshd -D -d"
+
+ 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
+ """
+ init = self._temp.get(u"ini")
+ exec_cmd_no_error(self._node, f"rm -f {init}", sudo=True)
+
+ with open(kwargs[u"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)
+ self.create_kernelvm_init(
+ template=f"{Constants.RESOURCES_TPL}/vm/init.sh",
+ vnf_bin=self._opt.get(u"vnf_bin")
+ )
+ elif u"testpmd_io" in self._opt.get(u"vnf"):
+ self.create_kernelvm_config_testpmd_io(**kwargs)
+ self.create_kernelvm_init(
+ template=f"{Constants.RESOURCES_TPL}/vm/init.sh",
+ vnf_bin=self._opt.get(u"vnf_bin")
+ )
+ elif u"testpmd_mac" in self._opt.get(u"vnf"):
+ self.create_kernelvm_config_testpmd_mac(**kwargs)
+ self.create_kernelvm_init(
+ template=f"{Constants.RESOURCES_TPL}/vm/init.sh",
+ vnf_bin=self._opt.get(u"vnf_bin")
+ )
+ elif u"iperf3" in self._opt.get(u"vnf"):
+ qemu_id = self._opt.get(u'qemu_id') % 2
+ self.create_kernelvm_config_iperf3()
+ self.create_kernelvm_init(
+ template=f"{Constants.RESOURCES_TPL}/vm/init_iperf3.sh",
+ vnf_bin=self._opt.get(u"vnf_bin"),
+ ip_address_l=u"2.2.2.2/30" if qemu_id else u"1.1.1.1/30",
+ ip_address_r=u"2.2.2.1" if qemu_id else u"1.1.1.2",
+ ip_route_r=u"1.1.1.0/30" if qemu_id else u"2.2.2.0/30"
+ )
+ else:
+ raise RuntimeError(u"QEMU: Unsupported VNF!")