@@ -161,7 +161,10 @@ def _check_tx_rate_limiting(test_microvm):
161
161
162
162
# Second step: check bandwidth when rate limiting is on.
163
163
print ("Run guest TX iperf for rate limiting without burst" )
164
- _check_tx_bandwidth (test_microvm , eth1 .host_ip , expected_kbps )
164
+ observed_kbps = _get_tx_bandwidth_with_duration (
165
+ test_microvm , eth1 .host_ip , IPERF_TRANSMIT_TIME
166
+ )
167
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
165
168
166
169
# Third step: get the number of bytes when rate limiting is on and there is
167
170
# an initial burst size from where to consume.
@@ -179,7 +182,10 @@ def _check_tx_rate_limiting(test_microvm):
179
182
assert _diff (burst_kbps , expected_kbps ) > 100
180
183
181
184
# Since the burst should be consumed, check rate limit is in place.
182
- _check_tx_bandwidth (test_microvm , eth2 .host_ip , expected_kbps )
185
+ observed_kbps = _get_tx_bandwidth_with_duration (
186
+ test_microvm , eth2 .host_ip , IPERF_TRANSMIT_TIME
187
+ )
188
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
183
189
184
190
185
191
def _check_rx_rate_limiting (test_microvm ):
@@ -241,11 +247,17 @@ def _check_tx_rate_limit_patch(test_microvm):
241
247
# Check that a TX rate limiter can be applied to a previously unlimited
242
248
# interface.
243
249
_patch_iface_bw (test_microvm , "eth0" , "TX" , bucket_size , REFILL_TIME_MS )
244
- _check_tx_bandwidth (test_microvm , eth0 .host_ip , expected_kbps )
250
+ observed_kbps = _get_tx_bandwidth_with_duration (
251
+ test_microvm , eth0 .host_ip , IPERF_TRANSMIT_TIME
252
+ )
253
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
245
254
246
255
# Check that a TX rate limiter can be updated.
247
256
_patch_iface_bw (test_microvm , "eth1" , "TX" , bucket_size , REFILL_TIME_MS )
248
- _check_tx_bandwidth (test_microvm , eth1 .host_ip , expected_kbps )
257
+ observed_kbps = _get_tx_bandwidth_with_duration (
258
+ test_microvm , eth1 .host_ip , IPERF_TRANSMIT_TIME
259
+ )
260
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
249
261
250
262
# Check that a TX rate limiter can be removed.
251
263
_patch_iface_bw (test_microvm , "eth0" , "TX" , 0 , 0 )
@@ -283,15 +295,6 @@ def _check_rx_rate_limit_patch(test_microvm):
283
295
assert _diff (rate_no_limit_kbps , expected_kbps ) > 50
284
296
285
297
286
- def _check_tx_bandwidth (test_microvm , ip , expected_kbps ):
287
- """Check that the rate-limited TX bandwidth is close to what we expect."""
288
- observed_kbps = _get_tx_bandwidth_with_duration (
289
- test_microvm , ip , IPERF_TRANSMIT_TIME
290
- )
291
- diff_pc = _diff (observed_kbps , expected_kbps )
292
- assert diff_pc < MAX_BYTES_DIFF_PERCENTAGE
293
-
294
-
295
298
def _get_tx_bandwidth_with_duration (test_microvm , host_ip , duration ):
296
299
"""Check that the rate-limited TX bandwidth is close to what we expect."""
297
300
0 commit comments