Refactor iperf3 function in runtest.sh for improved argument handling and readability
This commit is contained in:
parent
e3c3647a7e
commit
50000ac5c2
1 changed files with 15 additions and 11 deletions
26
runtest.sh
26
runtest.sh
|
@ -109,23 +109,27 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do
|
|||
|
||||
# iperf3 function
|
||||
run_iperf() {
|
||||
local target=$1
|
||||
local mode=$2 # tcp or udp
|
||||
local direction=$3 # up or down
|
||||
|
||||
local args="-c $target -J -t $IPERF_DURATION"
|
||||
[ "$mode" = "udp" ] && args="$args -u -b 10M"
|
||||
|
||||
[ "$direction" = "down" ] && args="$args -R"
|
||||
|
||||
iperf3 $args 2>/dev/null | jq -r '
|
||||
local target="$1"
|
||||
local mode="$2"
|
||||
local direction="$3"
|
||||
local args=("-c" "$target" "-J" "-t" "10")
|
||||
|
||||
if [ "$mode" = "udp" ]; then
|
||||
args+=("-u")
|
||||
fi
|
||||
|
||||
if [ "$direction" = "down" ]; then
|
||||
args+=("--reverse")
|
||||
fi
|
||||
|
||||
iperf3 "${args[@]}" 2>/dev/null | jq -r '
|
||||
if .error then "0" else
|
||||
if .end then
|
||||
if .end.sum_received then .end.sum_received.bits_per_second
|
||||
elif .end.sum then .end.sum.bits_per_second
|
||||
else "0" end
|
||||
else "0" end
|
||||
end'
|
||||
end' || echo "0"
|
||||
}
|
||||
|
||||
echo " Running iperf3 tests..."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue