|
| 1 | +# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +"""Tests for the net device.""" |
| 4 | +from subprocess import run, PIPE |
| 5 | +import time |
| 6 | + |
| 7 | +import host_tools.network as net_tools |
| 8 | + |
| 9 | +# The iperf version to run this tests with |
| 10 | +IPERF_BINARY = 'iperf3' |
| 11 | + |
| 12 | + |
| 13 | +def test_high_ingress_traffic(test_microvm_with_ssh, network_config): |
| 14 | + """Run iperf rx with high UDP traffic.""" |
| 15 | + test_microvm = test_microvm_with_ssh |
| 16 | + test_microvm.spawn() |
| 17 | + |
| 18 | + test_microvm.basic_config() |
| 19 | + |
| 20 | + # Create tap before configuring interface. |
| 21 | + tap, _host_ip, guest_ip = test_microvm.ssh_network_config( |
| 22 | + network_config, |
| 23 | + '1' |
| 24 | + ) |
| 25 | + # Set the tap's tx queue len to 5. This increases the probability |
| 26 | + # of filling the tap under high ingress traffic. |
| 27 | + tap.set_tx_queue_len(5) |
| 28 | + |
| 29 | + # Start the microvm. |
| 30 | + test_microvm.start() |
| 31 | + |
| 32 | + # Start iperf3 server on the guest. |
| 33 | + ssh_connection = net_tools.SSHConnection(test_microvm.ssh_config) |
| 34 | + ssh_connection.execute_command('{} -sD\n'.format(IPERF_BINARY)) |
| 35 | + time.sleep(1) |
| 36 | + |
| 37 | + # Start iperf3 client on the host. Send 1Gbps UDP traffic. |
| 38 | + # If the net device breaks, iperf will freeze. We have to use a timeout. |
| 39 | + run( |
| 40 | + 'timeout 30 {} {} -c {} -u -V -b 1000000000 -t 30'.format( |
| 41 | + test_microvm.jailer.netns_cmd_prefix(), |
| 42 | + IPERF_BINARY, |
| 43 | + guest_ip, |
| 44 | + ), stdout=PIPE, shell=True, check=False |
| 45 | + ) |
| 46 | + |
| 47 | + # Check if the high ingress traffic broke the net interface. |
| 48 | + # If the net interface still works we should be able to execute |
| 49 | + # ssh commands. |
| 50 | + exit_code, _, _ = ssh_connection.execute_command('echo success\n') |
| 51 | + assert exit_code == 0 |
0 commit comments