From 692fc8e8c9ebe55bf333104a389658b5c8040d22 Mon Sep 17 00:00:00 2001 From: Tim Wilkinson Date: Mon, 6 Mar 2023 23:08:05 -0800 Subject: [PATCH] Improve error reporting when server is busy/disabled --- files/usr/lib/lua/aredn/nettools.lua | 45 ++++++++++++++++------------ files/www/cgi-bin/iperf | 8 +++-- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/files/usr/lib/lua/aredn/nettools.lua b/files/usr/lib/lua/aredn/nettools.lua index 481c7303..b2f1d7c2 100755 --- a/files/usr/lib/lua/aredn/nettools.lua +++ b/files/usr/lib/lua/aredn/nettools.lua @@ -124,38 +124,45 @@ function tools.getIperf3(target, protocol) local summary = { protocol = protocol, client = {}, server = {}, sender = {}, receiver = {} } local trace = {} -- start remote server - os.execute("wget -q 'http://" .. target .. ":8080/cgi-bin/iperf?server=' > /dev/null 2>&1") - local output = capture("/usr/bin/iperf3 -b 0 -c " .. target .. (protocol == "udp" and " -u" or "") .. " 2>&1") + local output = capture("/usr/bin/wget -q -O - 'http://localhost:8080/cgi-bin/iperf?server=" .. target .. "&protocol=" .. protocol .. "'") for _, line in ipairs(output:splitNewLine()) do - local chost, cport, shost, sport = line:match("local ([%d%.]+) port (%d+) connected to ([%d%.]+) port (%d+)") - if chost then - summary.client = { host = chost, port = tonumber(cport) } - summary.server = { host = shost, port = tonumber(sport) } + if line:match("CLIENT DISABLED") then + summary.error = "client disabled" + elseif line:match("SERVER DISABLED") then + summary.error = "server disabled" + elseif line:match("BUSY") then + summary.error = "busy" else - local from, to, transfer, tu, bitrate, bu, retr = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)%s+sender") - if from then - summary.sender = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), retr = tonumber(retr) } + local chost, cport, shost, sport = line:match("local ([%d%.]+) port (%d+) connected to ([%d%.]+) port (%d+)") + if chost then + summary.client = { host = chost, port = tonumber(cport) } + summary.server = { host = shost, port = tonumber(sport) } else - local from, to, transfer, tu, bitrate, bu = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+receiver") + local from, to, transfer, tu, bitrate, bu, retr = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)%s+sender") if from then - summary.receiver = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu) } + summary.sender = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), retr = tonumber(retr) } else - local from, to, transfer, tu, bitrate, bu, jitter, lost, total, percent = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+([%d%.]+) ms%s+(%d+)/(%d+) %(([%d%.]+)%%%)%s+sender") + local from, to, transfer, tu, bitrate, bu = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+receiver") if from then - summary.sender = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), jitterMs = tonumber(jitter), lostDgrams = tonumber(lost), totalDgrams = tonumber(total), lossPercentage = tonumber(precent) } + summary.receiver = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu) } else - local from, to, transfer, tu, bitrate, bu, jitter, lost, total, percent = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+([%d%.]+) ms%s+(%d+)/(%d+) %(([%d%.]+)%%%)%s+receiver") + local from, to, transfer, tu, bitrate, bu, jitter, lost, total, percent = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+([%d%.]+) ms%s+(%d+)/(%d+) %(([%d%.]+)%%%)%s+sender") if from then - summary.receiver = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), jitterMs = tonumber(jitter), lostDgrams = tonumber(lost), totalDgrams = tonumber(total), lossPercentage = tonumber(precent) } + summary.sender = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), jitterMs = tonumber(jitter), lostDgrams = tonumber(lost), totalDgrams = tonumber(total), lossPercentage = tonumber(precent) } else - local from, to, transfer, tu, bitrate, bu, retr, cwnd, cu = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)%s+([%d%.]+) ([KM])Bytes") + local from, to, transfer, tu, bitrate, bu, jitter, lost, total, percent = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+([%d%.]+) ms%s+(%d+)/(%d+) %(([%d%.]+)%%%)%s+receiver") if from then - trace[#trace + 1] = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, by), retr = tonumber(retr), cwndKB = toK(cwnd, cu) } + summary.receiver = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), jitterMs = tonumber(jitter), lostDgrams = tonumber(lost), totalDgrams = tonumber(total), lossPercentage = tonumber(precent) } else - local from, to, transfer, tu, bitrate, bu, dgrams = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)") + local from, to, transfer, tu, bitrate, bu, retr, cwnd, cu = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)%s+([%d%.]+) ([KM])Bytes") if from then - trace[#trace + 1] = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), dgrams = tonumber(dgrams) } + trace[#trace + 1] = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, by), retr = tonumber(retr), cwndKB = toK(cwnd, cu) } + else + local from, to, transfer, tu, bitrate, bu, dgrams = line:match("([%d%.]+)-([%d%.]+)%s+sec%s+([%d%.]+) ([KM])Bytes%s+([%d%.]+) ([MK])bits/sec%s+(%d+)") + if from then + trace[#trace + 1] = { from = tonumber(from), to = tonumber(to), transferMB = toM(transfer, tu), bitrateMb = toM(bitrate, bu), dgrams = tonumber(dgrams) } + end end end end diff --git a/files/www/cgi-bin/iperf b/files/www/cgi-bin/iperf index 3fb62290..541a3180 100755 --- a/files/www/cgi-bin/iperf +++ b/files/www/cgi-bin/iperf @@ -49,7 +49,7 @@ print "Cache-Control: no-store\r" print("Access-Control-Allow-Origin: *\r") print("\r") if uci.cursor():get("aredn", "@iperf[0]", "enable") == "0" then - print("DISABLED
iperf is disabled
") + print("CLIENT DISABLED
iperf is disabled
") elseif not server then print("
Provide a server name to run a test between this client and a server [/cgi-bin/iperf?server=<ServerName>&protocol=<udp|tcp>]
") elseif server:match("[^%w%-%.]") then @@ -72,12 +72,14 @@ else local f = io.popen("wget -q -O - 'http://" .. server .. ":8080/cgi-bin/iperf?server=' 2>&1") if f then status = f:read("*a") - f:close(); + f:close() end if status:match("running") then print("SUCCESS
Client: " .. node .. "\nServer: " .. server .. "\n" .. io.popen("p=$$;setsid sh -c \"(sleep 20; kill $p)\" > /dev/null 2>&1 & /usr/bin/iperf3 --forceflush -b 0 -Z -c " .. server .. (protocol == "udp" and " -u" or "") .. " 2>&1"):read("*a") .. "
") + elseif status:match("iperf is disabled") then + print("SERVER DISABLED
iperf server is disabled
") else - print("SERVER ERROR
iperf client failed to start server
") + print("SERVER ERROR
iperf server failed to start server
") end end end