| OLD | NEW |
| 1 import logging, commands, random | 1 import logging, commands, random |
| 2 from autotest_lib.client.common_lib import error | 2 from autotest_lib.client.common_lib import error |
| 3 from autotest_lib.client.bin import utils | 3 from autotest_lib.client.bin import utils |
| 4 import kvm_test_utils, kvm_utils | 4 from autotest_lib.client.virt import virt_utils, virt_test_utils |
| 5 | 5 |
| 6 | 6 |
| 7 def run_jumbo(test, params, env): | 7 def run_jumbo(test, params, env): |
| 8 """ | 8 """ |
| 9 Test the RX jumbo frame function of vnics: | 9 Test the RX jumbo frame function of vnics: |
| 10 | 10 |
| 11 1) Boot the VM. | 11 1) Boot the VM. |
| 12 2) Change the MTU of guest nics and host taps depending on the NIC model. | 12 2) Change the MTU of guest nics and host taps depending on the NIC model. |
| 13 3) Add the static ARP entry for guest NIC. | 13 3) Add the static ARP entry for guest NIC. |
| 14 4) Wait for the MTU ok. | 14 4) Wait for the MTU ok. |
| (...skipping 15 matching lines...) Expand all Loading... |
| 30 flood_time = params.get("flood_time", "300") | 30 flood_time = params.get("flood_time", "300") |
| 31 max_icmp_pkt_size = int(mtu) - 28 | 31 max_icmp_pkt_size = int(mtu) - 28 |
| 32 | 32 |
| 33 ifname = vm.get_ifname(0) | 33 ifname = vm.get_ifname(0) |
| 34 ip = vm.get_address(0) | 34 ip = vm.get_address(0) |
| 35 if ip is None: | 35 if ip is None: |
| 36 raise error.TestError("Could not get the IP address") | 36 raise error.TestError("Could not get the IP address") |
| 37 | 37 |
| 38 try: | 38 try: |
| 39 # Environment preparation | 39 # Environment preparation |
| 40 ethname = kvm_test_utils.get_linux_ifname(session, vm.get_mac_address(0)
) | 40 ethname = virt_test_utils.get_linux_ifname(session, vm.get_mac_address(0
)) |
| 41 | 41 |
| 42 logging.info("Changing the MTU of guest ...") | 42 logging.info("Changing the MTU of guest ...") |
| 43 guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname , mtu) | 43 guest_mtu_cmd = "ifconfig %s mtu %s" % (ethname , mtu) |
| 44 session.cmd(guest_mtu_cmd) | 44 session.cmd(guest_mtu_cmd) |
| 45 | 45 |
| 46 logging.info("Chaning the MTU of host tap ...") | 46 logging.info("Chaning the MTU of host tap ...") |
| 47 host_mtu_cmd = "ifconfig %s mtu %s" % (ifname, mtu) | 47 host_mtu_cmd = "ifconfig %s mtu %s" % (ifname, mtu) |
| 48 utils.run(host_mtu_cmd) | 48 utils.run(host_mtu_cmd) |
| 49 | 49 |
| 50 logging.info("Add a temporary static ARP entry ...") | 50 logging.info("Add a temporary static ARP entry ...") |
| 51 arp_add_cmd = "arp -s %s %s -i %s" % (ip, vm.get_mac_address(0), ifname) | 51 arp_add_cmd = "arp -s %s %s -i %s" % (ip, vm.get_mac_address(0), ifname) |
| 52 utils.run(arp_add_cmd) | 52 utils.run(arp_add_cmd) |
| 53 | 53 |
| 54 def is_mtu_ok(): | 54 def is_mtu_ok(): |
| 55 s, o = kvm_test_utils.ping(ip, 1, interface=ifname, | 55 s, o = virt_test_utils.ping(ip, 1, interface=ifname, |
| 56 packetsize=max_icmp_pkt_size, | 56 packetsize=max_icmp_pkt_size, |
| 57 hint="do", timeout=2) | 57 hint="do", timeout=2) |
| 58 return s == 0 | 58 return s == 0 |
| 59 | 59 |
| 60 def verify_mtu(): | 60 def verify_mtu(): |
| 61 logging.info("Verify the path MTU") | 61 logging.info("Verify the path MTU") |
| 62 s, o = kvm_test_utils.ping(ip, 10, interface=ifname, | 62 s, o = virt_test_utils.ping(ip, 10, interface=ifname, |
| 63 packetsize=max_icmp_pkt_size, | 63 packetsize=max_icmp_pkt_size, |
| 64 hint="do", timeout=15) | 64 hint="do", timeout=15) |
| 65 if s != 0 : | 65 if s != 0 : |
| 66 logging.error(o) | 66 logging.error(o) |
| 67 raise error.TestFail("Path MTU is not as expected") | 67 raise error.TestFail("Path MTU is not as expected") |
| 68 if kvm_test_utils.get_loss_ratio(o) != 0: | 68 if virt_test_utils.get_loss_ratio(o) != 0: |
| 69 logging.error(o) | 69 logging.error(o) |
| 70 raise error.TestFail("Packet loss ratio during MTU " | 70 raise error.TestFail("Packet loss ratio during MTU " |
| 71 "verification is not zero") | 71 "verification is not zero") |
| 72 | 72 |
| 73 def flood_ping(): | 73 def flood_ping(): |
| 74 logging.info("Flood with large frames") | 74 logging.info("Flood with large frames") |
| 75 kvm_test_utils.ping(ip, interface=ifname, | 75 virt_test_utils.ping(ip, interface=ifname, |
| 76 packetsize=max_icmp_pkt_size, | 76 packetsize=max_icmp_pkt_size, |
| 77 flood=True, timeout=float(flood_time)) | 77 flood=True, timeout=float(flood_time)) |
| 78 | 78 |
| 79 def large_frame_ping(count=100): | 79 def large_frame_ping(count=100): |
| 80 logging.info("Large frame ping") | 80 logging.info("Large frame ping") |
| 81 s, o = kvm_test_utils.ping(ip, count, interface=ifname, | 81 s, o = virt_test_utils.ping(ip, count, interface=ifname, |
| 82 packetsize=max_icmp_pkt_size, | 82 packetsize=max_icmp_pkt_size, |
| 83 timeout=float(count) * 2) | 83 timeout=float(count) * 2) |
| 84 ratio = kvm_test_utils.get_loss_ratio(o) | 84 ratio = virt_test_utils.get_loss_ratio(o) |
| 85 if ratio != 0: | 85 if ratio != 0: |
| 86 raise error.TestFail("Loss ratio of large frame ping is %s" % | 86 raise error.TestFail("Loss ratio of large frame ping is %s" % |
| 87 ratio) | 87 ratio) |
| 88 | 88 |
| 89 def size_increase_ping(step=random.randrange(90, 110)): | 89 def size_increase_ping(step=random.randrange(90, 110)): |
| 90 logging.info("Size increase ping") | 90 logging.info("Size increase ping") |
| 91 for size in range(0, max_icmp_pkt_size + 1, step): | 91 for size in range(0, max_icmp_pkt_size + 1, step): |
| 92 logging.info("Ping %s with size %s", ip, size) | 92 logging.info("Ping %s with size %s", ip, size) |
| 93 s, o = kvm_test_utils.ping(ip, 1, interface=ifname, | 93 s, o = virt_test_utils.ping(ip, 1, interface=ifname, |
| 94 packetsize=size, | 94 packetsize=size, |
| 95 hint="do", timeout=1) | 95 hint="do", timeout=1) |
| 96 if s != 0: | 96 if s != 0: |
| 97 s, o = kvm_test_utils.ping(ip, 10, interface=ifname, | 97 s, o = virt_test_utils.ping(ip, 10, interface=ifname, |
| 98 packetsize=size, | 98 packetsize=size, |
| 99 adaptive=True, hint="do", | 99 adaptive=True, hint="do", |
| 100 timeout=20) | 100 timeout=20) |
| 101 | 101 |
| 102 if kvm_test_utils.get_loss_ratio(o) > int(params.get( | 102 if virt_test_utils.get_loss_ratio(o) > int(params.get( |
| 103 "fail_ratio", 50)): | 103 "fail_ratio", 50)): |
| 104 raise error.TestFail("Ping loss ratio is greater " | 104 raise error.TestFail("Ping loss ratio is greater " |
| 105 "than 50% for size %s" % size) | 105 "than 50% for size %s" % size) |
| 106 | 106 |
| 107 logging.info("Waiting for the MTU to be OK") | 107 logging.info("Waiting for the MTU to be OK") |
| 108 wait_mtu_ok = 10 | 108 wait_mtu_ok = 10 |
| 109 if not kvm_utils.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): | 109 if not virt_utils.wait_for(is_mtu_ok, wait_mtu_ok, 0, 1): |
| 110 logging.debug(commands.getoutput("ifconfig -a")) | 110 logging.debug(commands.getoutput("ifconfig -a")) |
| 111 raise error.TestError("MTU is not as expected even after %s " | 111 raise error.TestError("MTU is not as expected even after %s " |
| 112 "seconds" % wait_mtu_ok) | 112 "seconds" % wait_mtu_ok) |
| 113 | 113 |
| 114 # Functional Test | 114 # Functional Test |
| 115 verify_mtu() | 115 verify_mtu() |
| 116 large_frame_ping() | 116 large_frame_ping() |
| 117 size_increase_ping() | 117 size_increase_ping() |
| 118 | 118 |
| 119 # Stress test | 119 # Stress test |
| 120 flood_ping() | 120 flood_ping() |
| 121 verify_mtu() | 121 verify_mtu() |
| 122 | 122 |
| 123 finally: | 123 finally: |
| 124 # Environment clean | 124 # Environment clean |
| 125 session.close() | 125 session.close() |
| 126 logging.info("Removing the temporary ARP entry") | 126 logging.info("Removing the temporary ARP entry") |
| 127 utils.run("arp -d %s -i %s" % (ip, ifname)) | 127 utils.run("arp -d %s -i %s" % (ip, ifname)) |
| OLD | NEW |