Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared-state mesh information packages async implmentation and reference state #1112

Merged
merged 47 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
97c6e58
shared-state: moving to async
javierajorge Apr 16, 2024
9221be5
Merge branch 'libremesh:master' into moving_to_async
javierbrk Apr 25, 2024
5a36c2c
shared-state-async: Removes cron task
javierajorge May 9, 2024
9ab43ff
shared-state-async: move publishers to new location
javierajorge May 9, 2024
6d1d112
shared_satate_bat_links: addss new key pair structure
javierajorge May 12, 2024
8cceccc
adds hook to insert config
javierajorge May 12, 2024
1f72404
fixes typo
javierajorge May 12, 2024
ccfd634
bat_links_info_ref: adds data type registration
javierajorge May 12, 2024
b53b37d
ref_state: add babel and missing bat links reference state
javierajorge May 12, 2024
e686037
ref_state: adds key index to links
javierajorge May 12, 2024
825e1a5
Merge branch 'libremesh:master' into moving_to_async
javierbrk May 12, 2024
331e5f0
shared-state: fiexes broken tests
javierajorge May 12, 2024
4f5c936
shared-state: adds wifi key to info data type
javierajorge May 12, 2024
f9054bc
ref_state: implements commons package
javierajorge May 12, 2024
2495b39
Merge branch 'moving_to_async' into f/reference_state
javierajorge May 12, 2024
991fa73
ref_state: implement publishser
javierajorge May 12, 2024
f4d2124
ref_state: improve doc
javierajorge May 12, 2024
bea395b
ref_state: fiexes print and nodeinfo ref datatype
javierajorge May 13, 2024
49adce0
removes reference data type old sync method
javierajorge May 13, 2024
bf3dfbb
Merge branch 'libremesh:master' into f/reference_state
javierbrk May 13, 2024
6ce5f04
ref_state: adds insert rpc call
javierajorge May 13, 2024
8c2a7de
ref_state: removes rpcd publish
javierajorge May 13, 2024
9c5e287
ref_state: fixes bug in wifi interface
javierajorge May 13, 2024
af48dd6
ref_state: fixes sync with ips
javierajorge May 13, 2024
098de02
updates packages and publisher
javierajorge May 13, 2024
f6d4f11
ref_state: renaming
javierajorge May 13, 2024
8cd9ec5
ref_state: fixes typo
javierajorge May 13, 2024
c9084b9
fixes more typos
javierajorge May 16, 2024
c14ce5e
ref_state:fixes publication strings error
javierajorge May 16, 2024
b95fed2
ref_state: fix test for write_if_diff
javierajorge May 28, 2024
3f55caf
change default reference state
javierajorge May 30, 2024
8034373
Merge branch 'libremesh:master' into f/reference_state
javierbrk Jun 19, 2024
5312ac4
ref_state: add missing new line at end of files and removes extra f
javierajorge Jun 27, 2024
02bdc7f
ref_state: adds wifi links location
javierajorge Jun 28, 2024
a9224f9
ref_state: fixes location issue
javierajorge Jul 2, 2024
bb44561
Ref_state: removes unnecessary locations
javierajorge Jul 3, 2024
1eca555
ref_state: new generic location implementation
javierbrk Jul 12, 2024
0e45a85
ref_state: new generic location for bat links and babel links
javierbrk Jul 30, 2024
f06d125
f_ref_state: add commit at the end of the uci defaults files
javierbrk Aug 1, 2024
e85670d
ref_state: fix typos
javierbrk Aug 1, 2024
b19b1ca
Merge branch 'master' into f/reference_state
javierbrk Aug 1, 2024
f46ea9a
ref_state: implements persistence
javierbrk Aug 9, 2024
cf4c38e
ref_state: fix script dir
javierbrk Aug 9, 2024
660b0ce
ref_state: fixes lime default usage
javierbrk Aug 9, 2024
c27def8
ref_state: fixes early call to publish error in bat_links
javierbrk Aug 9, 2024
e27ba12
ref_state: clean up unused functions
javierbrk Aug 15, 2024
8791409
ref_state: add new line at the end of file
javierbrk Aug 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sinc_args=""

