Skip to content

Commit

Permalink
Ref_state: removes unnecessary locations
Browse files Browse the repository at this point in the history
  • Loading branch information
javierajorge committed Jul 3, 2024
1 parent a9224f9 commit bb44561
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
-- !
-- ! You should have received a copy of the GNU Affero General Public License
-- ! along with this program. If not, see <http://www.gnu.org/licenses/>.

local JSON = require("luci.jsonc")
local node_status = require("lime.node_status")
local network = require("lime.network")
Expand All @@ -35,8 +34,6 @@ function get_wifi_links_info()
local key_table = {string.lower(string.gsub(src_macaddr, ":", "")),
string.lower(string.gsub(station.station_mac, ":", ""))}
table.sort(key_table)
local src_loc = location.get_node() or location.get_community() or {
lat = "FIXME",long = "FIXME" }
links[table.concat(key_table)] = {
src_mac = src_macaddr,
dst_mac = string.lower(station.station_mac),
Expand All @@ -46,21 +43,28 @@ function get_wifi_links_info()
rx_rate = station_stats.rx_rate,
tx_rate = station_stats.tx_rate,
freq = freq,
channel = chanenel,
src_loc = src_loc
channel = chanenel

This comment has been minimized.

Copy link
@G10h4ck

G10h4ck Jul 4, 2024

Member

lets fix that chanenel too ;)

}
end
return links
return {
links = links,
src_loc = location.get_node() or location.get_community() or {
lat = "FIXME",
long = "FIXME"
}
}
end

