github.com/dmaizel/tests@v0.0.0-20210728163746-cae6a2d9cee8/metrics/network/network-metrics-iperf.sh (about) 1 #!/bin/bash 2 # 3 # Copyright (c) 2018 Intel Corporation 4 # 5 # SPDX-License-Identifier: Apache-2.0 6 # 7 # This test measures bidirectional bandwidth. This 8 # is used when we want to test both directions for the 9 # maximum amount of throughput. 10 # Bidirectional bandwidth is only supported by iperf, 11 # this feature was dropped for iperf3. 12 13 set -e 14 15 SCRIPT_PATH=$(dirname "$(readlink -f "$0")") 16 source "${SCRIPT_PATH}/lib/network-common.bash" 17 source "${SCRIPT_PATH}/../lib/common.bash" 18 19 # Test name 20 TEST_NAME="${TEST_NAME:-network iperf bidirectional bandwidth}" 21 # Image name 22 image="${image:-local-iperf}" 23 # Dockerfile 24 dockerfile="${SCRIPT_PATH}/iperf_dockerfile/Dockerfile" 25 # Measurement time (seconds) 26 transmit_timeout="${transmit_timeout:-30}" 27 28 save_config(){ 29 metrics_json_start_array 30 31 local json="$(cat << EOF 32 { 33 "image": "$image", 34 "iperf version": "2.0.5", 35 "transmit timeout": $transmit_timeout 36 } 37 EOF 38 )" 39 metrics_json_add_array_element "$json" 40 metrics_json_end_array "Config" 41 } 42 43 44 function main() { 45 cmds=("awk") 46 check_cmds "${cmds[@]}" 47 48 # Check no processes are left behind 49 check_processes 50 check_dockerfiles_images "$image" "$dockerfile" 51 init_env 52 53 # Start iperf server configuration 54 # Set the TMPDIR to an existing tmpfs mount to avoid a 9p unlink error 55 local init_cmds="export TMPDIR=/dev/shm" 56 local server_command="$init_cmds && iperf -s" 57 local server_address=$(start_server "$image" "$server_command" "$server_extra_args") 58 59 # Verify server IP address 60 if [ -z "$server_address" ];then 61 clean_env 62 die "server: ip address no found" 63 fi 64 65 # Start iperf client 66 local client_command="$init_cmds && iperf -c $server_address -d -T $transmit_timeout" 67 68 metrics_json_init 69 save_config 70 71 result=$(start_client "$image" "$client_command" "$client_extra_args") 72 73 metrics_json_start_array 74 75 local total_bidirectional_client_bandwidth=$(echo $result | tail -1 | awk '{print $(NF-9)}') 76 local total_bidirectional_client_bandwidth_units=$(echo $result | tail -1 | awk '{print $(NF-8)}') 77 local total_bidirectional_server_bandwidth=$(echo $result | tail -1 | awk '{print $(NF-1)}') 78 local total_bidirectional_server_bandwidth_units=$(echo $result | tail -1 | awk '{print $(NF)}') 79 80 local json="$(cat << EOF 81 { 82 "client to server": { 83 "Result" : $total_bidirectional_client_bandwidth, 84 "Units" : "$total_bidirectional_client_bandwidth_units" 85 }, 86 "server to client": { 87 "Result" : $total_bidirectional_server_bandwidth, 88 "Units" : "$total_bidirectional_server_bandwidth_units" 89 } 90 } 91 EOF 92 )" 93 94 metrics_json_add_array_element "$json" 95 metrics_json_end_array "Results" 96 metrics_json_save 97 clean_env 98 99 # Check no processes are left behind 100 check_processes 101 } 102 main "$@"