summaryrefslogtreecommitdiffstats
path: root/test/vpp_iperf.py
diff options
context:
space:
mode:
authorNaveen Joy <najoy@cisco.com>2022-10-04 14:22:05 -0700
committerDave Wallace <dwallacelf@gmail.com>2022-12-13 01:43:01 +0000
commite416893a597959509c7f667c140c271c0bb78c14 (patch)
treec294b99cfe1890415c8a14968caf358182b6a4ca /test/vpp_iperf.py
parentd3ccb0c2fba3e3f8b2eca7b2e1a1fe2877eb993b (diff)
tests: tapv2, tunv2 and af_packet interface tests for vpp
Tests gso/gro-coalesce features on tapv2, tunv2 and af_packet interfaces to ensure that packet transmission is enabled correctly for various MTU sizes and interface combinations in bridged and routed topologies for IPv4 and IPv6. Interface tests are dynamically generated at run time from the config file vm_test_config.py. Type: test Change-Id: I5f9d8cc80d20b4e34011fc8a87e35659bd9613bc Signed-off-by: Naveen Joy <najoy@cisco.com>
Diffstat (limited to 'test/vpp_iperf.py')
-rw-r--r--test/vpp_iperf.py118
1 files changed, 98 insertions, 20 deletions
diff --git a/test/vpp_iperf.py b/test/vpp_iperf.py
index 78ce9d08c90..42b5ea8a523 100644
--- a/test/vpp_iperf.py
+++ b/test/vpp_iperf.py
@@ -4,6 +4,7 @@
import subprocess
import os
+import sys
class VppIperf:
@@ -26,13 +27,14 @@ class VppIperf:
iperf.server_args='-p 5202'
"""
- def __init__(self, server_ns=None, client_ns=None, server_ip=None):
+ def __init__(self, server_ns=None, client_ns=None, server_ip=None, logger=None):
self.server_ns = server_ns
self.client_ns = client_ns
self.server_ip = server_ip
self.duration = 10
self.client_args = ""
self.server_args = ""
+ self.logger = logger
# Set the iperf executable
self.iperf = os.path.join(os.getenv("TEST_DATA_DIR") or "/", "usr/bin/iperf")
@@ -45,7 +47,6 @@ class VppIperf:
)
def start_iperf_server(self):
- print("Starting iPerf Server Daemon in Namespace ", self.server_ns)
args = [
"ip",
"netns",
@@ -54,22 +55,22 @@ class VppIperf:
self.iperf,
"-s",
"-D",
- "-B",
- self.server_ip,
]
args.extend(self.server_args.split())
+ args = " ".join(args)
try:
- subprocess.run(
+ return subprocess.run(
args,
- stderr=subprocess.STDOUT,
timeout=self.duration + 5,
encoding="utf-8",
+ shell=True,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
)
except subprocess.TimeoutExpired as e:
raise Exception("Error: Timeout expired for iPerf", e.output)
def start_iperf_client(self):
- print("Starting iPerf Client in Namespace ", self.client_ns)
args = [
"ip",
"netns",
@@ -82,30 +83,107 @@ class VppIperf:
str(self.duration),
]
args.extend(self.client_args.split())
+ args = " ".join(args)
try:
- subprocess.run(
+ return subprocess.run(
args,
- stderr=subprocess.STDOUT,
timeout=self.duration + 5,
encoding="utf-8",
+ capture_output=True,
+ shell=True,
)
except subprocess.TimeoutExpired as e:
raise Exception("Error: Timeout expired for iPerf", e.output)
- def start(self):
- """Run iPerf and return True if successful"""
+ def start(self, server_only=False, client_only=False):
+ """Runs iPerf.
+
+ Starts the iperf server daemon & runs the iperf client.
+ arguments:-
+ server_only -- start the iperf server daemon only
+ client_only -- run the iperf client only
+ Return True if we have no errors in iPerf client, else False.
+ """
self.ensure_init()
- try:
+ if not client_only:
self.start_iperf_server()
- except Exception as e:
- subprocess.run(["pkill", "iperf"])
- raise Exception("Error starting iPerf Server", e)
+ if not server_only:
+ result = self.start_iperf_client()
+ self.logger.debug(f"Iperf client args: {result.args}")
+ self.logger.debug(result.stdout)
+ if result.stderr:
+ self.logger.error(
+ f"Error starting Iperf Client in Namespace: {self.client_ns}"
+ )
+ self.logger.error(f"Iperf client args: {result.args}")
+ self.logger.error(f"Iperf client has errors: {result.stderr}")
+ return False
+ else:
+ return True
- try:
- self.start_iperf_client()
- except Exception as e:
- raise Exception("Error starting iPerf Client", e)
- subprocess.run(["pkill", "iperf"])
+
+## Functions to start and stop iPerf using the iPerf object
+def start_iperf(
+ ip_version,
+ client_ns="iprf_client_ns",
+ server_ns="iprf_server_ns",
+ server_ipv4_address="10.0.0.102",
+ server_ipv6_address="2001:1::2",
+ client_args="",
+ server_args="",
+ duration=10,
+ server_only=False,
+ client_only=False,
+ logger=None,
+):
+ """Start an iperf connection stream using the iPerf object.
+
+ Starts iPerf an connection stream between an iPerf client in the
+ client namespace (client_ns) and a server in another
+ namespace (server_ns).
+ Parameters:
+ ip_version - 4 or 6
+ client_ns - iPerf client namespace
+ server_ns - iPerf server namespace
+ server_ipv4_address - ipv4 address of the server, if ip_version=4
+ server_ipv6_address - ipv6 address of the server, if ip_version=6
+ client_args - Additonal iperf control arguments to be passed
+ to the iperf client from the test (str)
+ server_args - Additonal iperf control arguments to be passed
+ to the iperf server from the test (str)
+ duration - Iperf duration in seconds
+ server_only - start iperf server only
+ client_only - start the iperf client only
+ logger - test logger
+ """
+ if ip_version == 4:
+ iperf_server_ip = server_ipv4_address
+ elif ip_version == 6:
+ iperf_server_ip = server_ipv6_address
+ client_args = "-V" + " " + client_args
+ server_args = "-V" + " " + server_args
+ iperf = VppIperf()
+ iperf.client_ns = client_ns
+ iperf.server_ns = server_ns
+ iperf.server_ip = iperf_server_ip
+ iperf.client_args = client_args
+ iperf.server_args = server_args
+ iperf.duration = duration
+ iperf.logger = logger
+ return iperf.start(server_only=server_only, client_only=client_only)
+
+
+def stop_iperf():
+ args = ["pkill", "iperf"]
+ args = " ".join(args)
+ try:
+ return subprocess.run(
+ args,
+ encoding="utf-8",
+ shell=True,
+ )
+ except Exception:
+ pass
if __name__ == "__main__":