Skip to content

Commit

Permalink
shared_satate_bat_links: addss new key pair structure
Browse files Browse the repository at this point in the history
  • Loading branch information
javierajorge committed May 12, 2024
1 parent 727af91 commit 6d1d112
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ function get_bat_links_info()
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)

local kv_fromlinks = {}
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
neight_value.src_mac=string.lower(src_macaddr)
neight_value.dst_mac=string.lower(neight_value.dst_mac)
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
Expand All @@ -50,8 +51,11 @@ function get_bat_links_info()
neight_value.tq = originator_value.tq
end
end
local key_table = {(string.gsub(neight_value.src_mac,":","")),(string.gsub(neight_value.dst_mac,":",""))}
table.sort(key_table)
kv_fromlinks[table.concat(key_table)]=neight_value
end
return bat_neighbors_obj
return kv_fromlinks
end

local result = { [hostname] = get_bat_links_info() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,13 @@ 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.wlan0_mesh_mac,":"), links_info[1].src_mac)
assert.are.equal(table.concat(iwinfo.mocks.wlan1_mesh_mac,":"), links_info[4].src_mac)
assert.are.equal('02:58:47:da:4e:aa', links_info[1].dst_mac)
assert.are.equal(1040, links_info[1].last_seen_msecs)
assert.are.equal("wlan0-mesh_250", links_info[1].iface)
assert.are.equal(111, links_info[1].tq)
assert.are.equal(222, links_info[2].tq)
assert.are.equal(333, links_info[3].tq)
assert.are.equal(444, links_info[4].tq)
assert.are.equal(string.lower(table.concat(iwinfo.mocks.wlan0_mesh_mac,":")), links_info["025847462895c00000000000"].src_mac)
assert.are.equal(string.lower(table.concat(iwinfo.mocks.wlan1_mesh_mac,":")), links_info["02ab46da4eaac00000010101"].src_mac)
assert.are.equal('02:58:47:da:4e:aa', links_info["025847da4eaac00000000000"].dst_mac)
assert.are.equal(1250, links_info["025847462895c00000000000"].last_seen_msecs)
assert.are.equal("wlan0-mesh_250", links_info["025847462895c00000000000"].iface)
assert.are.equal(222, links_info["025847462895c00000000000"].tq)
assert.are.equal(333, links_info["02ab46da4eaac00000010101"].tq)
assert.are.equal(444, links_info["02ab46462895c00000010101"].tq)
end)
end)

0 comments on commit 6d1d112

Please sign in to comment.