Skip to content

Commit

Permalink
Merge branch 'libremesh:master' into feature/mesh-upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
javierbrk authored Aug 28, 2024
2 parents d4332af + 527c1eb commit 8a9efc8
Show file tree
Hide file tree
Showing 42 changed files with 686 additions and 186 deletions.

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
@@ -1,14 +1,16 @@
#!/bin/sh
unique_append()
{
grep -qF "$1" "$2" || echo "$1" >> "$2"
}


## information generator datatype
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
@@ -0,0 +1,16 @@
#!/bin/sh
## 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

This file was deleted.

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"
}
]
}
Loading

0 comments on commit 8a9efc8

Please sign in to comment.