X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FQemuUtils.py;h=c215dfd96faf1f9c766d119bb8b14f486330b23e;hb=a5a51a112a0d3475f2368a18b6b42f7712ec5b25;hp=a1482752f14a8a4b87a990debe67f4fe7588bf18;hpb=42d1016e92cf2b8ba4e493d878c475de325a447a;p=csit.git diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py index a1482752f1..c215dfd96f 100644 --- a/resources/libraries/python/QemuUtils.py +++ b/resources/libraries/python/QemuUtils.py @@ -27,6 +27,8 @@ from resources.libraries.python.DUTSetup import DUTSetup from resources.libraries.python.OptionString import OptionString from resources.libraries.python.ssh import exec_cmd, exec_cmd_no_error from resources.libraries.python.topology import NodeType, Topology +from resources.libraries.python.VhostUser import VirtioFeaturesFlags +from resources.libraries.python.VhostUser import VirtioFeatureMask from resources.libraries.python.VppConfigGenerator import VppConfigGenerator __all__ = [u"QemuUtils"] @@ -56,7 +58,7 @@ class QemuUtils: :type vnf: str :type img: str """ - self._vhost_id = 0 + self._nic_id = 0 self._node = node self._arch = Topology.get_node_arch(self._node) self._opt = dict() @@ -213,13 +215,13 @@ class QemuUtils: self._params.add_with_value( u"append", f"'ro rootfstype=9p rootflags=trans=virtio " f"root=virtioroot console={self._opt.get(u'console')} " - f"tsc=reliable hugepages=256 " + f"tsc=reliable hugepages=512 " f"init={self._temp.get(u'ini')} fastboot'" ) def add_vhost_user_if( self, socket, server=True, jumbo_frames=False, queue_size=None, - queues=1, csum=False, gso=False): + queues=1, virtio_feature_mask=None): """Add Vhost-user interface. :param socket: Path of the unix socket. @@ -227,32 +229,38 @@ class QemuUtils: :param jumbo_frames: Set True if jumbo frames are used in the test. :param queue_size: Vring queue size. :param queues: Number of queues. - :param csum: Checksum offloading. - :param gso: Generic segmentation offloading. + :param virtio_feature_mask: Mask of virtio features to be enabled. :type socket: str :type server: bool :type jumbo_frames: bool :type queue_size: int :type queues: int - :type csum: bool - :type gso: bool + :type virtio_feature_mask: int """ - self._vhost_id += 1 + self._nic_id += 1 self._params.add_with_value( - u"chardev", f"socket,id=char{self._vhost_id}," + u"chardev", f"socket,id=char{self._nic_id}," f"path={socket}{u',server' if server is True else u''}" ) self._params.add_with_value( - u"netdev", f"vhost-user,id=vhost{self._vhost_id}," - f"chardev=char{self._vhost_id},queues={queues}" + u"netdev", f"vhost-user,id=vhost{self._nic_id}," + f"chardev=char{self._nic_id},queues={queues}" ) mac = f"52:54:00:00:{self._opt.get(u'qemu_id'):02x}:" \ - f"{self._vhost_id:02x}" + f"{self._nic_id:02x}" queue_size = f"rx_queue_size={queue_size},tx_queue_size={queue_size}" \ if queue_size else u"" + if virtio_feature_mask is None: + gso = False + csum = False + else: + gso = VirtioFeatureMask.is_feature_enabled( + virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_GSO) + csum = VirtioFeatureMask.is_feature_enabled( + virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_CSUM) self._params.add_with_value( - u"device", f"virtio-net-pci,netdev=vhost{self._vhost_id},mac={mac}," - f"addr={self._vhost_id+5}.0,mq=on,vectors={2 * queues + 2}," + u"device", f"virtio-net-pci,netdev=vhost{self._nic_id},mac={mac}," + f"addr={self._nic_id+5}.0,mq=on,vectors={2 * queues + 2}," f"csum={u'on' if csum else u'off'},gso={u'on' if gso else u'off'}," f"guest_tso4=off,guest_tso6=off,guest_ecn=off," f"{queue_size}" @@ -260,7 +268,7 @@ class QemuUtils: # Add interface MAC and socket to the node dict. if_data = {u"mac_address": mac, u"socket": socket} - if_name = f"vhost{self._vhost_id}" + if_name = f"vhost{self._nic_id}" self._vm_info[u"interfaces"][if_name] = if_data # Add socket to temporary file list. self._temp[if_name] = socket @@ -271,7 +279,10 @@ class QemuUtils: :param pci: PCI address of interface. :type pci: str """ - self._params.add_with_value(u"device", f"vfio-pci,host={pci}") + self._nic_id += 1 + self._params.add_with_value( + u"device", f"vfio-pci,host={pci},addr={self._nic_id+5}.0" + ) def create_kernelvm_config_vpp(self, **kwargs): """Create QEMU VPP config files. @@ -294,11 +305,12 @@ class QemuUtils: vpp_config.add_unix_cli_listen() vpp_config.add_unix_exec(running) vpp_config.add_socksvr() - vpp_config.add_statseg_per_node_counters(value=u"on") + 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_heapsize(u"1G") - vpp_config.add_ip_heap_size(u"1G") - vpp_config.add_statseg_size(u"1G") 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}") @@ -320,12 +332,11 @@ class QemuUtils: 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_nat_max_translations_per_thread(value=655360) 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" + 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: @@ -397,7 +408,7 @@ class QemuUtils: :param kwargs: Key-value pairs to replace content of init startup file. :type kwargs: dict """ - template = f"{Constants.RESOURCES_TPL_VM}/init.sh" + 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)