function add_dst_loc(links_info, shared_state_sample, hostname)
for link, l_data in pairs(links_info) do
for node, data in pairs(shared_state_sample) do
if node ~= hostname then
local link_data = data[link]
if link_data ~= nil then
if link_data.src_mac == l_data.dst_mac then
l_data.dst_loc = link_data.src_loc
if shared_state_sample ~= nil then
for link, l_data in pairs(links_info.links) do
for node, data in pairs(shared_state_sample) do
if node ~= hostname and data.links ~= nil then
local link_data = data.links[link]
if link_data ~= nil then
if link_data.src_mac == l_data.dst_mac then
l_data.dst_loc = data.src_loc
end
end
end
end
Expand All @@ -72,5 +76,7 @@ local hostname = io.input("/proc/sys/kernel/hostname"):read("*line")
local links_info = get_wifi_links_info()
local shared_state_sample = JSON.parse(io.popen("shared-state-async get wifi_links_info", "r"):read('*all'))
add_dst_loc(links_info, shared_state_sample, hostname)
local result = {[hostname] = links_info}
local result = {
[hostname] = links_info

This comment has been minimized.

Copy link
@G10h4ck

G10h4ck Jul 4, 2024

Member

what does this [hostname] syntax means?

This comment has been minimized.

Copy link
@javierbrk

javierbrk Jul 8, 2024

Collaborator

this creates the final info table that is going to be inserted into the table. The hostname is the first key to insert information. The output is something like

"cheche": {
        "src_loc": {
            "long": "-64.4228178",
            "lat": "-31.8019512"
        },
        "links": []
    },
    "tito": {
        "src_loc": {
            "long": "-64.41095",
            "lat": "-31.71857"
        },
}
io.popen("shared-state-async insert wifi_links_info", "w"):write(JSON.stringify(result))
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local JSON = require("luci.jsonc")


local shared_state_output_text = [[
{"LiMe-462895":{"c00000010101c04a00be7b0a":{"src_loc":{"long":"FYI","lat":"FYI"},"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-46,-43],"signal":-42,"rx_rate":300000,"src_mac":"c0:4a:00:be:7b:0a"},"a6f3c1462897ae40411c8516":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-54,-54],"signal":-51,"rx_rate":300000,"src_mac":"a6:f3:c1:46:28:97"},"a6f3c1462897c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":180000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-65,-63],"signal":-61,"rx_rate":270000,"src_mac":"a6:f3:c1:46:28:97"},"a6f3c1462896c64a00fc3abe":{"freq":2462,"iface":"wlan0-mesh","tx_rate":144400,"dst_mac":"c6:4a:00:fc:3a:be","channel":11,"chains":[-51,-40],"signal":-40,"rx_rate":144400,"src_mac":"a6:f3:c1:46:28:96"}},"LiMe-b713f7":{"a6f3c1462897ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-53,-53],"signal":-50,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:35"},"ae40411c85c3ae40411df934":{"freq":5785,"iface":"wlan2-mesh","tx_rate":150000,"dst_mac":"ae:40:41:1c:85:c3","channel":157,"chains":[-51,-36],"signal":-36,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:34"},"ae40411df935c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-58,-63],"signal":-57,"rx_rate":240000,"src_mac":"ae:40:41:1d:f9:35"},"ae40411c8516ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-58,-70],"signal":-57,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:35"}},"LiMe-fc3abd":{"ae40411df935c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-48,-46],"signal":-44,"rx_rate":300000,"src_mac":"c6:4a:00:fc:3a:bf"},"ae40411c8516c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":150000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-67,-63],"signal":-62,"rx_rate":270000,"src_mac":"c6:4a:00:fc:3a:bf"},"a6f3c1462897c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-64,-67],"signal":-63,"rx_rate":180000,"src_mac":"c6:4a:00:fc:3a:bf"},"a6f3c1462896c64a00fc3abe":{"freq":2462,"iface":"wlan0-mesh","tx_rate":144400,"dst_mac":"a6:f3:c1:46:28:96","channel":11,"chains":[-53,-45],"signal":-44,"rx_rate":130000,"src_mac":"c6:4a:00:fc:3a:be"}},"cheche":{"ae40411c8516ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-55,-59],"signal":-54,"rx_rate":243000,"src_mac":"ae:40:41:1c:85:16"},"ae40411c85c3ae40411df934":{"freq":5785,"iface":"wlan2-mesh","tx_rate":270000,"dst_mac":"ae:40:41:1d:f9:34","channel":157,"chains":[-40,-31],"signal":-30,"rx_rate":150000,"src_mac":"ae:40:41:1c:85:c3"},"a6f3c1462897ae40411c8516":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-56,-58],"signal":-54,"rx_rate":180000,"src_mac":"ae:40:41:1c:85:16"},"ae40411c8516c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":270000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-73,-75],"signal":-71,"rx_rate":90000,"src_mac":"ae:40:41:1c:85:16"}}}
{"LiMe-462895":{"src_loc":{"lat":"FYI","long":"FYI"},"links":{"c00000010101c04a00be7b0a":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-46,-43],"signal":-42,"rx_rate":300000,"src_mac":"c0:4a:00:be:7b:0a"},"a6f3c1462897ae40411c8516":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-54,-54],"signal":-51,"rx_rate":300000,"src_mac":"a6:f3:c1:46:28:97"},"a6f3c1462897c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":180000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-65,-63],"signal":-61,"rx_rate":270000,"src_mac":"a6:f3:c1:46:28:97"},"a6f3c1462896c64a00fc3abe":{"freq":2462,"iface":"wlan0-mesh","tx_rate":144400,"dst_mac":"c6:4a:00:fc:3a:be","channel":11,"chains":[-51,-40],"signal":-40,"rx_rate":144400,"src_mac":"a6:f3:c1:46:28:96"}}},"LiMe-b713f7":{"a6f3c1462897ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-53,-53],"signal":-50,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:35"},"ae40411c85c3ae40411df934":{"freq":5785,"iface":"wlan2-mesh","tx_rate":150000,"dst_mac":"ae:40:41:1c:85:c3","channel":157,"chains":[-51,-36],"signal":-36,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:34"},"ae40411df935c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-58,-63],"signal":-57,"rx_rate":240000,"src_mac":"ae:40:41:1d:f9:35"},"ae40411c8516ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-58,-70],"signal":-57,"rx_rate":300000,"src_mac":"ae:40:41:1d:f9:35"}},"LiMe-fc3abd":{"ae40411df935c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-48,-46],"signal":-44,"rx_rate":300000,"src_mac":"c6:4a:00:fc:3a:bf"},"ae40411c8516c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":150000,"dst_mac":"ae:40:41:1c:85:16","channel":48,"chains":[-67,-63],"signal":-62,"rx_rate":270000,"src_mac":"c6:4a:00:fc:3a:bf"},"a6f3c1462897c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-64,-67],"signal":-63,"rx_rate":180000,"src_mac":"c6:4a:00:fc:3a:bf"},"a6f3c1462896c64a00fc3abe":{"freq":2462,"iface":"wlan0-mesh","tx_rate":144400,"dst_mac":"a6:f3:c1:46:28:96","channel":11,"chains":[-53,-45],"signal":-44,"rx_rate":130000,"src_mac":"c6:4a:00:fc:3a:be"}},"cheche":{"ae40411c8516ae40411df935":{"freq":5240,"iface":"wlan1-mesh","tx_rate":240000,"dst_mac":"ae:40:41:1d:f9:35","channel":48,"chains":[-55,-59],"signal":-54,"rx_rate":243000,"src_mac":"ae:40:41:1c:85:16"},"ae40411c85c3ae40411df934":{"freq":5785,"iface":"wlan2-mesh","tx_rate":270000,"dst_mac":"ae:40:41:1d:f9:34","channel":157,"chains":[-40,-31],"signal":-30,"rx_rate":150000,"src_mac":"ae:40:41:1c:85:c3"},"a6f3c1462897ae40411c8516":{"freq":5240,"iface":"wlan1-mesh","tx_rate":300000,"dst_mac":"a6:f3:c1:46:28:97","channel":48,"chains":[-56,-58],"signal":-54,"rx_rate":180000,"src_mac":"ae:40:41:1c:85:16"},"ae40411c8516c64a00fc3abf":{"freq":5240,"iface":"wlan1-mesh","tx_rate":270000,"dst_mac":"c6:4a:00:fc:3a:bf","channel":48,"chains":[-73,-75],"signal":-71,"rx_rate":90000,"src_mac":"ae:40:41:1c:85:16"}}}
]]

