in microsoft/testsuites/network/networksettings.py [0:0]
def validate_device_statistics(self, environment: Environment, log: Logger) -> None:
client_iperf3_log = "iperfResults.log"
server_node = cast(RemoteNode, environment.nodes[0])
client_node = cast(RemoteNode, environment.nodes[1])
ethtool = client_node.tools[Ethtool]
try:
devices_statistics = ethtool.get_all_device_statistics()
except UnsupportedOperationException as identifier:
raise SkippedException(identifier)
for device_stats in devices_statistics:
per_queue_packets = {
k: v
for (k, v) in device_stats.items()
if self._queue_stats_regex.search(k)
}
assert_that(
per_queue_packets,
"Statistics per VMBUS channel are empty. It might be because the driver"
" is not supported or because of very old kernel.",
).is_not_empty()
# preparation work before launch iperf3
stop_firewall(environment)
# run iperf3 on server side and client side
# iperfResults.log stored client side log
source_iperf3 = server_node.tools[Iperf3]
dest_iperf3 = client_node.tools[Iperf3]
source_iperf3.run_as_server()
dest_iperf3.run_as_client(
server_node.internal_address, client_iperf3_log, parallel_number=64
)
# wait for a while then check any error shown up in iperfResults.log
dest_cat = client_node.tools[Cat]
iperf_log = dest_cat.read(client_iperf3_log, sudo=True, force_run=True)
assert_that(iperf_log).does_not_contain("error")
# validate from the stats that traffic is evenly spread
try:
devices_statistics = ethtool.get_all_device_statistics()
except UnsupportedOperationException as identifier:
raise SkippedException(identifier)
for device_stats in devices_statistics:
per_tx_queue_packets = [
v
for (k, v) in device_stats.items()
if self._tx_queue_stats_regex.search(k)
]
# No queue should receive/transmit 30% more packets than other queues
# If it does, failure should be reported
min_tx_queue_packets = min(per_tx_queue_packets)
# Avoid divide by 0 scenario while checking traffic spread among queues
if min_tx_queue_packets == 0:
min_tx_queue_packets = 1
max_tx_queue_packets = max(per_tx_queue_packets)
assert_that(
((max_tx_queue_packets - min_tx_queue_packets) / min_tx_queue_packets),
"Statistics show traffic is not evenly distributed among tx queues",
).is_less_than_or_equal_to(0.3)
per_rx_queue_packets = [
v
for (k, v) in device_stats.items()
if self._rx_queue_stats_regex.search(k)
]
min_rx_queue_packets = min(per_rx_queue_packets)
# Avoid divide by 0 scenario while checking traffic spread among queues
if min_rx_queue_packets == 0:
min_rx_queue_packets = 1
max_rx_queue_packets = max(per_rx_queue_packets)
assert_that(
((max_rx_queue_packets - min_rx_queue_packets) / min_rx_queue_packets),
"Statistics show traffic is not evenly distributed among rx queues",
).is_less_than_or_equal_to(0.3)