2024-01-01 17:42:17 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2024-01-10 11:54:33 +01:00
|
|
|
|
|
|
|
function with_set_x() {
|
|
|
|
set -x
|
|
|
|
"$@"
|
|
|
|
{
|
|
|
|
ec=$?
|
|
|
|
set +x
|
|
|
|
return $ec
|
|
|
|
} 2>/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
function log() {
|
|
|
|
echo "$*" >&2
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-01-02 18:43:06 +01:00
|
|
|
args=()
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
|
|
arg=$1
|
|
|
|
shift
|
|
|
|
case "$arg" in
|
|
|
|
-6)
|
|
|
|
ipv6_only=true
|
|
|
|
continue
|
|
|
|
;;
|
|
|
|
-*) ;;
|
|
|
|
*)
|
|
|
|
if [[ -z $tool ]]; then
|
|
|
|
tool=$arg
|
|
|
|
continue
|
|
|
|
elif [[ -z $node ]]; then
|
|
|
|
node=$arg
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
args+=("$arg")
|
|
|
|
done
|
|
|
|
|
|
|
|
tool=${tool?:"tool argument missing. should be one of iperf3,ping,curl,ab"}
|
|
|
|
node=${node?:"node argument missing. should be 'node-1' , 'node-2' etc"}
|
2024-01-01 17:42:17 +01:00
|
|
|
|
2024-01-02 07:33:24 +01:00
|
|
|
if [[ $node == node-* ]]; then
|
|
|
|
index=${node#node-}
|
2024-01-02 18:43:06 +01:00
|
|
|
if [[ $ipv6_only == true ]]; then
|
|
|
|
host="2001:0DB8::55$index"
|
|
|
|
else
|
|
|
|
host="10.55.$index.77"
|
|
|
|
fi
|
2024-01-02 07:33:24 +01:00
|
|
|
else
|
|
|
|
host=$node
|
|
|
|
fi
|
|
|
|
|
2024-01-01 17:42:17 +01:00
|
|
|
connect_timeout_sec=3
|
|
|
|
|
|
|
|
case "$tool" in
|
|
|
|
ping)
|
2024-01-02 18:43:06 +01:00
|
|
|
with_set_x exec ping -W $connect_timeout_sec "${args[@]}" "$host"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
iperf3)
|
|
|
|
port=5001
|
2024-01-02 18:43:06 +01:00
|
|
|
with_set_x exec iperf3 --client "$host" --port=$port --connect-timeout=$((connect_timeout_sec * 1000)) "${args[@]}"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
curl)
|
|
|
|
port=8080
|
2024-01-02 18:43:06 +01:00
|
|
|
if [[ $host = *:* ]]; then
|
|
|
|
host="[$host]"
|
|
|
|
args+=(--ipv6)
|
|
|
|
fi
|
|
|
|
with_set_x exec curl "http://$host:$port/" -v --connect-timeout $connect_timeout_sec "${args[@]}"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
|
|
|
ab)
|
|
|
|
port=8080
|
2024-01-02 18:43:06 +01:00
|
|
|
if [[ " ${args[*]}" != *" -n "* && " ${args[*]}" != *" -c "* ]]; then
|
|
|
|
args+=(-n 500 -c 50 "${args[@]}")
|
2024-01-02 07:33:24 +01:00
|
|
|
fi
|
2024-01-02 18:43:06 +01:00
|
|
|
with_set_x exec ab -s $connect_timeout_sec "${args[@]}" "http://$host:$port/"
|
2024-01-01 17:42:17 +01:00
|
|
|
;;
|
2024-01-02 05:16:22 +01:00
|
|
|
*)
|
2024-01-10 11:54:33 +01:00
|
|
|
log "Unknown tool: $tool"
|
2024-01-02 05:16:22 +01:00
|
|
|
exit 2
|
|
|
|
;;
|
2024-01-01 17:42:17 +01:00
|
|
|
esac
|