LQM fixes 3 (#366)

This commit is contained in:
Tim Wilkinson 2022-05-22 19:06:02 -07:00 committed by GitHub
parent 754ced48b0
commit b680d2019e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 32 deletions

View File

@ -63,6 +63,7 @@ function get_config()
}
end
-- Connected if we have tracked this link recently
function is_connected(track)
if track.lastseen >= now then
return true
@ -71,11 +72,20 @@ function is_connected(track)
end
end
function should_block(track)
if now > track.pending then
return track.blocks.dtd or track.blocks.signal or track.blocks.distance or track.blocks.user or track.blocks.dup or track.blocks.quality
-- Pending if this link is too new
function is_pending(track)
if track.pending > now then
return true
else
return false
end
end
function should_block(track)
if is_pending(track) then
return track.blocks.dtd or track.blocks.user
else
return track.blocks.dtd or track.blocks.signal or track.blocks.distance or track.blocks.user or track.blocks.dup or track.blocks.quality
end
end
@ -115,7 +125,8 @@ function update_block(track)
return "unchanged"
end
function calcDistance(lat1, lon1, lat2, lon2)
-- Distance in meters between two points
function calc_distance(lat1, lon1, lat2, lon2)
local r2 = 12742000 -- diameter earth (meters)
local p = 0.017453292519943295 -- Math.PI / 180
local v = 0.5 - math.cos((lat2 - lat1) * p) / 2 + math.cos(lat1 * p) * math.cos(lat2 * p) * (1 - math.cos((lon2 - lon1) * p)) / 2
@ -278,7 +289,7 @@ function lqm()
track.last_tx = tx
track.last_tx_total = tx_total
track.last_quality = tx_quality
track.tx_quality = math.ceil(quality_run_avg * track.tx_quality + (1 - quality_run_avg) * tx_quality)
track.tx_quality = math.min(100, math.max(0, math.ceil(quality_run_avg * track.tx_quality + (1 - quality_run_avg) * tx_quality)))
end
track.tx_rate = station.tx_rate
@ -295,7 +306,7 @@ function lqm()
for _, track in pairs(tracker)
do
-- Only refresh remote attributes periodically
if track.ip and (now > track.refresh or track.pending > now) then
if track.ip and (now > track.refresh or is_pending(track)) then
track.refresh = now + refresh_timeout
local info = json.parse(luci.sys.httpget("http://" .. track.ip .. ":8080/cgi-bin/sysinfo.json?link_info=1&lqm=1"))
if info then
@ -303,7 +314,7 @@ function lqm()
track.lat = tonumber(info.lat)
track.lon = tonumber(info.lon)
if lat and lon then
track.distance = calcDistance(lat, lon, track.lat, track.lon)
track.distance = calc_distance(lat, lon, track.lat, track.lon)
end
end
local old_rev_snr = track.rev_snr
@ -391,7 +402,7 @@ function lqm()
-- potential routing issues and avoid any firewall blocks on the other end.
-- Take a penalty if we fail
if os.execute("/usr/sbin/arping -f -w " .. ping_timeout .. " -I " .. wlan .. " " .. track.ip .. " >/dev/null") ~= 0 then
track.tx_quality = math.max(0, math.ceil(track.tx_quality - config.ping_penalty))
track.tx_quality = math.min(100, math.max(0, math.ceil(track.tx_quality - config.ping_penalty)))
end
end
@ -557,26 +568,28 @@ function lqm()
-- Update the block state and calculate the routable distance
for _, track in pairs(tracker)
do
if update_block(track) == "unblocked" then
-- If the link becomes unblocked, return it to pending state
track.pending = now + pending_timeout
end
if is_connected(track) then
if update_block(track) == "unblocked" then
-- If the link becomes unblocked, return it to pending state
track.pending = now + pending_timeout
end
-- Find the most distant, unblocked, routable, node
if not track.blocked and track.distance then
if now > track.pending and track.routable then
if track.distance > distance then
distance = track.distance
end
else
if track.distance > alt_distance then
alt_distance = track.distance
-- Find the most distant, unblocked, routable, node
if not track.blocked and track.distance then
if not is_pending(track) and track.routable then
if track.distance > distance then
distance = track.distance
end
else
if track.distance > alt_distance then
alt_distance = track.distance
end
end
end
end
-- Remove any trackers which are too old
if now > track.lastseen + lastseen_timeout then
-- Remove any trackers which are too old or if they disconnect while still pending
if ((now > track.lastseen + lastseen_timeout) or (not is_connected(track) and is_pending(track))) then
track.blocked = true;
track.blocks = {}
update_block(track)

View File

@ -67,5 +67,5 @@ else
server = server .. ".local.mesh"
end
luci.sys.httpget("http://" .. server .. ":8080/cgi-bin/iperf?server=")
print("<html><head><title>iperf</title></head><body><body><pre>" .. io.popen("/usr/bin/iperf3 -b 0 -c " .. server .. (protocol == "udp" and " -u" or "") .. " 2>&1"):read("*a") .. "</pre></body></html>")
print("<html><head><title>iperf</title></head><body><pre>" .. io.popen("/usr/bin/iperf3 -b 0 -c " .. server .. (protocol == "udp" and " -u" or "") .. " 2>&1"):read("*a") .. "</pre></body></html>")
end

View File

@ -119,6 +119,9 @@ html.print([[<hr>
if (track.pending > data.info.now) {
return "pending";
}
if (track.lastseen < data.info.now) {
return "disconnected";
}
if (track.blocked) {
if (track.blocks.user) {
return "blocked - user";
@ -172,14 +175,16 @@ html.print([[<hr>
let txquality = "-";
let distance = "-";
let status = get_status(track, data);
if (status === "pending" || !track.blocked) {
txspeed = (track.tx_rate * wifi_scale).toFixed(2) + " Mbps";
}
if (typeof track.tx_quality === "number" && (status === "pending" || !track.blocked || (track.blocks.quality && !(track.blocks.dtd || track.blocks.signal || track.blocks.distance || track.blocks.user || track.blocks.dup)))) {
txquality = track.tx_quality + "%";
}
if (typeof track.distance === "number") {
distance = convertd(track.distance);
if (status !== "disconnected") {
if (status === "pending" || !track.blocked) {
txspeed = (track.tx_rate * wifi_scale).toFixed(2) + " Mbps";
}
if (typeof track.tx_quality === "number" && (status === "pending" || !track.blocked || (track.blocks.quality && !(track.blocks.dtd || track.blocks.signal || track.blocks.distance || track.blocks.user || track.blocks.dup)))) {
txquality = track.tx_quality + "%";
}
if (typeof track.distance === "number") {
distance = convertd(track.distance);
}
}
links += `<div><span class="m">${name(track)}</span><span class="s">${track.snr}${"rev_snr" in track ? "/" + track.rev_snr : ""}</span><span class="p">${distance}</span><span class="s">${txquality}</span><span class="p">${txspeed}</span><span class="p">${status}</span></div>`;
}

View File

@ -61,6 +61,7 @@ local files = {
"/tmp/manager.log",
"/tmp/manager.log.0",
"/tmp/AutoDistReset.log",
"/tmp/lqm.info",
"/sys/kernel/debug/ieee80211/phy0/ath9k/ack_to",
"/sys/kernel/debug/ieee80211/phy1/ath9k/ack_to",
"/etc/board.json"