-
Notifications
You must be signed in to change notification settings - Fork 96
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
links information according to batman protocol #1055
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
82a3892
intial module structure
javierbrk 2fdda95
added batman link information publisher
javierajorge 1aed507
removed debug prints
javierajorge db4a0fd
consistent renaming
javierajorge 9ee9922
fixed folder name
javierajorge 79e7dba
Added test case
javierajorge ad077f4
removed unused file
javierajorge 947e962
Add batctl dependency
javierajorge f89fbd2
Fixed makefile title
javierbrk 3d86203
removed hard_ifindex and added new line at the end of file
javierbrk 18d70c7
remove debug print
javierbrk 6817c8c
add link tq parameter and optional best indicator
javierbrk f6aa83f
package refactoring to include tq index
javierajorge 6d4c609
include mac verification in tests
javierajorge 3d63187
name refactoring and comments
javierajorge 934a550
Merge branch 'libremesh:master' into batmaninfo
javierbrk 1e1f379
shared-state-async: ads bat links info
javierajorge 30298c7
adds shared state async as aa dependency
javierbrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# | ||
# Copyright (C) 2023 Javier Jorge <jjorge@inti.gob.ar> | ||
# Copyright (c) 2023 Instituto Nacional de Tecnología Industrial | ||
# Copyright (C) 2023 Asociación Civil Altermundi <info@altermundi.net> | ||
# This is free software, licensed under the GNU Affero General Public License v3. | ||
# | ||
|
||
include ../../libremesh.mk | ||
|
||
define Package/$(PKG_NAME) | ||
SECTION:=lime | ||
CATEGORY:=LibreMesh | ||
TITLE:=Batman protocol links information module for shared-state | ||
MAINTAINER:= Javier <jjorge@inti.gob.ar> | ||
DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ | ||
+lime-system +batctl-default shared-state | ||
PKGARCH:=all | ||
endef | ||
|
||
define Package/$(PKG_NAME)/description | ||
Syncronize batman protocol links information beween nodes. | ||
endef | ||
|
||
$(eval $(call BuildPackage,$(PKG_NAME))) |
1 change: 1 addition & 0 deletions
1
...tate-bat_links_info/files/etc/shared-state/publishers/shared-state-publish_bat_links_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../usr/bin/shared-state-publish_bat_links_info |
9 changes: 9 additions & 0 deletions
9
packages/shared-state-bat_links_info/files/etc/uci-defaults/shared-state_bat_links_info_cron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/sh | ||
unique_append() | ||
{ | ||
grep -qF "$1" "$2" || echo "$1" >> "$2" | ||
} | ||
|
||
unique_append \ | ||
'*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync bat_links_info &> /dev/null)&)'\ | ||
/etc/crontabs/root |
40 changes: 40 additions & 0 deletions
40
packages/shared-state-bat_links_info/files/usr/bin/shared-state-publish_bat_links_info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/lua | ||
|
||
--! LibreMesh | ||
--! Copyright (C) 2023 Javier Jorge <jjorge@inti.gob.ar> | ||
--! Copyright (C) 2023 Asociación Civil Altermundi <info@altermundi.net> | ||
--! | ||
--! 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/>. | ||
|
||
local JSON = require("luci.jsonc") | ||
local utils = require('lime.utils') | ||
local network = require ("lime.network") | ||
|
||
local hostname = utils.hostname() | ||
function get_bat_links_info() | ||
local batneights_obj={} | ||
local batneights = utils.unsafe_shell("batctl nj") | ||
batneights = string.gsub(batneights,"neigh_address","dst_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.src_mac=src_macaddr | ||
end | ||
return batneights_obj | ||
end | ||
|
||
local result = { [hostname] = get_bat_links_info() } | ||
io.popen("shared-state insert bat_links_info", "w"):write(JSON.stringify(result)) |
27 changes: 27 additions & 0 deletions
27
packages/shared-state-bat_links_info/tests/test_shared-state-bat_links_info.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
local utils = require "lime.utils" | ||
local network = require ("lime.network") | ||
local iwinfo = require "iwinfo" | ||
|
||
|
||
|
||
describe('Tests bat_links_info #bat_links_info', function () | ||
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"}]' | ||
end) | ||
stub(network, "get_mac", function (iface) | ||
return iwinfo.mocks.wlan1_mesh_mac | ||
end) | ||
|
||
package.path = package.path .. ";packages/shared-state-bat_links_info/files/usr/bin/?;;" | ||
require ("shared-state-publish_bat_links_info") | ||
|
||
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(26, links_info[1].hard_ifindex) | ||
assert.are.equal(1990, links_info[1].last_seen_msecs) | ||
assert.are.equal("wlan0-mesh_250", links_info[1].iface) | ||
end) | ||
end) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New line missing at the end of file
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done !