aboutsummaryrefslogtreecommitdiffstats
path: root/resources/libraries/python
diff options
context:
space:
mode:
authorMartin Balaz <martin.balaz@pantheon.tech>2020-08-03 11:14:49 +0200
committerPeter Mikus <pmikus@cisco.com>2020-10-29 08:06:19 +0000
commit1be82a8542da6764f4ec8562cbcece0c65c8173a (patch)
tree1f6e39befd81c37bbb7a2caa882b0606008a4b93 /resources/libraries/python
parentb9aabb97bb10297ce004f731b7b61b9dc9c83ee6 (diff)
tests: Add GSO enabled tests
Change-Id: I409b060f64ae7c6787448ae519fd76d8384e9ffb Signed-off-by: Martin Balaz <martin.balaz@pantheon.tech>
Diffstat (limited to 'resources/libraries/python')
-rw-r--r--resources/libraries/python/QemuManager.py8
-rw-r--r--resources/libraries/python/QemuUtils.py18
-rw-r--r--resources/libraries/python/VhostUser.py74
3 files changed, 87 insertions, 13 deletions
diff --git a/resources/libraries/python/QemuManager.py b/resources/libraries/python/QemuManager.py
index 547250e283..6436f69aec 100644
--- a/resources/libraries/python/QemuManager.py
+++ b/resources/libraries/python/QemuManager.py
@@ -144,6 +144,8 @@ class QemuManager:
"""
qemu_id = kwargs[u"qemu_id"]
name = kwargs[u"name"]
+ virtio_feature_mask = kwargs[u"virtio_feature_mask"] \
+ if u"virtio_feature_mask" in kwargs else None
self.machines[name] = QemuUtils(
node=self.nodes[kwargs[u"node"]],
@@ -168,16 +170,14 @@ class QemuManager:
jumbo_frames=kwargs[u"jumbo"],
queues=kwargs[u"queues"],
queue_size=kwargs[u"perf_qemu_qsz"],
- csum=kwargs[u"enable_csum"],
- gso=kwargs[u"enable_gso"]
+ virtio_feature_mask=virtio_feature_mask
)
self.machines[name].add_vhost_user_if(
f"/run/vpp/sock-{qemu_id}-2",
jumbo_frames=kwargs[u"jumbo"],
queues=kwargs[u"queues"],
queue_size=kwargs[u"perf_qemu_qsz"],
- csum=kwargs[u"enable_csum"],
- gso=kwargs[u"enable_gso"]
+ virtio_feature_mask=virtio_feature_mask
)
def _c_vpp_2vfpt_ip4base_plen24(self, **kwargs):
diff --git a/resources/libraries/python/QemuUtils.py b/resources/libraries/python/QemuUtils.py
index 7491c71021..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"]
@@ -219,7 +221,7 @@ class QemuUtils:
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,15 +229,13 @@ 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._nic_id += 1
self._params.add_with_value(
@@ -250,6 +250,14 @@ class QemuUtils:
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._nic_id},mac={mac},"
f"addr={self._nic_id+5}.0,mq=on,vectors={2 * queues + 2},"
diff --git a/resources/libraries/python/VhostUser.py b/resources/libraries/python/VhostUser.py
index cc9685d74d..22528b2b7f 100644
--- a/resources/libraries/python/VhostUser.py
+++ b/resources/libraries/python/VhostUser.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2019 Cisco and/or its affiliates.
+# Copyright (c) 2020 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:
@@ -13,6 +13,8 @@
"""Vhost-user interfaces library."""
+from enum import IntEnum
+
from robot.api import logger
from resources.libraries.python.PapiExecutor import PapiSocketExecutor
@@ -20,28 +22,53 @@ from resources.libraries.python.topology import NodeType, Topology
from resources.libraries.python.InterfaceUtil import InterfaceUtil
+class VirtioFeaturesFlags(IntEnum):
+ """Virtio Features Flags."""
+ VIRTIO_NET_F_API_CSUM = 0
+ VIRTIO_NET_F_API_GUEST_CSUM = 1
+ VIRTIO_NET_F_API_GSO = 6
+ VIRTIO_NET_F_API_GUEST_TSO4 = 7
+ VIRTIO_NET_F_API_GUEST_TSO6 = 8
+ VIRTIO_NET_F_API_GUEST_UFO = 10
+ VIRTIO_NET_F_API_HOST_TSO4 = 11
+ VIRTIO_NET_F_API_HOST_TSO6 = 12
+ VIRTIO_NET_F_API_HOST_UFO = 14
+ VIRTIO_NET_F_API_MRG_RXBUF = 15
+ VIRTIO_NET_F_API_CTRL_VQ = 17
+ VIRTIO_NET_F_API_GUEST_ANNOUNCE = 21
+ VIRTIO_NET_F_API_MQ = 22
+ VIRTIO_F_API_ANY_LAYOUT = 27
+ VIRTIO_F_API_INDIRECT_DESC = 28
+
+
class VhostUser:
"""Vhost-user interfaces L1 library."""
@staticmethod
def vpp_create_vhost_user_interface(
- node, socket, is_server=False, enable_gso=False):
+ node, socket, is_server=False, virtio_feature_mask=None):
"""Create Vhost-user interface on VPP node.
:param node: Node to create Vhost-user interface on.
:param socket: Vhost-user interface socket path.
:param is_server: Server side of connection. Default: False
- :param enable_gso: Generic segmentation offloading. Default: False
+ :param virtio_feature_mask: Mask of virtio features to be enabled.
:type node: dict
:type socket: str
:type is_server: bool
- :type enable_gso: bool
+ :type virtio_feature_mask: int
:returns: SW interface index.
:rtype: int
"""
cmd = u"create_vhost_user_if"
err_msg = f"Failed to create Vhost-user interface " \
f"on host {node[u'host']}"
+ if virtio_feature_mask is None:
+ enable_gso = False
+ else:
+ enable_gso = VirtioFeatureMask.is_feature_enabled(
+ virtio_feature_mask, VirtioFeaturesFlags.VIRTIO_NET_F_API_GSO
+ )
args = dict(
is_server=bool(is_server),
sock_filename=str(socket),
@@ -123,3 +150,42 @@ class VhostUser:
logger.debug(f"Vhost-user details:\n{details}")
return details
+
+
+class VirtioFeatureMask:
+ """Virtio features utilities"""
+
+ @staticmethod
+ def create_virtio_feature_mask(**kwargs):
+ """Create virtio feature mask with feature bits set according to kwargs.
+ :param kwargs: Key-value pairs of feature names and it's state
+ :type kwargs: dict
+ """
+ virtio_feature_mask = 0
+
+ if u"all" in kwargs and kwargs[u"all"] is True:
+ for virtio_feature_flag in VirtioFeaturesFlags:
+ virtio_feature_mask |= 1 << virtio_feature_flag.value
+ else:
+ for feature_name, enabled in kwargs.items():
+ virtio_feature_name = \
+ u"VIRTIO_NET_F_API_" + feature_name.upper()
+ if virtio_feature_name not in VirtioFeaturesFlags.__members__:
+ raise ValueError(u"Unsupported virtio feature flag name")
+ if enabled:
+ virtio_feature_mask |= \
+ 1 << VirtioFeaturesFlags[virtio_feature_name].value
+
+ return virtio_feature_mask
+
+ @staticmethod
+ def is_feature_enabled(virtio_feature_mask, virtio_feature_flag):
+ """Checks if concrete virtio feature is enabled within
+ virtio_feature_mask
+ :param virtio_feature_mask: Mask of enabled virtio features
+ :param virtio_feature_flag: Checked virtio feature
+ :type virtio_feature_mask: int
+ :type virtio_feature_flag: VirtioFeaturesFlags
+ """
+ feature_flag_bit = 1 << virtio_feature_flag.value
+ return (virtio_feature_mask & feature_flag_bit) > 0