package.path = package.path .. ";packages/shared-state-wifi_links_info/files/usr/share/shared-state/publishers/?;;"
Expand All @@ -30,16 +30,18 @@ it('a simple test to get links info and assert requiered fields are present', fu
local links_info = {}

links_info = get_wifi_links_info()
assert.is.equal(26000, links_info["c00000000000c04a00be7b09"].tx_rate)
assert.is.equal("c0:4a:00:be:7b:09", links_info["c00000000000c04a00be7b09"].dst_mac)
assert.is.same({-17,-18}, links_info["c00000000000c04a00be7b09"].chains)
assert.is.equal(-14, links_info["c00000000000c04a00be7b09"].signal)
assert.is.equal("wlan0-mesh", links_info["c00000000000c04a00be7b09"].iface)
assert.is.equal(13000, links_info["c00000000000c04a00be7b09"].rx_rate)
assert.is.equal(2400, links_info["c00000000000c04a00be7b09"].freq)
assert.is.equal("c0:00:00:00:00:00", links_info["c00000000000c04a00be7b09"].src_mac)
assert.is.equal(26000, links_info.links["c00000000000c04a00be7b09"].tx_rate)
assert.is.equal("c0:4a:00:be:7b:09", links_info.links["c00000000000c04a00be7b09"].dst_mac)
assert.is.same({-17,-18}, links_info.links["c00000000000c04a00be7b09"].chains)
assert.is.equal(-14, links_info.links["c00000000000c04a00be7b09"].signal)
assert.is.equal("wlan0-mesh", links_info.links["c00000000000c04a00be7b09"].iface)
assert.is.equal(13000, links_info.links["c00000000000c04a00be7b09"].rx_rate)
assert.is.equal(2400, links_info.links["c00000000000c04a00be7b09"].freq)
assert.is.equal("c0:00:00:00:00:00", links_info.links["c00000000000c04a00be7b09"].src_mac)
end)



it('a simple test to get location info', function()
stub(utils, "unsafe_shell", function (cmd)
if string.match(cmd, "wlan0") then
Expand All @@ -60,19 +62,19 @@ it('a simple test to get location info', function()

links_info = get_wifi_links_info()
local hostname = io.input("/proc/sys/kernel/hostname"):read("*line")
local shared_state_sample = JSON.parse(shared_state_output_text)
assert.is.equal(nil, links_info["c00000010101c04a00be7b0a"].dst_loc)
add_dst_loc(links_info,shared_state_sample)
assert.is.equal("FYI", links_info["c00000010101c04a00be7b0a"].dst_loc.lat)
local shared_state_sample_s = JSON.parse(shared_state_output_text)
assert.is.equal(nil, links_info.links["c00000010101c04a00be7b0a"].dst_loc)
add_dst_loc(links_info,shared_state_sample_s,"sdfsdf")
assert.is.equal("FYI", links_info.links["c00000010101c04a00be7b0a"].dst_loc.lat)
local links_info = {}

links_info = get_wifi_links_info()
local hostname = io.input("/proc/sys/kernel/hostname"):read("*line")
--asume shared state has just initialized
local shared_state_sample = JSON.parse("{}")
assert.is.equal(nil, links_info["c00000010101c04a00be7b0a"].dst_loc)
assert.is.equal(nil, links_info.links["c00000010101c04a00be7b0a"].dst_loc)
add_dst_loc(links_info,shared_state_sample)
assert.is.equal(nil, links_info["c00000010101c04a00be7b0a"].dst_loc)
assert.is.equal("c0:00:00:00:00:00", links_info["c00000000000c04a00be7b09"].src_mac)
assert.is.equal(nil, links_info.links["c00000010101c04a00be7b0a"].dst_loc)
assert.is.equal("c0:00:00:00:00:00", links_info.links["c00000000000c04a00be7b09"].src_mac)

end)

0 comments on commit bb44561

Please sign in to comment.