#!/usr/bin/env bash
set -euo pipefail
transport=${1:-stcp}; profile=${2:-leo}
case "$transport" in stcp|tcp) ;; *) exit 2;; esac
case "$profile" in leo) count=1024; runs=5; limit=180;; meo) count=1024; runs=5; limit=300;; geo) count=64; runs=3; limit=600;; deep) count=16; runs=3; limit=900;; *) exit 2;; esac
bench=${BENCH:-/opt/stcp/stcp_tcp_path_bench}
mkdir -p "$HOME/stcp-satellite/logs"
log="$HOME/stcp-satellite/logs/$profile-$transport-$(date +%Y%m%d-%H%M%S).log"
# Configure both endpoints and start the matching server before running.
failed=0
for ((i=1;i<=runs;i++)); do
 echo "=== $transport $profile RUN $i/$runs ==="
 date -Ins
 rc=0; timeout "$limit" "$bench" client "$transport" 192.0.2.20 19953 16384 "$count" 1 || rc=$?
 echo "EXIT=$rc"; if ((rc)); then failed=1; fi
 sudo tc -s qdisc show dev ifb-sat-rx
 sleep 2
done > >(tee "$log") 2>&1
exit "$failed"
