uzbek-plus/b6j/aurora-modem-datatest

28 lines
2.6 KiB
Bash
Executable file

#!/bin/sh
# B6 data-path test through the bearer set up by aurora-modem start. Output dir $1. Uses only /32 routes (aurora-modem addroute).
O=${1:-/tmp/b6/dt}; mkdir -p $O; . /tmp/aurora-modem.d/ipcfg || { echo "DT: no ipcfg"; exit 1; }
CU="env LD_LIBRARY_PATH=/tmp/cu/usr/lib /tmp/cu/usr/bin/curl --cacert /tmp/cu/etc/ssl/certs/ca-certificates.crt --interface $IF -4 --connect-timeout 10 -sS"
W='code=%{http_code} remote=%{remote_ip}:%{remote_port} local=%{local_ip} ssl_verify=%{ssl_verify_result} t_total=%{time_total}\n'
D1=${DNS%%,*}
{ for n in ya.ru www.google.com; do echo "### nslookup $n $D1"; timeout 20 nslookup $n $D1 2>&1; done; } > $O/dns.txt
ips() { awk -v n="$1" '/^### nslookup/{c=($3==n)} c && /^Address[^:]*: *[0-9.]+$/{print $NF}' $O/dns.txt | grep -v "^$D1$" | sort -u | head -2; }
YA=$(ips ya.ru); GO=$(ips www.google.com); YA1=$(echo $YA | cut -d' ' -f1); GO1=$(echo $GO | cut -d' ' -f1)
for y in $YA $GO; do sh /tmp/aurora-modem addroute $y; done
{ echo "ya.ru=$YA google=$GO"; for h in 77.88.8.8 $YA1 172.16.42.2 8.8.4.4; do echo "--- route get $h: $(ip route get $h 2>&1 | head -1)"; done; } > $O/routes.txt
{ for h in 77.88.8.8 1.1.1.1; do echo "### ping $h"; ping -c 3 -W 3 $h 2>&1; done; } > $O/ping.txt
Y=$(date -u +%Y)
{ echo "### http://ya.ru/"; timeout 40 $CU --resolve ya.ru:80:$YA1 -o /dev/null -w "$W" http://ya.ru/ 2>&1; echo "rc=$?"
if [ "$Y" -ge 2026 ]; then
echo "### https://www.google.com/generate_204"; timeout 40 $CU --resolve www.google.com:443:$GO1 -o /dev/null -w "$W" https://www.google.com/generate_204 2>&1; echo "rc=$?"
echo "### https://1.1.1.1/cdn-cgi/trace"; timeout 40 $CU -o /dev/null -w "$W" https://1.1.1.1/cdn-cgi/trace 2>&1; echo "rc=$?"
else echo "### HTTPS skipped: clock year $Y (not a cellular failure)"; fi; } > $O/http.txt
DNSOK=$([ -n "$YA1" ] && [ -n "$GO1" ] && echo 1 || echo 0)
PING=$(grep -oE "[0-9]+ packets received" $O/ping.txt | cut -d' ' -f1 | tr '\n' '+'); PING=${PING%+}
PINGOK=$(grep -qE "[1-9][0-9]* packets received" $O/ping.txt && echo 1 || echo 0)
HTTP=$(grep -A1 "^### http://" $O/http.txt | grep -oE "code=[0-9]+" | head -1)
HTTPS=$(grep -oE "code=[0-9]+" $O/http.txt | tail -n +2 | tr '\n' ' ')
HTTPOK=$(echo "$HTTP" | grep -qE "code=[1-5][0-9][0-9]" && echo 1 || echo 0)
if [ "$Y" -ge 2026 ]; then echo "$HTTPS" | grep -q "code=204" && echo "$HTTPS" | grep -q "code=200" && HTTPSOK=1 || HTTPSOK=0; else HTTPSOK=skip; fi
V=FAIL; [ $DNSOK$PINGOK$HTTPOK = 111 ] && [ "$HTTPSOK" != 0 ] && V=PASS
echo "DATATEST $V dns=$DNSOK(ya=$YA1 go=$GO1) ping=$PING http=$HTTP https=[$HTTPS]($HTTPSOK) if=$IF addr=$A" | tee $O/verdict.txt
[ $V = PASS ]