case "$1" in
list)
echo '{ "sync": { "data_type": "str", "peers_ip": "str" }, "get": { "data_type": "str" }, "publish": { "data_type": "str" }, "publish_all": { } }'
echo '{ "sync": { "data_type": "str", "peers_ip": "str" }, "get": { "data_type": "str" }, "publish": { "data_type": "str" }, "publish_all": { },"insert": { "data_type": "str", "json": "str" } }'
;;
call)
# source jshn shell library
Expand All @@ -20,6 +20,21 @@ case "$1" in
json_load $msg
json_get_vars data_type
json_get_vars peers_ip
json=$(jsonfilter -s $msg -e "@.json")
if json_is_a peers_ip array
then
json_select peers_ip
idx=1
ips=""
while json_is_a ${idx} string ## iterate over data inside "peersip" object
do
json_get_var ip_addr $idx
ips="$ips$ip_addr "
idx=$(( idx + 1 ))
done
else
ips=$peers_ip
fi
case "$2" in
get)
if output=$(shared-state-async get $data_type 2>/dev/null)
Expand All @@ -30,7 +45,7 @@ case "$1" in
fi
;;
sync)
shared-state-async sync $data_type ${peers_ip//,/ } > /dev/null 2>&1
shared-state-async sync $data_type $ips > /dev/null 2>&1
echo {\"data\": {} , \"error\": $? }
;;
publish)
Expand All @@ -41,6 +56,10 @@ case "$1" in
shared-state-async-publish-all > /dev/null 2>&1
echo {\"data\": {} , \"error\": $? }
;;
insert)
printf '%s' "$json" | shared-state-async insert $data_type > /dev/null 2>&1
echo {\"data\": {} , \"error\": $? }
;;
*)
echo '{\"data\" {} ,\"error\" = "Method not found"}'
;;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared-state-babel_links_info/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ define Package/$(PKG_NAME)
TITLE:=Babel links module for shared-state
MAINTAINER:=Asociación Civil Altermundi <[email protected]>
DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \
+libubus-lua shared-state-async
+libubus-lua +shared-state-ref_state_commons shared-state-async
PKGARCH:=all
endef

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ unique_append()
grep -qF "$1" "$2" || echo "$1" >> "$2"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not used anymore should be removed ;)



uci set shared-state.babel_links_info=dataType
uci set shared-state.babel_links_info.name='babel_links_info'
uci set shared-state.babel_links_info.scope='community'
uci set shared-state.babel_links_info.ttl='2400'
uci set shared-state.babel_links_info.update_interval='30'
uci commit shared-state

## Reference state data type
uci set shared-state.babel_links_info_ref=dataType
uci set shared-state.babel_links_info_ref.name='babel_links_info_ref'
uci set shared-state.babel_links_info_ref.scope='community'
uci set shared-state.babel_links_info_ref.ttl='2400'
uci set shared-state.babel_links_info_ref.update_interval='50'

uci commit shared-state
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,11 @@
-- ! Copyright (c) 2023 Instituto Nacional de Tecnología Industrial
-- ! Copyright (C) 2023 Asociación Civil Altermundi <[email protected]>
-- !
-- ! This program is free software: you can redistribute it and/or modify
-- ! it under the terms of the GNU Affero General Public License as
-- ! published by the Free Software Foundation, either version 3 of the
-- ! License, or (at your option) any later version.
-- !
-- ! This program is distributed in the hope that it will be useful,
-- ! but WITHOUT ANY WARRANTY; without even the implied warranty of
-- ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- ! GNU Affero General Public License for more details.
-- !
-- ! 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/>.
-- ! SPDX-License-Identifier: AGPL-3.0-only

local JSON = require("luci.jsonc")
local utils = require('lime.utils')
local ubus = require "ubus"
local shared_state_links_info = require ("shared_state_links_info")

local ifaceip = {}

Expand All @@ -40,16 +29,16 @@ function get_babel_links_info()
babelneigt_obj = ubus.call(conn, "babeld", "get_neighbours", {})
if babelneigt_obj ~= nil then
for key, value in pairs(babelneigt_obj.IPv6) do
table.insert(links, {
local key_table = {(string.gsub(get_interface_ip(value.dev),":","")),(string.gsub(key,":",""))}
table.sort(key_table)
links[table.concat(key_table)]= {
src_ip = get_interface_ip(value.dev),
dst_ip = key,
iface = value.dev
})
}
end
end
return links
end

local hostname = io.input("/proc/sys/kernel/hostname"):read("*line")
local result = { [hostname] = get_babel_links_info() }
io.popen("shared-state-async insert babel_links_info", "w"):write(JSON.stringify(result))
shared_state_links_info.insert_in_ss_with_location(get_babel_links_info(),"babel_links_info")
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ describe('Tests network_nodes #network_nodes', function()
require("shared-state-publish_babel_links_info")

babelinfo = get_babel_links_info()
assert.are.equal('fe80::16cc:20ff:feda:4eac', babelinfo[1].dst_ip)
assert.are.equal("wlan1-mesh_17",babelinfo[1].iface)
assert.are.equal("fe80::c24a:ff:fefc:3abd",babelinfo[1].src_ip)
assert.are.equal('fe80::16cc:20ff:feda:4eac', babelinfo["fe8016cc20fffeda4eacfe80c24afffefc3abd"].dst_ip)
assert.are.equal("wlan1-mesh_17",babelinfo["fe8016cc20fffeda4eacfe80c24afffefc3abd"].iface)
assert.are.equal("fe80::c24a:ff:fefc:3abd",babelinfo["fe8016cc20fffeda4eacfe80c24afffefc3abd"].src_ip)
end)
end)

Expand Down
2 changes: 1 addition & 1 deletion packages/shared-state-bat_links_info/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define Package/$(PKG_NAME)
TITLE:=Batman protocol links information module for shared-state
MAINTAINER:= Javier <[email protected]>
DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \
+lime-system +batctl-default shared-state-async
+lime-system +batctl-default +shared-state-ref_state_commons shared-state-async
PKGARCH:=all
endef

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@ unique_append()
{
grep -qF "$1" "$2" || echo "$1" >> "$2"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not used anymore should be removed, also the script should be renamed ;)


