Skip to content

Commit

Permalink
add link tq parameter and optional best indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrk committed Oct 4, 2023
1 parent 18d70c7 commit 6817c8c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ local network = require ("lime.network")
local hostname = utils.hostname()
function get_bat_links_info()
local batneights_obj={}
local batneights = utils.unsafe_shell("batctl nj")
local batneights = utils.unsafe_shell("batctl oj")
batneights = string.gsub(batneights,"neigh_address","dst_mac")
batneights = string.gsub(batneights,"orig_address","src_mac")
batneights = string.gsub(batneights,"hard_ifname","iface")
batneights_obj = JSON.parse(batneights)
for key,value in pairs (batneights_obj) do
macparts = network.get_mac(value.iface)
src_macaddr = table.concat(macparts,":")
value.hard_ifindex=nil
value.src_mac=src_macaddr
end
return batneights_obj
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,33 @@ local iwinfo = require "iwinfo"


describe('Tests bat_links_info #bat_links_info', function ()

oj_output = [[
[{"hard_ifindex":28,"hard_ifname":"wlan1-mesh_250","orig_address":
"02:95:39:46:28:95","last_seen_msecs":20,"neigh_address":
"02:ab:46:da:4e:aa","tq":222},{"hard_ifindex":26,"hard_ifname":
"wlan0-mesh_250","orig_address":"02:95:39:46:28:95","last_seen_msecs":
20,"neigh_address":"02:58:47:da:4e:aa","tq":0},{"hard_ifindex":28,
"hard_ifname":"wlan1-mesh_250","orig_address":"02:95:39:46:28:95",
"best":true,"last_seen_msecs":20,"neigh_address":"02:ab:46:46:28:95",
"tq":251},{"hard_ifindex":26,"hard_ifname":"wlan0-mesh_250","orig_address"
:"02:95:39:46:28:95","last_seen_msecs":20,"neigh_address":
"02:58:47:46:28:95","tq":239},{"hard_ifindex":26,"hard_ifname":
"wlan0-mesh_250","orig_address":"02:58:47:da:4e:aa","last_seen_msecs":
1260,"neigh_address":"02:58:47:46:28:95","tq":179},{"hard_ifindex":26,
"hard_ifname":"wlan0-mesh_250","orig_address":"02:58:47:da:4e:aa","best"
:true,"last_seen_msecs":1260,"neigh_address":"02:58:47:da:4e:aa","tq":
255},{"hard_ifindex":28,"hard_ifname":"wlan1-mesh_250","orig_address":
"02:95:39:da:4e:aa","last_seen_msecs":1100,"neigh_address":
"02:ab:46:46:28:95","tq":214},{"hard_ifindex":26,"hard_ifname":
"wlan0-mesh_250","orig_address":"02:95:39:da:4e:aa","last_seen_msecs":
1100,"neigh_address":"02:58:47:46:28:95","tq":0},{"hard_ifindex":28,
"hard_ifname":"wlan1-mesh_250","orig_address":"02:95:39:da:4e:aa","best":
true,"last_seen_msecs":1100,"neigh_address":"02:ab:46:da:4e:aa","tq":255}]
]]

stub(utils, "unsafe_shell", function (cmd)
return '[{"hard_ifindex":26,"hard_ifname":"wlan0-mesh_250","last_seen_msecs":1990,"neigh_address":"02:58:47:da:4e:aa"},{"hard_ifindex":26,"hard_ifname":"wlan0-mesh_250","last_seen_msecs":1690,"neigh_address":"02:58:47:46:28:95"},{"hard_ifindex":28,"hard_ifname":"wlan1-mesh_250","last_seen_msecs":1510,"neigh_address":"02:ab:46:da:4e:aa"},{"hard_ifindex":28,"hard_ifname":"wlan1-mesh_250","last_seen_msecs":970,"neigh_address":"02:ab:46:46:28:95"}]'
return oj_output
end)
stub(network, "get_mac", function (iface)
return iwinfo.mocks.wlan1_mesh_mac
Expand All @@ -18,9 +43,11 @@ describe('Tests bat_links_info #bat_links_info', function ()
it('a simple test to get node info and assert requiered fields are present', function()
local links_info = {}
links_info = get_bat_links_info()
assert.are.equal(table.concat(iwinfo.mocks.wlan1_mesh_mac,":"), links_info[1].src_mac)
assert.are.equal('02:58:47:da:4e:aa', links_info[1].dst_mac)
assert.are.equal(1990, links_info[1].last_seen_msecs)
assert.are.equal("wlan0-mesh_250", links_info[1].iface)
assert.are.equal('02:95:39:46:28:95', links_info[1].src_mac)
assert.are.equal('02:ab:46:da:4e:aa', links_info[1].dst_mac)
assert.are.equal(20, links_info[1].last_seen_msecs)
assert.are.equal("wlan1-mesh_250", links_info[1].iface)
assert.are.equal(222, links_info[1].tq)

end)
end)

0 comments on commit 6817c8c

Please sign in to comment.