- if self._vpp_startup_conf_backup is not None:
- ret, _, _ = \
- ssh.exec_command('sudo cp {src} {dest}'.
- format(src=self._vpp_startup_conf,
- dest=self._vpp_startup_conf_backup))
- if ret != 0:
- raise RuntimeError('Backup of config file failed on node '
- '{name}'.format(name=self._hostname))
-
- ret, _, _ = \
- ssh.exec_command('echo "{config}" | sudo tee {filename}'.
- format(config=self._vpp_config,
- filename=filename))
-
- if ret != 0:
- raise RuntimeError('Writing config file failed to node {name}'.
- format(name=self._hostname))
-
- if restart_vpp:
- DUTSetup.start_service(self._node, Constants.VPP_UNIT)
-
- # Sleep <waittime> seconds, up to <retry> times,
- # and verify if VPP is running.
- for _ in range(retries):
- time.sleep(1)
- ret, stdout, _ = \
- ssh.exec_command_sudo('vppctl show pci')
- if ret == 0 and 'Connection refused' not in stdout:
- break
- else:
- raise RuntimeError('VPP failed to restart on node {name}'.
- format(name=self._hostname))
-
- def restore_config(self):
- """Restore VPP startup.conf from backup.
-
- :raises RuntimeError: When restoration of startup.conf file failed.
- """
-
- ssh = SSH()
- ssh.connect(self._node)
-
- ret, _, _ = ssh.exec_command('sudo cp {src} {dest}'.
- format(src=self._vpp_startup_conf_backup,
- dest=self._vpp_startup_conf))
- if ret != 0:
- raise RuntimeError('Restoration of config file failed on node '
- '{name}'.format(name=self._hostname))
+ cmd = f"echo \"{self._vpp_config}\" | sudo tee {filename}"
+ exec_cmd_no_error(
+ self._node, cmd, message="Writing config file failed!"
+ )
+
+ def apply_config(self, filename=None, verify_vpp=True):
+ """Generate and write VPP startup configuration to file and restart VPP.
+
+ Use data from calls to this class to form a startup.conf file and
+ replace /etc/vpp/startup.conf with it on topology node.
+
+ :param filename: Startup configuration file name.
+ :param verify_vpp: Verify VPP is running after restart.
+ :type filename: str
+ :type verify_vpp: bool
+ """
+ self.write_config(filename=filename)
+
+ VPPUtil.restart_vpp_service(self._node, self._node_key)
+ if verify_vpp:
+ VPPUtil.verify_vpp(self._node)
+
+
+class VppInitConfig:
+ """VPP Initial Configuration."""
+ @staticmethod
+ def init_vpp_startup_configuration_on_all_duts(nodes):
+ """Apply initial VPP startup configuration on all DUTs.
+
+ :param nodes: Nodes in the topology.
+ :type nodes: dict
+ """
+ huge_size = Constants.DEFAULT_HUGEPAGE_SIZE
+ for node in nodes.values():
+ if node["type"] == NodeType.DUT:
+ vpp_config = VppConfigGenerator()
+ vpp_config.set_node(node)
+ vpp_config.add_unix_log()
+ vpp_config.add_unix_cli_listen()
+ vpp_config.add_unix_cli_no_pager()
+ vpp_config.add_unix_gid()
+ vpp_config.add_unix_coredump()
+ vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH)
+ vpp_config.add_main_heap_size("2G")
+ vpp_config.add_main_heap_page_size(huge_size)
+ vpp_config.add_default_hugepage_size(huge_size)
+ vpp_config.add_statseg_size("2G")
+ vpp_config.add_statseg_page_size(huge_size)
+ vpp_config.add_statseg_per_node_counters("on")
+ vpp_config.add_plugin("disable", "default")
+ vpp_config.add_plugin("enable", "dpdk_plugin.so")
+ vpp_config.add_dpdk_dev(
+ *[node["interfaces"][interface].get("pci_address") \
+ for interface in node["interfaces"]]
+ )
+ vpp_config.add_ip6_hash_buckets(2000000)
+ vpp_config.add_ip6_heap_size("4G")
+ vpp_config.apply_config()
+
+ @staticmethod
+ def create_vpp_startup_configuration_container(node, cpuset_cpus=None):
+ """Create base startup configuration of VPP on container.
+
+ :param node: Node in the topology.
+ :param cpuset_cpus: List of CPU cores to allocate.
+ :type node: dict
+ :type cpuset_cpus: list.
+ :returns: Base VPP startup configuration for container.
+ :rtype: VppConfigGenerator
+ """
+ huge_size = Constants.DEFAULT_HUGEPAGE_SIZE
+
+ vpp_config = VppConfigGenerator()
+ vpp_config.set_node(node)
+ vpp_config.add_unix_log()
+ vpp_config.add_unix_cli_listen()
+ vpp_config.add_unix_cli_no_pager()
+ vpp_config.add_unix_exec("/tmp/running.exec")
+ vpp_config.add_socksvr(socket=Constants.SOCKSVR_PATH)
+ if cpuset_cpus:
+ # We will pop the first core from the list to be a main core
+ vpp_config.add_cpu_main_core(str(cpuset_cpus.pop(0)))
+ # If more cores in the list, the rest will be used as workers.
+ corelist_workers = ",".join(str(cpu) for cpu in cpuset_cpus)
+ vpp_config.add_cpu_corelist_workers(corelist_workers)
+ vpp_config.add_buffers_per_numa(215040)
+ vpp_config.add_plugin("disable", "default")
+ vpp_config.add_plugin("enable", "memif_plugin.so")
+ vpp_config.add_plugin("enable", "perfmon_plugin.so")
+ vpp_config.add_main_heap_size("2G")
+ vpp_config.add_main_heap_page_size(huge_size)
+ vpp_config.add_default_hugepage_size(huge_size)
+ vpp_config.add_statseg_size("2G")
+ vpp_config.add_statseg_page_size(huge_size)
+ vpp_config.add_statseg_per_node_counters("on")
+ vpp_config.add_ip6_hash_buckets(2000000)
+ vpp_config.add_ip6_heap_size("4G")
+
+ return vpp_config