## information generator datatype
uci set shared-state.bat_links_info=dataType
uci set shared-state.bat_links_info.name='bat_links_info'
uci set shared-state.bat_links_info.scope='community'
uci set shared-state.bat_links_info.ttl='2400'
uci set shared-state.bat_links_info.update_interval='30'

## Reference state data type
uci set shared-state.bat_links_info_ref=dataType
uci set shared-state.bat_links_info_ref.name='bat_links_info_ref'
uci set shared-state.bat_links_info_ref.scope='community'
uci set shared-state.bat_links_info_ref.ttl='2400'
uci set shared-state.bat_links_info_ref.update_interval='50'

uci commit shared-state
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,12 @@
--! Copyright (C) 2023 Javier Jorge <[email protected]>
--! Copyright (C) 2023 Asociación Civil Altermundi <[email protected]>
--!
--! This program is free software: you can redistribute it and/or modify
--! it under the terms of the GNU Affero General Public License as
--! published by the Free Software Foundation, either version 3 of the
--! License, or (at your option) any later version.
--!
--! This program is distributed in the hope that it will be useful,
--! but WITHOUT ANY WARRANTY; without even the implied warranty of
--! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
--! GNU Affero General Public License for more details.
--!
--! 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/>.
--! SPDX-License-Identifier: AGPL-3.0-only

local JSON = require("luci.jsonc")
local utils = require('lime.utils')
local network = require ("lime.network")

local hostname = utils.hostname()
local shared_state_links_info = require ("shared_state_links_info")

function get_bat_links_info()
local bat_neighbors_obj={}
Expand All @@ -34,25 +22,30 @@ 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)

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,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
local kv_fromlinks = {}
if bat_neighbors_obj then
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=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
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
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
end
return bat_neighbors_obj
return kv_fromlinks
end

local result = { [hostname] = get_bat_links_info() }
io.popen("shared-state-async insert bat_links_info", "w"):write(JSON.stringify(result))
shared_state_links_info.insert_in_ss_with_location(get_bat_links_info(),"bat_links_info")
92 changes: 92 additions & 0 deletions packages/shared-state-bat_links_info/tests/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"LiMe-430b0c": [
{
"dst_mac": "02:cc:4e:1f:73:aa",
"last_seen_msecs": 1560,
"tq": 255,
"src_mac": "02:cc:4e:43:0b:0c",
"iface": "wlan2-mesh_29"
},
{
"dst_mac": "02:ab:46:1f:73:aa",
"last_seen_msecs": 1000,
"tq": 255,
"src_mac": "02:ab:46:43:0b:0c",
"iface": "wlan1-mesh_29"
},
{
"dst_mac": "02:ab:46:dd:69:1c",
"last_seen_msecs": 1670,
"tq": 251,
"src_mac": "02:ab:46:43:0b:0c",
"iface": "wlan1-mesh_29"
}
],
"cheche": [
{
"dst_mac": "02:ab:46:dd:69:1c",
"last_seen_msecs": 20,
"tq": 255,
"src_mac": "02:ab:46:1f:73:aa",
"iface": "wlan1-mesh_29"
},
{
"dst_mac": "02:ab:46:43:0b:0c",
"last_seen_msecs": 1300,
"tq": 251,
"src_mac": "02:ab:46:1f:73:aa",
"iface": "wlan1-mesh_29"
},
{
"dst_mac": "02:cc:4e:43:0b:0c",
"last_seen_msecs": 900,
"tq": 242,
"src_mac": "02:cc:4e:1f:73:aa",
"iface": "wlan2-mesh_29"
},
{
"dst_mac": "02:58:47:dd:69:1c",
"last_seen_msecs": 1460,
"tq": 255,
"src_mac": "02:58:47:1f:73:aa",
"iface": "wlan0-mesh_29"
},
{
"dst_mac": "02:58:47:1f:73:f6",
"last_seen_msecs": 520,
"tq": 255,
"src_mac": "02:58:47:1f:73:aa",
"iface": "wlan0-mesh_29"
}
],
"konB-11s": [
{
"dst_mac": "02:58:47:1f:73:aa",
"last_seen_msecs": 1020,
"tq": 255,
"src_mac": "02:58:47:dd:69:1c",
"iface": "wlan0-mesh_29"
},
{
"dst_mac": "02:58:47:1f:73:f6",
"last_seen_msecs": 1010,
"tq": 255,
"src_mac": "02:58:47:dd:69:1c",
"iface": "wlan0-mesh_29"
},
{
"dst_mac": "02:ab:46:1f:73:aa",
"last_seen_msecs": 540,
"tq": 235,
"src_mac": "02:ab:46:dd:69:1c",
"iface": "wlan1-mesh_29"
},
{
"dst_mac": "02:ab:46:43:0b:0c",
"last_seen_msecs": 1140,
"tq": 255,
"src_mac": "02:ab:46:dd:69:1c",
"iface": "wlan1-mesh_29"
}
]
}
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)
Loading
Loading