99# The iperf version to run this tests with
1010IPERF_BINARY = "iperf3"
1111
12+ # iperf server side log path inside guest
13+ GUEST_IPERF_SERVER_LOG = "/tmp/iperf-server.log"
14+
1215# Interval used by iperf to get maximum bandwidth
1316IPERF_TRANSMIT_TIME = 4
1417
@@ -127,7 +130,7 @@ def test_rx_rate_limiting_cpu_load(uvm_plain):
127130 threshold = 20 ,
128131 )
129132 with cpu_load_monitor :
130- _run_iperf_on_host (iperf_cmd )
133+ _run_iperf_on_host (iperf_cmd , test_microvm )
131134
132135
133136def _check_tx_rate_limiting (test_microvm ):
@@ -141,7 +144,7 @@ def _check_tx_rate_limiting(test_microvm):
141144
142145 # First step: get the transfer rate when no rate limiting is enabled.
143146 # We are receiving the result in KBytes from iperf.
144- print ("Run guest TX iperf with no rate-limit " )
147+ print ("Run guest TX iperf for no rate limiting " )
145148 rate_no_limit_kbps = _get_tx_bandwidth_with_duration (
146149 test_microvm , eth0 .host_ip , IPERF_TRANSMIT_TIME
147150 )
@@ -157,11 +160,12 @@ def _check_tx_rate_limiting(test_microvm):
157160 assert _get_percentage_difference (rate_no_limit_kbps , expected_kbps ) > 100
158161
159162 # Second step: check bandwidth when rate limiting is on.
163+ print ("Run guest TX iperf for rate limiting without burst" )
160164 _check_tx_bandwidth (test_microvm , eth1 .host_ip , expected_kbps )
161165
162166 # Third step: get the number of bytes when rate limiting is on and there is
163167 # an initial burst size from where to consume.
164- print ("Run guest TX iperf with exact burst size " )
168+ print ("Run guest TX iperf for rate limiting with burst " )
165169 # Use iperf to obtain the bandwidth when there is burst to consume from,
166170 # send exactly BURST_SIZE packets.
167171 iperf_cmd = "{} -c {} -n {} -f KBytes -w {} -N" .format (
@@ -189,7 +193,7 @@ def _check_rx_rate_limiting(test_microvm):
189193
190194 # First step: get the transfer rate when no rate limiting is enabled.
191195 # We are receiving the result in KBytes from iperf.
192- print ("Run guest RX iperf with no rate-limit " )
196+ print ("Run guest RX iperf with no rate limiting " )
193197 rate_no_limit_kbps = _get_rx_bandwidth_with_duration (
194198 test_microvm , eth0 .guest_ip , IPERF_TRANSMIT_TIME
195199 )
@@ -205,11 +209,12 @@ def _check_rx_rate_limiting(test_microvm):
205209 assert _get_percentage_difference (rate_no_limit_kbps , expected_kbps ) > 100
206210
207211 # Second step: check bandwidth when rate limiting is on.
212+ print ("Run guest RX iperf for rate limiting without burst" )
208213 _check_rx_bandwidth (test_microvm , eth1 .guest_ip , expected_kbps )
209214
210215 # Third step: get the number of bytes when rate limiting is on and there is
211216 # an initial burst size from where to consume.
212- print ("Run guest RX iperf with exact burst size " )
217+ print ("Run guest RX iperf for rate limiting with burst " )
213218 # Use iperf to obtain the bandwidth when there is burst to consume from,
214219 # send exactly BURST_SIZE packets.
215220 iperf_cmd = "{} {} -c {} -n {} -f KBytes -w {} -N" .format (
@@ -219,8 +224,7 @@ def _check_rx_rate_limiting(test_microvm):
219224 BURST_SIZE ,
220225 IPERF_TCP_WINDOW ,
221226 )
222- iperf_out = _run_iperf_on_host (iperf_cmd )
223- print (iperf_out )
227+ iperf_out = _run_iperf_on_host (iperf_cmd , test_microvm )
224228 _ , burst_kbps = _process_iperf_output (iperf_out )
225229 print ("RX burst_kbps: {}" .format (burst_kbps ))
226230 # Test that the burst bandwidth is at least as two times the rate limit.
@@ -357,9 +361,7 @@ def _get_rx_bandwidth_with_duration(test_microvm, guest_ip, duration):
357361 duration ,
358362 IPERF_TCP_WINDOW ,
359363 )
360- iperf_out = _run_iperf_on_host (iperf_cmd )
361- print (iperf_out )
362-
364+ iperf_out = _run_iperf_on_host (iperf_cmd , test_microvm )
363365 _ , observed_kbps = _process_iperf_output (iperf_out )
364366 print ("RX observed_kbps: {}" .format (observed_kbps ))
365367 return observed_kbps
@@ -383,7 +385,7 @@ def _patch_iface_bw(test_microvm, iface_id, rx_or_tx, new_bucket_size, new_refil
383385
384386def _start_iperf_server_on_guest (test_microvm ):
385387 """Start iperf in server mode through an SSH connection."""
386- iperf_cmd = "{ } -sD -f KBytes\n " . format ( IPERF_BINARY )
388+ iperf_cmd = f" { IPERF_BINARY } -sD -f KBytes --logfile { GUEST_IPERF_SERVER_LOG } "
387389 test_microvm .ssh .run (iperf_cmd )
388390
389391 # Wait for the iperf daemon to start.
@@ -411,10 +413,15 @@ def _start_iperf_server_on_host(netns_cmd_prefix):
411413 time .sleep (1 )
412414
413415
414- def _run_iperf_on_host (iperf_cmd ):
416+ def _run_iperf_on_host (iperf_cmd , test_microvm ):
415417 """Execute a client related iperf command locally."""
416- code , stdout , stderr = utils .check_output (iperf_cmd )
417- assert code == 0 , f"stdout: { stdout } \n stderr: { stderr } "
418+ rc , stdout , stderr = utils .run_cmd (iperf_cmd )
419+ assert rc == 0 , "stdout:\n {}\n stderr:\n {}\n iperf server log:\n {}\n " .format (
420+ stdout ,
421+ stderr ,
422+ test_microvm .ssh .check_output (f"cat { GUEST_IPERF_SERVER_LOG } " ).stdout ,
423+ )
424+ print (f"iperf log:\n { stdout } " )
418425
419426 return stdout
420427
0 commit comments