Skip to content

Commit

Permalink
name refactoring and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
javierajorge committed Oct 12, 2023
1 parent 6d4c609 commit 3d63187
Showing 1 changed file with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,34 @@ local network = require ("lime.network")
local hostname = utils.hostname()

function get_bat_links_info()
local batneights_obj={}
local batlinks_obj={}
local batlinks = utils.unsafe_shell("batctl oj")
batlinks_obj = JSON.parse(batlinks)
local bat_neighbors_obj={}
local bat_originators_obj={}
local bat_originators = utils.unsafe_shell("batctl oj")
bat_originators_obj = JSON.parse(bat_originators)


local batneights = utils.unsafe_shell("batctl nj")
batneights = string.gsub(batneights,"neigh_address","dst_mac")
batlinks = string.gsub(batlinks,"orig_address","src_mac")
batneights = string.gsub(batneights,"hard_ifname","iface")
batneights_obj = JSON.parse(batneights)
local bat_neighbors = utils.unsafe_shell("batctl nj")
bat_neighbors = string.gsub(bat_neighbors,"neigh_address","dst_mac")
bat_neighbors = string.gsub(bat_neighbors,"hard_ifname","iface")
bat_neighbors_obj = JSON.parse(bat_neighbors)

for key,neight_value in pairs (batneights_obj) do
for key,neight_value in pairs (bat_neighbors_obj) do
local macparts = network.get_mac(neight_value.iface)
local src_macaddr = table.concat(macparts,":")
neight_value.hard_ifindex=nil
neight_value.src_mac=src_macaddr
for key,link_value in pairs (batlinks_obj) do
if link_value.hard_ifname == neight_value.iface and
link_value.neigh_address== link_value.orig_address and
link_value.neigh_address== neight_value.dst_mac then
neight_value.tq = link_value.tq
for key,originator_value in pairs (bat_originators_obj) do
if originator_value.hard_ifname == neight_value.iface and
originator_value.neigh_address== originator_value.orig_address and
originator_value.neigh_address== neight_value.dst_mac then
-- Batman "transmit link quality" (tq) is a byte that describes
-- the probability of a successful transmission towards a
-- neighbor node
neight_value.tq = originator_value.tq
end
end
end
return batneights_obj
return bat_neighbors_obj
end

local result = { [hostname] = get_bat_links_info() }
Expand Down

0 comments on commit 3d63187

Please sign in to comment.