X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FVppConfigGenerator.py;h=0628e8ee4757282324cb5d91c5e9f690d3b12c06;hb=e2c0d2e1481f899ba82a3892694a04a127668b2b;hp=b769b89acd688b494f6cf85b38d321df5d9dc0f4;hpb=d79b753c1fde3cd831f60ac5cc0034f613c44b43;p=csit.git diff --git a/resources/libraries/python/VppConfigGenerator.py b/resources/libraries/python/VppConfigGenerator.py index b769b89acd..0628e8ee47 100644 --- a/resources/libraries/python/VppConfigGenerator.py +++ b/resources/libraries/python/VppConfigGenerator.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Cisco and/or its affiliates. +# Copyright (c) 2023 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -11,12 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -"""VPP Configuration File Generator library. - -TODO: Support initialization with default values, -so that we do not need to have block of 6 "Add Unix" commands -in 7 various places of CSIT code. -""" +"""VPP Configuration File Generator library.""" import re @@ -26,7 +21,7 @@ from resources.libraries.python.topology import NodeType from resources.libraries.python.topology import Topology from resources.libraries.python.VPPUtil import VPPUtil -__all__ = [u"VppConfigGenerator"] +__all__ = ["VppConfigGenerator", "VppInitConfig"] def pci_dev_check(pci_dev): @@ -63,12 +58,8 @@ class VppConfigGenerator: self._vpp_config = u"" # VPP Service name self._vpp_service_name = u"vpp" - # VPP Logfile location - self._vpp_logfile = u"/tmp/vpe.log" # VPP Startup config location self._vpp_startup_conf = u"/etc/vpp/startup.conf" - # VPP Startup config backup location - self._vpp_startup_conf_backup = None def set_node(self, node, node_key=None): """Set DUT node. @@ -86,22 +77,6 @@ class VppConfigGenerator: self._node = node self._node_key = node_key - def set_vpp_logfile(self, logfile): - """Set VPP logfile location. - - :param logfile: VPP logfile location. - :type logfile: str - """ - self._vpp_logfile = logfile - - def set_vpp_startup_conf_backup(self, backup=u"/etc/vpp/startup.backup"): - """Set VPP startup configuration backup. - - :param backup: VPP logfile location. - :type backup: str - """ - self._vpp_startup_conf_backup = backup - def get_config_str(self): """Get dumped startup configuration in VPP config format. @@ -156,15 +131,13 @@ class VppConfigGenerator: if level >= 0: self._vpp_config += f"{level * indent}}}\n" - def add_unix_log(self, value=None): + def add_unix_log(self, value="/var/log/vpp/vpp.log"): """Add UNIX log configuration. :param value: Log file. :type value: str """ path = [u"unix", u"log"] - if value is None: - value = self._vpp_logfile self.add_config_item(self._nodeconfig, value, path) def add_unix_cli_listen(self, value=u"/run/vpp/cli.sock"): @@ -176,6 +149,11 @@ class VppConfigGenerator: path = [u"unix", u"cli-listen"] self.add_config_item(self._nodeconfig, value, path) + def add_unix_cli_no_pager(self): + """Add UNIX cli-no-pager configuration.""" + path = [u"unix", u"cli-no-pager"] + self.add_config_item(self._nodeconfig, u"", path) + def add_unix_gid(self, value=u"vpp"): """Add UNIX gid configuration. @@ -205,6 +183,20 @@ class VppConfigGenerator: path = [u"socksvr", u"socket-name"] self.add_config_item(self._nodeconfig, socket, path) + def add_graph_node_variant(self, variant=Constants.GRAPH_NODE_VARIANT): + """Add default graph node variant. + + :param value: Graph node variant default value. + :type value: str + """ + if variant == u"": + return + variant_list = [u"hsw", u"skx", u"icl"] + if variant not in variant_list: + raise ValueError("Invalid graph node variant value") + path = [u"node", u"default", u"variant"] + self.add_config_item(self._nodeconfig, variant, path) + def add_api_segment_gid(self, value=u"vpp"): """Add API-SEGMENT gid configuration. @@ -261,32 +253,19 @@ class VppConfigGenerator: path = [u"dpdk", f"dev {device}"] self.add_config_item(self._nodeconfig, u"", path) - def add_dpdk_dev_parameter(self, device, parameter, value): - """Add parameter for DPDK device. - - :param device: PCI device (format xxxx:xx:xx.x). - :param parameter: Parameter name. - :param value: Parameter value. - :type device: str - :type parameter: str - :type value: str - """ - if pci_dev_check(device): - path = [u"dpdk", f"dev {device}", parameter] - self.add_config_item(self._nodeconfig, value, path) - def add_dpdk_cryptodev(self, count): """Add DPDK Crypto PCI device configuration. :param count: Number of HW crypto devices to add. :type count: int """ - cryptodev = Topology.get_cryptodev(self._node) - for i in range(count): - cryptodev_config = re.sub(r"\d.\d$", f"1.{str(i)}", cryptodev) - path = [u"dpdk", f"dev {cryptodev_config}"] - self.add_config_item(self._nodeconfig, u"", path) - self.add_dpdk_uio_driver(u"vfio-pci") + cryptodevs = Topology.get_cryptodev(self._node) + for device in cryptodevs.values(): + for i in range(int(count/len(cryptodevs))): + addr = re.sub(r"\d.\d$", f"0.{i+1}", device["pci_address"]) + path = ["dpdk", f"dev {addr}"] + self.add_config_item(self._nodeconfig, "", path) + self.add_dpdk_uio_driver("vfio-pci") def add_dpdk_sw_cryptodev(self, sw_pmd_type, socket_id, count): """Add DPDK SW Crypto device configuration. @@ -304,26 +283,6 @@ class VppConfigGenerator: path = [u"dpdk", cryptodev_config] self.add_config_item(self._nodeconfig, u"", path) - def add_dpdk_eth_bond_dev(self, ethbond_id, mode, xmit_policy, *slaves): - """Add DPDK Eth_bond device configuration. - - :param ethbond_id: Eth_bond device ID. - :param mode: Link bonding mode. - :param xmit_policy: Transmission policy. - :param slaves: PCI device(s) to be bonded (format xxxx:xx:xx.x). - :type ethbond_id: str or int - :type mode: str or int - :type xmit_policy: str - :type slaves: list - """ - slaves_config = u"slave=" + u",slave=".join( - slave if pci_dev_check(slave) else u"" for slave in slaves - ) - ethbond_config = f"vdev eth_bond{ethbond_id}," \ - f"mode={mode}{slaves_config},xmit_policy={xmit_policy}" - path = [u"dpdk", ethbond_config] - self.add_config_item(self._nodeconfig, u"", path) - def add_dpdk_dev_default_rxq(self, value): """Add DPDK dev default rxq configuration. @@ -387,6 +346,22 @@ class VppConfigGenerator: path = [u"dpdk", u"uio-driver"] self.add_config_item(self._nodeconfig, value, path) + def add_dpdk_max_simd_bitwidth(self, variant=Constants.GRAPH_NODE_VARIANT): + """Add DPDK max-simd-bitwidth configuration. + + :param value: Graph node variant default value. + :type value: str + """ + if variant == u"icl": + value = 512 + elif variant in [u"skx", u"hsw"]: + value = 256 + else: + return + + path = [u"dpdk", u"max-simd-bitwidth"] + self.add_config_item(self._nodeconfig, value, path) + def add_cpu_main_core(self, value): """Add CPU main core configuration. @@ -405,13 +380,31 @@ class VppConfigGenerator: path = [u"cpu", u"corelist-workers"] self.add_config_item(self._nodeconfig, value, path) - def add_heapsize(self, value): - """Add Heapsize configuration. + def add_main_heap_size(self, value): + """Add Main Heap Size configuration. + + :param value: Amount of heap. + :type value: str + """ + path = [u"memory", u"main-heap-size"] + self.add_config_item(self._nodeconfig, value, path) + + def add_main_heap_page_size(self, value): + """Add Main Heap Page Size configuration. + + :param value: Heap page size. + :type value: str + """ + path = [u"memory", u"main-heap-page-size"] + self.add_config_item(self._nodeconfig, value, path) + + def add_default_hugepage_size(self, value=Constants.DEFAULT_HUGEPAGE_SIZE): + """Add Default Hugepage Size configuration. - :param value: Amount of heapsize. + :param value: Hugepage size. :type value: str """ - path = [u"heapsize"] + path = [u"memory", u"default-hugepage-size"] self.add_config_item(self._nodeconfig, value, path) def add_api_trace(self): @@ -437,17 +430,53 @@ class VppConfigGenerator: path = [u"ip6", u"heap-size"] self.add_config_item(self._nodeconfig, value, path) - def add_ip_heap_size(self, value): - """Add IP heap-size configuration. + def add_ipsec_spd_flow_cache_ipv4_inbound(self, value): + """Add IPsec spd flow cache for IP4 inbound. - :param value: IP Heapsize amount. + :param value: "on" to enable spd flow cache. :type value: str """ - path = [u"ip", u"heap-size"] + path = [u"ipsec", u"ipv4-inbound-spd-flow-cache"] + self.add_config_item(self._nodeconfig, value, path) + + def add_ipsec_spd_flow_cache_ipv4_outbound(self, value): + """Add IPsec spd flow cache for IP4 outbound. + + :param value: "on" to enable spd flow cache. + :type value: str + """ + path = [u"ipsec", u"ipv4-outbound-spd-flow-cache"] + self.add_config_item(self._nodeconfig, value, path) + + def add_ipsec_spd_fast_path_ipv4_inbound(self, value): + """Add IPsec spd fast path for IP4 inbound. + + :param value: "on" to enable spd fast path. + :type value: str + """ + path = [u"ipsec", u"ipv4-inbound-spd-fast-path"] + self.add_config_item(self._nodeconfig, value, path) + + def add_ipsec_spd_fast_path_ipv4_outbound(self, value): + """Add IPsec spd fast path for IP4 outbound. + + :param value: "on" to enable spd fast path. + :type value: str + """ + path = [u"ipsec", u"ipv4-outbound-spd-fast-path"] + self.add_config_item(self._nodeconfig, value, path) + + def add_ipsec_spd_fast_path_num_buckets(self, value): + """Add num buckets for IPsec spd fast path. + + :param value: Number of buckets. + :type value: int + """ + path = [u"ipsec", u"spd-fast-path-num-buckets"] self.add_config_item(self._nodeconfig, value, path) def add_statseg_size(self, value): - """Add stats segment heap size configuration. + """Add Stats Heap Size configuration. :param value: Stats heapsize amount. :type value: str @@ -455,6 +484,15 @@ class VppConfigGenerator: path = [u"statseg", u"size"] self.add_config_item(self._nodeconfig, value, path) + def add_statseg_page_size(self, value): + """Add Stats Heap Page Size configuration. + + :param value: Stats heapsize amount. + :type value: str + """ + path = [u"statseg", u"page-size"] + self.add_config_item(self._nodeconfig, value, path) + def add_statseg_per_node_counters(self, value): """Add stats per-node-counters configuration. @@ -487,12 +525,21 @@ class VppConfigGenerator: self.add_config_item(self._nodeconfig, u"", path) def add_nat(self, value=u"deterministic"): - """Add NAT configuration. + """Add NAT mode configuration. + + :param value: NAT mode. + :type value: str + """ + path = [u"nat", value] + self.add_config_item(self._nodeconfig, u"", path) + + def add_nat_max_translations_per_thread(self, value): + """Add NAT max. translations per thread number configuration. :param value: NAT mode. :type value: str """ - path = [u"nat"] + path = [u"nat", u"max translations per thread"] self.add_config_item(self._nodeconfig, value, path) def add_nsim_poll_main_thread(self): @@ -532,6 +579,11 @@ class VppConfigGenerator: path = [u"session", u"enable"] self.add_config_item(self._nodeconfig, u"", path) + def add_session_app_socket_api(self): + """Use session app socket api.""" + path = [u"session", u"use-app-socket-api"] + self.add_config_item(self._nodeconfig, u"", path) + def add_session_event_queues_memfd_segment(self): """Add session event queue memfd segment.""" path = [u"session", u"evt_qs_memfd_seg"] @@ -632,12 +684,6 @@ class VppConfigGenerator: if filename is None: filename = self._vpp_startup_conf - if self._vpp_startup_conf_backup is not None: - cmd = f"cp {self._vpp_startup_conf} {self._vpp_startup_conf_backup}" - exec_cmd_no_error( - self._node, cmd, sudo=True, message=u"Copy config file failed!" - ) - cmd = f"echo \"{self._vpp_config}\" | sudo tee {filename}" exec_cmd_no_error( self._node, cmd, message=u"Writing config file failed!" @@ -660,9 +706,39 @@ class VppConfigGenerator: if verify_vpp: VPPUtil.verify_vpp(self._node) - def restore_config(self): - """Restore VPP startup.conf from backup.""" - cmd = f"cp {self._vpp_startup_conf_backup} {self._vpp_startup_conf}" - exec_cmd_no_error( - self._node, cmd, sudo=True, message=u"Copy config file failed!" - ) + +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[u"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[u"interfaces"]] + ) + vpp_config.add_ip6_hash_buckets(2000000) + vpp_config.add_ip6_heap_size("4G") + vpp_config.apply_config()