@@ -207,7 +207,10 @@ def _check_rx_rate_limiting(test_microvm):
207
207
208
208
# Second step: check bandwidth when rate limiting is on.
209
209
print ("Run guest RX iperf for rate limiting without burst" )
210
- _check_rx_bandwidth (test_microvm , eth1 .guest_ip , expected_kbps )
210
+ observed_kbps = _get_rx_bandwidth_with_duration (
211
+ test_microvm , eth1 .guest_ip , IPERF_TRANSMIT_TIME
212
+ )
213
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
211
214
212
215
# Third step: get the number of bytes when rate limiting is on and there is
213
216
# an initial burst size from where to consume.
@@ -228,7 +231,10 @@ def _check_rx_rate_limiting(test_microvm):
228
231
assert _diff (burst_kbps , expected_kbps ) > 100
229
232
230
233
# Since the burst should be consumed, check rate limit is in place.
231
- _check_rx_bandwidth (test_microvm , eth2 .guest_ip , expected_kbps )
234
+ observed_kbps = _get_rx_bandwidth_with_duration (
235
+ test_microvm , eth2 .guest_ip , IPERF_TRANSMIT_TIME
236
+ )
237
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
232
238
233
239
234
240
def _check_tx_rate_limit_patch (test_microvm ):
@@ -267,11 +273,17 @@ def _check_rx_rate_limit_patch(test_microvm):
267
273
# Check that an RX rate limiter can be applied to a previously unlimited
268
274
# interface.
269
275
_patch_iface_bw (test_microvm , "eth0" , "RX" , bucket_size , REFILL_TIME_MS )
270
- _check_rx_bandwidth (test_microvm , eth0 .guest_ip , expected_kbps )
276
+ observed_kbps = _get_rx_bandwidth_with_duration (
277
+ test_microvm , eth0 .guest_ip , IPERF_TRANSMIT_TIME
278
+ )
279
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
271
280
272
281
# Check that an RX rate limiter can be updated.
273
282
_patch_iface_bw (test_microvm , "eth1" , "RX" , bucket_size , REFILL_TIME_MS )
274
- _check_rx_bandwidth (test_microvm , eth1 .guest_ip , expected_kbps )
283
+ observed_kbps = _get_rx_bandwidth_with_duration (
284
+ test_microvm , eth1 .guest_ip , IPERF_TRANSMIT_TIME
285
+ )
286
+ assert _diff (observed_kbps , expected_kbps ) < MAX_BYTES_DIFF_PERCENTAGE
275
287
276
288
# Check that an RX rate limiter can be removed.
277
289
_patch_iface_bw (test_microvm , "eth0" , "RX" , 0 , 0 )
@@ -306,15 +318,6 @@ def _get_tx_bandwidth_with_duration(test_microvm, host_ip, duration):
306
318
return observed_kbps
307
319
308
320
309
- def _check_rx_bandwidth (test_microvm , ip , expected_kbps ):
310
- """Check that the rate-limited RX bandwidth is close to what we expect."""
311
- observed_kbps = _get_rx_bandwidth_with_duration (
312
- test_microvm , ip , IPERF_TRANSMIT_TIME
313
- )
314
- diff_pc = _diff (observed_kbps , expected_kbps )
315
- assert diff_pc < MAX_BYTES_DIFF_PERCENTAGE
316
-
317
-
318
321
def _get_rx_bandwidth_with_duration (test_microvm , guest_ip , duration ):
319
322
"""Check that the rate-limited RX bandwidth is close to what we expect."""
320
323
0 commit comments