From 4891f0bdfe5f30a591d37669285e44afed8ea01a Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Mon, 21 Apr 2025 12:48:33 -0500 Subject: [PATCH] Add iperf3 testing functionality to runtest.sh and update CSV output format; include local and remote TCP/UDP metrics --- enrich.py | 3 --- runtest.sh | 38 ++++++++++++++++++++++++++++++++++++-- settings.env.default | 4 ++++ 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/enrich.py b/enrich.py index 4b1b4e1..9ffd2a5 100755 --- a/enrich.py +++ b/enrich.py @@ -433,9 +433,6 @@ def analyze_pcap(pcapng_path, start_ts, end_ts, ap_bssid, ap_channel): 'CiscoMaxClients': max(cisco_reported_clients) if cisco_reported_clients else 0 }) - - - finally: cap.close() diff --git a/runtest.sh b/runtest.sh index 2551e3d..a86ca26 100755 --- a/runtest.sh +++ b/runtest.sh @@ -56,7 +56,7 @@ FAILED_START=$(get_tx_failed) # Create CSV header if needed if [ ! -f "$TEST_FILE" ]; then - echo "StartTimestamp,EndTimestamp,Link,Level,Noise,BSSID,TX Bitrate,RX Bitrate,$(speedtest --csv-header),TX Failures,Channel,Frequency,Packet Loss,Jitter" > "$TEST_FILE" + echo "StartTimestamp,EndTimestamp,Link,Level,Noise,BSSID,TX Bitrate,RX Bitrate,$(speedtest --csv-header),TX Failures,Channel,Frequency,Packet Loss,Jitter,LocalTCPUp,LocalTCPDown,LocalUDPUp,LocalUDPDown,RemoteTCPUp,RemoteTCPDown,RemoteUDPUp,RemoteUDPDown" > "$TEST_FILE" fi while [ "$COUNTER" -lt "$NUM_TESTS" ]; do @@ -107,10 +107,44 @@ while [ "$COUNTER" -lt "$NUM_TESTS" ]; do packet_loss=$(ping -c $PING_COUNT -q $PING_TARGET | grep -oP '\d+(?=% packet loss)') jitter=$(ping -c $PING_COUNT $PING_TARGET | grep "time=" | awk '{print $(NF-1)}' | sed 's/time=//g' | awk '{sum+=$1; sumsq+=$1*$1} END {if (NR>1) print sqrt(sumsq/NR - (sum/NR)**2); else print 0}') + # 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 ' + 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' + } + + echo " Running iperf3 tests..." + + # Run them all. These are in bits per second, convert as needed later. + LocalTCPUp=$(run_iperf "$IPERF_LOCAL_TARGET" tcp up) + LocalTCPDown=$(run_iperf "$IPERF_LOCAL_TARGET" tcp down) + LocalUDPUp=$(run_iperf "$IPERF_LOCAL_TARGET" udp up) + LocalUDPDown=$(run_iperf "$IPERF_LOCAL_TARGET" udp down) + + RemoteTCPUp=$(run_iperf "$IPERF_REMOTE_TARGET" tcp up) + RemoteTCPDown=$(run_iperf "$IPERF_REMOTE_TARGET" tcp down) + RemoteUDPUp=$(run_iperf "$IPERF_REMOTE_TARGET" udp up) + RemoteUDPDown=$(run_iperf "$IPERF_REMOTE_TARGET" udp down) + END_TIME=$(date -Iseconds) # Log everything - echo "$START_TIME,$END_TIME,$link_level_noise,$bssid_and_bitrate,$speed_results,$FAILED_DELTA,$channel,$freq,$packet_loss,$jitter" >> "$TEST_FILE" + echo "$START_TIME,$END_TIME,$link_level_noise,$bssid_and_bitrate,$speed_results,$FAILED_DELTA,$channel,$freq,$packet_loss,$jitter,$LocalTCPUp,$LocalTCPDown,$LocalUDPUp,$LocalUDPDown,$RemoteTCPUp,$RemoteTCPDown,$RemoteUDPUp,$RemoteUDPDown" >> "$TEST_FILE" done if [ "$COUNTER" -lt "$NUM_TESTS" ]; then diff --git a/settings.env.default b/settings.env.default index 720dfc6..23a3e5f 100644 --- a/settings.env.default +++ b/settings.env.default @@ -17,4 +17,8 @@ PING_TARGET=1.1.1.1 MAX_RETRIES=5 RETRY_DELAY=10 # seconds +IPERF_LOCAL_TARGET= +IPERF_REMOTE_TARGET= +IPERF_DURATION=10 + RECIPIENT=