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

links information according to batman protocol #1055

Merged
merged 18 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
24 changes: 24 additions & 0 deletions packages/shared-state-bat_links_info/Makefile
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)))
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
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))
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)
Copy link
Member

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done !