3 # Start an iPerf connection stream between two Linux namespaces ##
10 """ "Create an iPerf connection stream between two namespaces.
13 iperf = VppIperf() # Create the iPerf Object
14 iperf.client_ns = 'ns1' # Client Namespace
15 iperf.server_ns = 'ns2' # Server Namespace
16 iperf.server_ip = '10.0.0.102' # Server IP Address
17 iperf.start() # Start the connection stream
20 iperf.duration = 15 # Time to transmit for in seconds (Default=10)
22 ## Optionally set any iperf client & server args
24 # Run 4 parallel streams, write to logfile & bind to port 5202
25 iperf.client_args='-P 4 --logfile /tmp/vpp-vm-tests/vpp_iperf.log -p 5202'
26 iperf.server_args='-p 5202'
29 def __init__(self, server_ns=None, client_ns=None, server_ip=None):
30 self.server_ns = server_ns
31 self.client_ns = client_ns
32 self.server_ip = server_ip
36 # Set the iperf executable
37 self.iperf = os.path.join(os.getenv("TEST_DATA_DIR") or "/", "usr/bin/iperf")
39 def ensure_init(self):
40 if self.server_ns and self.client_ns and self.server_ip:
44 "Error: Cannot Start." "iPerf object has not been initialized"
47 def start_iperf_server(self):
48 print("Starting iPerf Server Daemon in Namespace ", self.server_ns)
60 args.extend(self.server_args.split())
64 stderr=subprocess.STDOUT,
65 timeout=self.duration + 5,
68 except subprocess.TimeoutExpired as e:
69 raise Exception("Error: Timeout expired for iPerf", e.output)
71 def start_iperf_client(self):
72 print("Starting iPerf Client in Namespace ", self.client_ns)
84 args.extend(self.client_args.split())
88 stderr=subprocess.STDOUT,
89 timeout=self.duration + 5,
92 except subprocess.TimeoutExpired as e:
93 raise Exception("Error: Timeout expired for iPerf", e.output)
96 """Run iPerf and return True if successful"""
99 self.start_iperf_server()
100 except Exception as e:
101 subprocess.run(["pkill", "iperf"])
102 raise Exception("Error starting iPerf Server", e)
105 self.start_iperf_client()
106 except Exception as e:
107 raise Exception("Error starting iPerf Client", e)
108 subprocess.run(["pkill", "iperf"])
111 if __name__ == "__main__":
112 # Run iPerf using default settings
114 iperf.client_ns = "ns1"
115 iperf.server_ns = "ns2"
116 iperf.server_ip = "10.0.0.102"