mirror of https://github.com/aredn/aredn.git
api: add RF IP for non-RF links (#124)
* api: add RF IP for non-RF links Add the RF IP address for non-RF linked devices. This allows the services to be displayed for non-RF Current Neighbors. * remove case manipulation
This commit is contained in:
parent
d595b9cf3d
commit
e93987fe06
|
@ -327,8 +327,8 @@ function model.all_hosts()
|
|||
local ip, name=string.match(data,"^([%x%.%:]+)%s+(%S.*)\t%s*$")
|
||||
if ip and name then
|
||||
if not string.match(name,"^(dtdlink[.]).*") then
|
||||
if not string.match(name,"^(mid[0-9][.]).*") then
|
||||
host['name']=name:upper()
|
||||
if not string.match(name,"^(mid%d+[.]).*") then
|
||||
host['name']=name
|
||||
host['ip']=ip
|
||||
table.insert(hosts,host)
|
||||
end
|
||||
|
@ -517,7 +517,7 @@ function model.getLocalCnxType(hostname)
|
|||
return "Loopback"
|
||||
elseif string.match(hostname,"dtdlink") then
|
||||
return "DTD"
|
||||
elseif hostname == string.lower( model.getNodeName() ) then
|
||||
elseif hostname:lower() == string.lower( model.getNodeName() ) then
|
||||
return "RF"
|
||||
else
|
||||
return "LAN"
|
||||
|
@ -531,9 +531,7 @@ function model.getLocalHosts()
|
|||
local hosts, line
|
||||
if nixio.fs.access("/etc/hosts") then
|
||||
for line in io.lines("/etc/hosts") do
|
||||
line = line:lower()
|
||||
-- line is not a comment
|
||||
local data = line:match("^([^#;]+)[#;]*(.*)$")
|
||||
local data = line:match("^([^#;]+)[#;]*(.*)$") -- line is not a comment
|
||||
if data then
|
||||
local hostname, entries
|
||||
local ip, entries = data:match("^%s*([%[%]%x%.%:]+)%s+(%S.-%S)%s*$")
|
||||
|
@ -548,7 +546,7 @@ function model.getLocalHosts()
|
|||
for hostname in entries:gmatch("%S+") do
|
||||
hostname = string.gsub(hostname,".local.mesh$","")
|
||||
entry["cnxtype"] = model.getLocalCnxType(hostname)
|
||||
entry["hostnames"][index] = hostname:upper()
|
||||
entry["hostnames"][index] = hostname
|
||||
index = index + 1
|
||||
end
|
||||
hosts = hosts or { }
|
||||
|
|
|
@ -66,55 +66,61 @@ end
|
|||
function model.getCurrentNeighbors(RFinfo)
|
||||
local RFinfo = RFinfo or false
|
||||
local info={}
|
||||
local links=model.getOLSRLinks()
|
||||
local links=model.getOLSRLinks() -- Get info for all current neighbors
|
||||
for k,v in pairs(links) do
|
||||
local host
|
||||
local remip=v['remoteIP']
|
||||
local remhost=nslookup(remip)
|
||||
info[remip]={}
|
||||
info[remip]['olsrInterface']=v['olsrInterface']
|
||||
info[remip]['linkType']= model.getOLSRInterfaceType(v['olsrInterface']) -- RF or DTD or TUN
|
||||
info[remip]['linkQuality']=v['linkQuality']
|
||||
info[remip]['neighborLinkQuality']=v['neighborLinkQuality']
|
||||
if remhost ~= nil then
|
||||
host = string.lower(remhost)
|
||||
end
|
||||
if host ~= nil then
|
||||
host = string.gsub(host,"mid%d+.", "")
|
||||
local linkip=v['remoteIP']
|
||||
|
||||
info[linkip]={}
|
||||
info[linkip]['olsrInterface']=v['olsrInterface']
|
||||
info[linkip]['linkType']= model.getOLSRInterfaceType(v['olsrInterface']) -- RF or DTD or TUN
|
||||
info[linkip]['linkQuality']=v['linkQuality']
|
||||
info[linkip]['neighborLinkQuality']=v['neighborLinkQuality']
|
||||
|
||||
local linkhost=nslookup(linkip) -- TOTO: stop using nslookup? use /var/run/olsr_hosts
|
||||
if linkhost~=nil then
|
||||
host = string.gsub(linkhost,"mid%d+.", "")
|
||||
host = string.gsub(host,"dtdlink%.", "")
|
||||
host = string.gsub(host,".local.mesh$","")
|
||||
info[remip]['hostname']=host
|
||||
else
|
||||
info[remip]['hostname']=remip
|
||||
end
|
||||
|
||||
if info[remip]['linkType'] == "RF" and RFinfo then
|
||||
-- get additional info for RF link
|
||||
require("iwinfo")
|
||||
info[linkip]['hostname']=host
|
||||
else
|
||||
info[linkip]['hostname']=linkip
|
||||
end
|
||||
|
||||
if info[linkip]['linkType'] == "RF" and RFinfo then -- get additional info for RF link
|
||||
require("iwinfo")
|
||||
info[linkip]["rfip"] = linkip
|
||||
local radio = ai.getMeshRadioDevice()
|
||||
local bandwidth = tonumber(ai.getChannelBW(radio))
|
||||
local wlan=get_ifname('wifi')
|
||||
local RFneighbors=iwinfo['nl80211'].assoclist(wlan)
|
||||
local mac2node=mac2host()
|
||||
for i, mac_host in pairs(mac2node) do
|
||||
local mac=string.match(mac_host, "^(.-)\-")
|
||||
mac=mac:upper()
|
||||
local node=string.match(mac_host, "\-(.*)")
|
||||
if host == node or remip == node then
|
||||
for stn in pairs(RFneighbors) do
|
||||
stnInfo=iwinfo['nl80211'].assoclist(wlan)[mac]
|
||||
if stnInfo ~= nil then
|
||||
info[remip]["signal"]=tonumber(stnInfo.signal)
|
||||
info[remip]["noise"]=tonumber(stnInfo.noise)
|
||||
info[remip]["tx_rate"]=adjust_rate(stnInfo.tx_rate/1000,bandwidth)
|
||||
info[remip]["rx_rate"]=adjust_rate(stnInfo.rx_rate/1000,bandwidth)
|
||||
info[remip]["expected_throughput"]=adjust_rate(stnInfo.expected_throughput/1000,bandwidth)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
local wlan=get_ifname('wifi')
|
||||
local RFneighbors=iwinfo['nl80211'].assoclist(wlan)
|
||||
local mac2node=mac2host()
|
||||
for i, mac_host in pairs(mac2node) do
|
||||
local mac=string.match(mac_host, "^(.-)\-")
|
||||
mac=mac:upper()
|
||||
local node=string.match(mac_host, "\-(.*)") -- add error checking here?
|
||||
if node == "" then node=linkhost end
|
||||
if linkhost == node or linkip == node then
|
||||
for stn in pairs(RFneighbors) do
|
||||
stnInfo=iwinfo['nl80211'].assoclist(wlan)[mac]
|
||||
if stnInfo ~= nil then
|
||||
info[linkip]["signal"]=tonumber(stnInfo.signal)
|
||||
info[linkip]["noise"]=tonumber(stnInfo.noise)
|
||||
info[linkip]["tx_rate"]=adjust_rate(stnInfo.tx_rate/1000,bandwidth)
|
||||
info[linkip]["rx_rate"]=adjust_rate(stnInfo.rx_rate/1000,bandwidth)
|
||||
info[linkip]["expected_throughput"]=adjust_rate(stnInfo.expected_throughput/1000,bandwidth)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else -- Get RF IP for non-RF nodes to display services keyed to RF IP
|
||||
local allhosts=ai.all_hosts()
|
||||
for k,v in pairs(allhosts) do
|
||||
if linkhost == v['name'] or host == v['name'] then
|
||||
info[linkip]["rfip"]=v['ip']
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return info
|
||||
end
|
||||
|
|
|
@ -132,7 +132,7 @@ function getRemoteNodes()
|
|||
local node={}
|
||||
-- skip currentneighbors, myself, and MID*. entries
|
||||
for cnk, cnv in pairs(cn) do
|
||||
if not (cnk == allhosts[k].ip or allhosts[k].name == mynode or (allhosts[k].name:match("^MID%d+%.") ~= nil)) then
|
||||
if not (cnk == allhosts[k].ip or allhosts[k].name == mynode or (allhosts[k].name:match("^mid%d+%.") ~= nil)) then
|
||||
node=allhosts[k]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue