#!/usr/bin/lua
--[[
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
Copyright (C) 2022 Tim Wilkinson
See Contributors file for additional contributors
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see
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 print("
Illegal server name") else if server == "" then -- iperf server if kill then os.execute("/usr/bin/killall -9 iperf3 > /dev/null 2>&1") else if io.popen("/bin/pidof iperf3"):read("*a") ~= "" then print("
iperf server busy") return end end local first = true local running = io.popen("/usr/bin/iperf3 -s -1 --idle-timeout 20 --forceflush -B 0.0.0.0") if not running then print("
iperf server failed to start") return end running:read("*l") print("
iperf server running") io.flush() return else -- iperf client if not server:match("%.") then server = server .. ".local.mesh" end local ip = iplookup(server) if not ip then print("
iperf no such server") else local remote = io.popen("/usr/bin/wget -O - 'http://" .. ip .. ":8080/cgi-bin/iperf?" .. (kill and "kill=1&" or "") .. "server=' 2>&1") if not remote then print("
iperf failed to call remote server") return end while true do local line = remote:read("*l") if not line then print("
iperf unknown error") break elseif line:match("CLIENT DISABLED") then print("
iperf server is disabled") break elseif line:match("BUSY") then print("
iperf server is busy") break elseif line:match("ERROR") then print("
iperf server error") break elseif line:match("RUNNING") then local running = io.popen("/usr/bin/iperf3 --forceflush --rcv-timeout 20000 -b 0 -Z -c " .. ip .. (protocol == "udp" and " -u" or "") .. " -l 16K 2>&1") if not running then print("
iperf client failed") break end print("
Client: " .. node .. "\nServer: " .. server) io.flush() for line in running:lines() do print(line) io.flush() end running:close() print("") break end end remote:close() end end end