+ 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_cpu_main_core('0')
+ 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_log_level('debug')
+ vpp_config.add_dpdk_no_tx_checksum_offload()
+ vpp_config.add_dpdk_no_multi_seg()
+ vpp_config.add_plugin('disable', 'default')
+ vpp_config.add_plugin('enable', 'dpdk_plugin.so')
+ vpp_config.apply_config(startup, restart_vpp=False)
+
+ # 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_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)
+ else:
+ raise RuntimeError('QEMU: Unsupported VNF!')
+ self.create_kernelvm_init(vnf_bin=self._opt.get('vnf_bin'))