From fbabf19ce13af02e96186669300ecc5fa0ea1da6 Mon Sep 17 00:00:00 2001 From: Ilario Gelmetti Date: Sun, 28 May 2023 12:42:14 +0200 Subject: [PATCH 01/12] readme: expanded instructions on ImageBuilder --- README.md | 45 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 89255f964..f96685493 100644 --- a/README.md +++ b/README.md @@ -21,22 +21,44 @@ We encourage each network community to create its firmware profile on [In this page][1] we provide a list of requirements that ensure you to have a working LibreMesh node on your router. This list comes with no warranties: read -carefully the [model-specific instructions on OpenWrt wiki][2] and be +carefully the [model-specific instructions on OpenWrt wiki][OpenWrt-ToH] and be extra-careful when flashing your routers! ## Building a Firmware Image on Your PC -The LibreMesh firmware can be compiled by following [these instructions][13]. +### Building the stable release LibreMesh 2020.1 -### Using the ImageBuilder +#### Using the BuildRoot -Start an ImageBuilder of your choice, use containers for an easier setup: +The BuildRoot **will cross-compile the whole OpenWrt and the LibreMesh packages** on your computer, so it will take approx 10 GB of disk space and a few hours of compilation time. + +For compiling LibreMesh firmware with this method, you can follow [these instructions][development_page]. + +#### Using the ImageBuilder + +The ImageBuilder method is not available for the stable release. + +### Building the experimental firmware + +The experimental code still has serious issues that have to be solved, use it only for developing or debugging. + +#### Using the BuildRoot + +As explained above, in the instuctions on the website you will find where to specify the version of the code to compile. + +#### Using the ImageBuilder + +The ImageBuiler **will download pre-compiled parts of the OpenWrt releases**, and add the pre-compiled LibreMesh packages, so it is **much faster** than the BuildRoot method (but less practical if you want to develop some new features modifying LibreMesh source code). + +Start an ImageBuilder of your choice, for example ath79-generic if your device is supported within it, use containers for an easier setup: ```shell mkdir ./images/ -docker run -it -v $(pwd)/images:/images/ ghcr.io/openwrt/imagebuilder:ath79-generic-v22.03.4 +docker run -it -v $(pwd)/images:/images/ ghcr.io/openwrt/imagebuilder:ath79-generic-v22.03.5 ``` +If your device is not part of ath79-generic profiles, you can replace it with another - combination. For knowing which target and subtarget is best suited for your router, check out the page about it in the [OpenWrt's Table of Hardware][OpenWrt-ToH]. + Within the container, add the `lime-packages` feed: ```shell @@ -55,11 +77,18 @@ Now create an image of your choice, to see the names of supported profiles run `make info` first. ```shell -make image PROFILE=ubnt_unifi PACKAGES="lime-system lime-proto-babeld" BIN_DIR=/images FILES=files +make image PROFILE=ubnt_unifi PACKAGES="lime-system lime-proto-babeld lime-proto-batadv lime-proto-anygw lime-hwd-openwrt-wan -dnsmasq" BIN_DIR=/images FILES=files ``` Your images should be available outside of the container in the `./images/` folder +##### Possible errors from the ImageBuilder + +If you get a `docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.` error, means that you don't have Docker's daemon running. Make sure you have `docker` installed and start its daemon with `systemctl start docker.service`. + +If you get a `opkg_download: Check your network settings and connectivity.` error, both check the connectivity and make sure that the firewall rules of your computer allow the container to reach the internet. + + ## Testing LibreMesh has unit tests that help us add new features while keeping maintenance @@ -115,13 +144,13 @@ sponsor](https://opencollective.com/libremesh#sponsor)] [1]: https://libremesh.org/docs/hardware/ -[2]: https://openwrt.org/toh/start +[OpenWrt-ToH]: https://openwrt.org/toh/start [4]: https://libremesh.org/howitworks.html [5]: https://libremesh.org/ [8]: https://www.autistici.org/mailman/listinfo/libremesh [9]: https://libremesh.org/communication.html [10]: https://github.com/libremesh/network-profiles/ [12]: https://opencollective.com/libremesh -[13]: https://libremesh.org/development.html +[development_page]: https://libremesh.org/development.html [lime-example]: https://github.com/libremesh/lime-packages/blob/master/packages/lime-docs/files/www/docs/lime-example.txt From 7c36dbd97a377629234ef3a695b0bea033cd64bc Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Tue, 22 Aug 2023 14:59:14 -0300 Subject: [PATCH 02/12] removed extra info from shared state Removed ttl, author and other information --- .../files/usr/libexec/rpcd/shared-state | 12 ++++- .../tests/test_rpcd_shared-state.lua | 52 +++++++++++++------ 2 files changed, 47 insertions(+), 17 deletions(-) diff --git a/packages/shared-state/files/usr/libexec/rpcd/shared-state b/packages/shared-state/files/usr/libexec/rpcd/shared-state index 7f6e6fda9..4fb387a6b 100755 --- a/packages/shared-state/files/usr/libexec/rpcd/shared-state +++ b/packages/shared-state/files/usr/libexec/rpcd/shared-state @@ -19,14 +19,22 @@ local function getFromSharedState(msg) local sharedState = shared_state.SharedState:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() - utils.printJson(resultTable) + local response ={} + for k,v in pairs(resultTable) do + response[k]=v.data + end + utils.printJson(response) end local function getFromSharedStateMultiWriter(msg) local sharedState = shared_state.SharedStateMultiWriter:new(msg.data_type, nixio.syslog) local resultTable = sharedState:get() - utils.printJson(resultTable) + local response ={} + for k,v in pairs(resultTable) do + response[k]=v.data + end + utils.printJson(response) end local function insertIntoSharedStateMultiWriter(msg) diff --git a/packages/shared-state/tests/test_rpcd_shared-state.lua b/packages/shared-state/tests/test_rpcd_shared-state.lua index a6ee604a8..e118126b1 100644 --- a/packages/shared-state/tests/test_rpcd_shared-state.lua +++ b/packages/shared-state/tests/test_rpcd_shared-state.lua @@ -1,5 +1,6 @@ local testUtils = require "tests.utils" local sharedState = require("shared-state") +local json = require("luci.jsonc") local testFileName = "packages/shared-state/files/usr/libexec/rpcd/shared-state" local sharedStateRpc = testUtils.load_lua_file_as_function(testFileName) @@ -37,9 +38,9 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal(dbA.zig.data, 'zag') local response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedState'}, '{"data_type": "wifi_links_info"}') - assert.is.equal(response.bar.data, 'foo') - assert.is.equal(response.baz.data, 'qux') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.bar, 'foo') + assert.is.equal(response.baz, 'qux') + assert.is.equal(response.zig, 'zag') end) it('test get multiwriter data ', function() @@ -54,12 +55,12 @@ describe('ubus-shared-state tests #ubus-shared-state', function() assert.is.equal('zag', dbA.zig.data) local response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') - assert.is.equal(response.bar.data, 'foo') - assert.is.equal(response.baz.data, 'qux') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.bar, 'foo') + assert.is.equal(response.baz, 'qux') + assert.is.equal(response.zig, 'zag') end) - it('test set multiwriter data ', function() + it('test insert multiwriter data ', function() local sharedStateA = sharedState.SharedStateMultiWriter:new('A') sharedStateA:insert({ bar = 'foo', @@ -72,7 +73,28 @@ describe('ubus-shared-state tests #ubus-shared-state', function() local response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, '{"data_type": "A", "json": {"zig": "newzag"}}') - local dbA = sharedStateA:get() + dbA = sharedStateA:get() + assert.is.equal('foo', dbA.bar.data) + assert.is.equal('newzag', dbA.zig.data) + end) + + it('test insert multiwriter data ', function() + local sharedStateA = sharedState.SharedStateMultiWriter:new('A') + sharedStateA:insert({ + bar = 'foo', + baz = 'qux', + zig = 'zag' + }) + local response = rpcdCall(sharedStateRpc, {'call', + 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') + assert.is.equal('foo', response.bar) + assert.is.equal('zag', response.zig) + response.zig="newzag" + callargs = '{"data_type": "A", "json": '..json.stringify(response)..'}' + local response = rpcdCall(sharedStateRpc, {'call', + 'insertIntoSharedStateMultiWriter'}, + callargs) + dbA = sharedStateA:get() assert.is.equal('foo', dbA.bar.data) assert.is.equal('newzag', dbA.zig.data) end) @@ -121,7 +143,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() '{"data_type": "A", "json": {"zig": "zag"}}') response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "A"}') - assert.is.equal(response.zig.data, 'zag') + assert.is.equal(response.zig, 'zag') response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, @@ -129,8 +151,8 @@ describe('ubus-shared-state tests #ubus-shared-state', function() response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 23) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 23) + assert.is.equal(response.primero.author, "primero") response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'},wifiStatusJsonsample27) @@ -139,8 +161,8 @@ describe('ubus-shared-state tests #ubus-shared-state', function() 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 27) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 27) + assert.is.equal(response.primero.author, "primero") response = rpcdCall(sharedStateRpc, {'call', 'insertIntoSharedStateMultiWriter'}, @@ -148,7 +170,7 @@ describe('ubus-shared-state tests #ubus-shared-state', function() response = rpcdCall(sharedStateRpc, {'call', 'getFromSharedStateMultiWriter'}, '{"data_type": "ref_state_wifilinks"}') - assert.is.equal(response.primero.data.bleachTTL, 23) - assert.is.equal(response.primero.data.author, "primero") + assert.is.equal(response.primero.bleachTTL, 23) + assert.is.equal(response.primero.author, "primero") end) end) From af73b38ca66e9bc26c8679835910284a97e59933 Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Tue, 29 Aug 2023 23:26:09 -0300 Subject: [PATCH 03/12] add new info module --- packages/shared-state-node_info/Makefile | 38 +++++++++++++++ .../shared-state-publish_node_info | 1 + .../uci-defaults/shared-state_node_info_cron | 9 ++++ .../usr/bin/shared-state-publish_node_info | 39 ++++++++++++++++ .../tests/test_shared-state-node_info.lua | 46 +++++++++++++++++++ 5 files changed, 133 insertions(+) create mode 100644 packages/shared-state-node_info/Makefile create mode 120000 packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info create mode 100755 packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron create mode 100755 packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info create mode 100644 packages/shared-state-node_info/tests/test_shared-state-node_info.lua diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile new file mode 100644 index 000000000..35654f902 --- /dev/null +++ b/packages/shared-state-node_info/Makefile @@ -0,0 +1,38 @@ +# +# Copyright (C) 2023 Javier Jorge +# This is free software, licensed under the GNU Affero General Public License v3. +# + +include $(TOPDIR)/rules.mk + +GIT_COMMIT_DATE:=$(shell git log -n 1 --pretty=%ad --date=short . ) +GIT_COMMIT_TSTAMP:=$(shell git log -n 1 --pretty=%at . ) + +PKG_NAME:=shared-state-node_info +PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP) + +include $(INCLUDE_DIR)/package.mk + +define Package/$(PKG_NAME) + TITLE:=Node information module for shared-state + CATEGORY:=LibreMesh + MAINTAINER:= + URL:=http://libremesh.org + DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ + +lime-system shared-state + PKGARCH:=all +endef + +define Package/$(PKG_NAME)/description + Syncronize node information beween nodes. +endef + +define Build/Compile +endef + +define Package/$(PKG_NAME)/install + $(INSTALL_DIR) $(1)/ + $(CP) ./files/* $(1)/ +endef + +$(eval $(call BuildPackage,$(PKG_NAME))) diff --git a/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info b/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info new file mode 120000 index 000000000..4124b3bed --- /dev/null +++ b/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info @@ -0,0 +1 @@ +../../usr/bin/shared-state-publish_node_info \ No newline at end of file diff --git a/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron new file mode 100755 index 000000000..483e0ab4f --- /dev/null +++ b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron @@ -0,0 +1,9 @@ +#!/bin/sh +unique_append() +{ + grep -qF "$1" "$2" || echo "$1" >> "$2" +} + +unique_append \ + '*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync wifi_links_info &> /dev/null)&)'\ + /etc/crontabs/root diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info new file mode 100755 index 000000000..80ab7002b --- /dev/null +++ b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info @@ -0,0 +1,39 @@ +#!/usr/bin/lua + +--! LibreMesh +--! Copyright (C) 2023 Javier Jorge +--! +--! 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 . + +local JSON = require("luci.jsonc") +local network = require ("lime.network") +local location = require("lime.location") +local network_nodes = require('network-nodes') + + +local hostname = io.input("/proc/sys/kernel/hostname"):read("*line") + +function get_node_info() + local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} + local node = network_nodes._create_node() + local uptime = utils.uptime_s() + local macs = network.get_own_macs("*") + table.insert(node, {coordinates=coords,macs= macs,uptime = uptime,device = "Router" } ) + return node +end + + +local result = { [hostname] = get_node_info() } +io.popen("shared-state insert wifi_links_info", "w"):write(JSON.stringify(result)) + diff --git a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua new file mode 100644 index 000000000..8c61d6f62 --- /dev/null +++ b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua @@ -0,0 +1,46 @@ +local network_nodes = require('network-nodes') +local JSON = require("luci.jsonc") +local test_utils = require('tests.utils') +local utils = require('lime.utils') +local node_status = require ("lime.node_status") + + + +local uci = nil + +package.path = package.path .. ";packages/shared-state-node_info/files/usr/bin/?;;" +require ("shared-state-publish_node_info") + + +describe('Tests network_nodes #network_nodes', function () + before_each('', function() + uci = test_utils.setup_test_uci() + stub(utils, "release_info", function () return {DISTRIB_RELEASE='2021.1'} end) + stub(utils, "current_board", function () return 'devboard' end) + stub(node_status,"get_ips",function () return 'caca' end) + end) + + after_each('', function() + test_utils.teardown_test_uci(uci) + end) + + it('a simple test to get links info and assert requiered fields are present', function() + utils.log("holaaaaaaa") + print("laaaaaaa") + uci = config.get_uci_cursor() + + uci:set('network', 'lan', 'interface') + uci:set('network', 'lan', 'ipaddr', '10.5.0.5') + uci:set('network', 'lan', 'ip6addr', 'fd0d:fe46:8ce8::ab:cd00/64') + utils.log("holaaaaaaa") + uci:commit('network') + local node = network_nodes._create_node() + utils.log("holaaaaaaa") + utils.log(utils.release_info()['DISTRIB_RELEASE']) + utils.log("\n") + utils.log(JSON.stringify(node)) + utils.log("\n") + nodeinfo = get_node_info() + utils.log(JSON.stringify(nodeinfo)) + end) +end) \ No newline at end of file From 5a4e6082ffb7fd3ee1f985daad30a2da3d4a30cc Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Wed, 30 Aug 2023 14:05:14 -0300 Subject: [PATCH 04/12] test pass --- .../usr/bin/shared-state-publish_node_info | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info index 80ab7002b..50d6576ca 100755 --- a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info +++ b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info @@ -19,21 +19,28 @@ local JSON = require("luci.jsonc") local network = require ("lime.network") local location = require("lime.location") -local network_nodes = require('network-nodes') +local utils = require('lime.utils') - -local hostname = io.input("/proc/sys/kernel/hostname"):read("*line") +local hostname = utils.hostname() function get_node_info() + local uci = config.get_uci_cursor() local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} - local node = network_nodes._create_node() + local fw_version = "no version" + pcall(function () fw_version = utils.release_info()['DISTRIB_RELEASE'] end) + local board = "no board" + pcall(function () board = utils.current_board() end) + local ipv4 = uci:get("network", "lan", "ipaddr") + local ipv6 = uci:get("network", "lan", "ip6addr") + if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end local uptime = utils.uptime_s() local macs = network.get_own_macs("*") - table.insert(node, {coordinates=coords,macs= macs,uptime = uptime,device = "Router" } ) + + node = {} + table.insert(node, {hostname=hostname, member=member, fw_version=fw_version, board=board, ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime,device = "Router" } ) return node end - local result = { [hostname] = get_node_info() } io.popen("shared-state insert wifi_links_info", "w"):write(JSON.stringify(result)) From e462037d96086f394e9688aa2a3536a03fa13fa6 Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Wed, 30 Aug 2023 16:09:41 -0300 Subject: [PATCH 05/12] fixed shared state data type --- .../files/etc/uci-defaults/shared-state_node_info_cron | 2 +- .../files/usr/bin/shared-state-publish_node_info | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron index 483e0ab4f..27132a824 100755 --- a/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron +++ b/packages/shared-state-node_info/files/etc/uci-defaults/shared-state_node_info_cron @@ -5,5 +5,5 @@ unique_append() } unique_append \ - '*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync wifi_links_info &> /dev/null)&)'\ + '*/5 * * * * ((sleep $(($RANDOM % 120)); shared-state sync node_info &> /dev/null)&)'\ /etc/crontabs/root diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info index 50d6576ca..74f492206 100755 --- a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info +++ b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info @@ -20,9 +20,9 @@ local JSON = require("luci.jsonc") local network = require ("lime.network") local location = require("lime.location") local utils = require('lime.utils') +local config = require("lime.config") local hostname = utils.hostname() - function get_node_info() local uci = config.get_uci_cursor() local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} @@ -35,12 +35,11 @@ function get_node_info() if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end local uptime = utils.uptime_s() local macs = network.get_own_macs("*") - node = {} table.insert(node, {hostname=hostname, member=member, fw_version=fw_version, board=board, ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime,device = "Router" } ) return node end local result = { [hostname] = get_node_info() } -io.popen("shared-state insert wifi_links_info", "w"):write(JSON.stringify(result)) +io.popen("shared-state insert node_info", "w"):write(JSON.stringify(result)) From 97ab0769b595dbca46ddb915954b1f9a26490adf Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Wed, 30 Aug 2023 22:48:41 -0300 Subject: [PATCH 06/12] fexted test cases --- packages/shared-state-node_info/Makefile | 1 + .../usr/bin/shared-state-publish_node_info | 10 +++++---- .../tests/test_shared-state-node_info.lua | 22 +++++-------------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile index 35654f902..96d39d031 100644 --- a/packages/shared-state-node_info/Makefile +++ b/packages/shared-state-node_info/Makefile @@ -1,5 +1,6 @@ # # Copyright (C) 2023 Javier Jorge +# Copyright (C) 2023 AsociaciĆ³n Civil Altermundi # This is free software, licensed under the GNU Affero General Public License v3. # diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info index 74f492206..62e2ccc3e 100755 --- a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info +++ b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info @@ -2,6 +2,7 @@ --! LibreMesh --! Copyright (C) 2023 Javier Jorge +--! Copyright (C) 2023 AsociaciĆ³n Civil Altermundi --! --! This program is free software: you can redistribute it and/or modify --! it under the terms of the GNU Affero General Public License as @@ -25,7 +26,8 @@ local config = require("lime.config") local hostname = utils.hostname() function get_node_info() local uci = config.get_uci_cursor() - local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} + local coords = location.get_node() or location.get_community() or + {lat="FIXME", long="FIXME"} local fw_version = "no version" pcall(function () fw_version = utils.release_info()['DISTRIB_RELEASE'] end) local board = "no board" @@ -35,9 +37,9 @@ function get_node_info() if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end local uptime = utils.uptime_s() local macs = network.get_own_macs("*") - node = {} - table.insert(node, {hostname=hostname, member=member, fw_version=fw_version, board=board, ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime,device = "Router" } ) - return node + return {hostname=hostname, firmware_version=fw_version, board=board, + ipv4=ipv4, ipv6=ipv6,coordinates=coords,macs= macs,uptime = uptime, + device = "Router" } end local result = { [hostname] = get_node_info() } diff --git a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua index 8c61d6f62..a21ab5704 100644 --- a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua +++ b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua @@ -1,46 +1,34 @@ -local network_nodes = require('network-nodes') local JSON = require("luci.jsonc") local test_utils = require('tests.utils') local utils = require('lime.utils') -local node_status = require ("lime.node_status") - - local uci = nil package.path = package.path .. ";packages/shared-state-node_info/files/usr/bin/?;;" require ("shared-state-publish_node_info") - describe('Tests network_nodes #network_nodes', function () before_each('', function() uci = test_utils.setup_test_uci() stub(utils, "release_info", function () return {DISTRIB_RELEASE='2021.1'} end) stub(utils, "current_board", function () return 'devboard' end) - stub(node_status,"get_ips",function () return 'caca' end) end) after_each('', function() test_utils.teardown_test_uci(uci) end) - it('a simple test to get links info and assert requiered fields are present', function() - utils.log("holaaaaaaa") - print("laaaaaaa") + it('a simple test to get node info and assert requiered fields are present', function() uci = config.get_uci_cursor() - uci:set('network', 'lan', 'interface') uci:set('network', 'lan', 'ipaddr', '10.5.0.5') uci:set('network', 'lan', 'ip6addr', 'fd0d:fe46:8ce8::ab:cd00/64') - utils.log("holaaaaaaa") uci:commit('network') - local node = network_nodes._create_node() - utils.log("holaaaaaaa") - utils.log(utils.release_info()['DISTRIB_RELEASE']) - utils.log("\n") - utils.log(JSON.stringify(node)) - utils.log("\n") nodeinfo = get_node_info() utils.log(JSON.stringify(nodeinfo)) + assert.are.equal('devboard', nodeinfo.board) + assert.are.equal('2021.1', nodeinfo.firmware_version) + assert.are.equal('10.5.0.5', nodeinfo.ipv4) + assert.are.equal('fd0d:fe46:8ce8::ab:cd00', nodeinfo.ipv6) end) end) \ No newline at end of file From f8d25719d9b4b6a9f57a9fd5ea3047866648604c Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Wed, 30 Aug 2023 23:09:38 -0300 Subject: [PATCH 07/12] publisher relocation --- .../etc/shared-state/publishers/shared-state-publish_node_info | 1 + .../files/etc/shared-state/shared-state-publish_node_info | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) create mode 120000 packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info delete mode 120000 packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info diff --git a/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info b/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info new file mode 120000 index 000000000..bd21001b3 --- /dev/null +++ b/packages/shared-state-node_info/files/etc/shared-state/publishers/shared-state-publish_node_info @@ -0,0 +1 @@ +../../../usr/bin/shared-state-publish_node_info \ No newline at end of file diff --git a/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info b/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info deleted file mode 120000 index 4124b3bed..000000000 --- a/packages/shared-state-node_info/files/etc/shared-state/shared-state-publish_node_info +++ /dev/null @@ -1 +0,0 @@ -../../usr/bin/shared-state-publish_node_info \ No newline at end of file From 090b41239146da45254f654b19013ac0c32defc7 Mon Sep 17 00:00:00 2001 From: "javier.jorge" Date: Wed, 30 Aug 2023 23:30:00 -0300 Subject: [PATCH 08/12] added missing dependencies, fixed indentations --- packages/shared-state-node_info/Makefile | 2 +- .../files/usr/bin/shared-state-publish_node_info | 11 +++++------ .../tests/test_shared-state-node_info.lua | 1 - 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile index 96d39d031..ec36cb8d5 100644 --- a/packages/shared-state-node_info/Makefile +++ b/packages/shared-state-node_info/Makefile @@ -20,7 +20,7 @@ define Package/$(PKG_NAME) MAINTAINER:= URL:=http://libremesh.org DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ - +lime-system shared-state + +lime-system +ubus-lime-location shared-state PKGARCH:=all endef diff --git a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info index 62e2ccc3e..309037c6c 100755 --- a/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info +++ b/packages/shared-state-node_info/files/usr/bin/shared-state-publish_node_info @@ -26,15 +26,15 @@ local config = require("lime.config") local hostname = utils.hostname() function get_node_info() local uci = config.get_uci_cursor() - local coords = location.get_node() or location.get_community() or + local coords = location.get_node() or location.get_community() or {lat="FIXME", long="FIXME"} local fw_version = "no version" pcall(function () fw_version = utils.release_info()['DISTRIB_RELEASE'] end) - local board = "no board" + local board = "no board" pcall(function () board = utils.current_board() end) - local ipv4 = uci:get("network", "lan", "ipaddr") - local ipv6 = uci:get("network", "lan", "ip6addr") - if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end + local ipv4 = uci:get("network", "lan", "ipaddr") + local ipv6 = uci:get("network", "lan", "ip6addr") + if ipv6 then ipv6 = ipv6:gsub("/.*$", "") end local uptime = utils.uptime_s() local macs = network.get_own_macs("*") return {hostname=hostname, firmware_version=fw_version, board=board, @@ -44,4 +44,3 @@ end local result = { [hostname] = get_node_info() } io.popen("shared-state insert node_info", "w"):write(JSON.stringify(result)) - diff --git a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua index a21ab5704..498c419f6 100644 --- a/packages/shared-state-node_info/tests/test_shared-state-node_info.lua +++ b/packages/shared-state-node_info/tests/test_shared-state-node_info.lua @@ -25,7 +25,6 @@ describe('Tests network_nodes #network_nodes', function () uci:set('network', 'lan', 'ip6addr', 'fd0d:fe46:8ce8::ab:cd00/64') uci:commit('network') nodeinfo = get_node_info() - utils.log(JSON.stringify(nodeinfo)) assert.are.equal('devboard', nodeinfo.board) assert.are.equal('2021.1', nodeinfo.firmware_version) assert.are.equal('10.5.0.5', nodeinfo.ipv4) From 9e7f3b153f4cfb2aee1115e86dab000ce856e458 Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Thu, 31 Aug 2023 11:14:10 -0300 Subject: [PATCH 09/12] add MAINTAINER info --- packages/shared-state-node_info/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile index ec36cb8d5..bc67b6277 100644 --- a/packages/shared-state-node_info/Makefile +++ b/packages/shared-state-node_info/Makefile @@ -17,7 +17,7 @@ include $(INCLUDE_DIR)/package.mk define Package/$(PKG_NAME) TITLE:=Node information module for shared-state CATEGORY:=LibreMesh - MAINTAINER:= + MAINTAINER:= Javier URL:=http://libremesh.org DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ +lime-system +ubus-lime-location shared-state From e5c53b546c381a087f606afe6c1655abfaa7f1a1 Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Thu, 31 Aug 2023 14:44:46 -0300 Subject: [PATCH 10/12] make remake --- packages/shared-state-node_info/Makefile | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/packages/shared-state-node_info/Makefile b/packages/shared-state-node_info/Makefile index bc67b6277..5b894b674 100644 --- a/packages/shared-state-node_info/Makefile +++ b/packages/shared-state-node_info/Makefile @@ -4,23 +4,15 @@ # This is free software, licensed under the GNU Affero General Public License v3. # -include $(TOPDIR)/rules.mk - -GIT_COMMIT_DATE:=$(shell git log -n 1 --pretty=%ad --date=short . ) -GIT_COMMIT_TSTAMP:=$(shell git log -n 1 --pretty=%at . ) - -PKG_NAME:=shared-state-node_info -PKG_VERSION=$(GIT_COMMIT_DATE)-$(GIT_COMMIT_TSTAMP) - -include $(INCLUDE_DIR)/package.mk +include ../../libremesh.mk define Package/$(PKG_NAME) - TITLE:=Node information module for shared-state + SECTION:=lime CATEGORY:=LibreMesh + TITLE:=Node information module for shared-state MAINTAINER:= Javier - URL:=http://libremesh.org DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ - +lime-system +ubus-lime-location shared-state + +lime-system +ubus-lime-location shared-state PKGARCH:=all endef @@ -28,12 +20,4 @@ define Package/$(PKG_NAME)/description Syncronize node information beween nodes. endef -define Build/Compile -endef - -define Package/$(PKG_NAME)/install - $(INSTALL_DIR) $(1)/ - $(CP) ./files/* $(1)/ -endef - $(eval $(call BuildPackage,$(PKG_NAME))) From 368ef41700978ca3db47d536767686e2dd162498 Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Thu, 31 Aug 2023 14:54:54 -0300 Subject: [PATCH 11/12] add freq information --- packages/shared-state-wifi_links_info/Makefile | 2 +- .../files/usr/bin/shared-state-publish_wifi_links_info | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/shared-state-wifi_links_info/Makefile b/packages/shared-state-wifi_links_info/Makefile index b5306e726..2a5328ff1 100644 --- a/packages/shared-state-wifi_links_info/Makefile +++ b/packages/shared-state-wifi_links_info/Makefile @@ -20,7 +20,7 @@ define Package/$(PKG_NAME) MAINTAINER:= URL:=http://libremesh.org DEPENDS:=+lua +luci-lib-jsonc +ubus-lime-utils \ - +lime-system shared-state + +lime-system +libiwinfo-lua shared-state PKGARCH:=all endef diff --git a/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info b/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info index a9a21ab59..fd0668fca 100755 --- a/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info +++ b/packages/shared-state-wifi_links_info/files/usr/bin/shared-state-publish_wifi_links_info @@ -20,6 +20,8 @@ local JSON = require("luci.jsonc") local node_status = require ("lime.node_status") local network = require ("lime.network") +local iwinfo = require "iwinfo" + function get_wifi_links_info() local stations = node_status.get_stations() @@ -28,9 +30,10 @@ function get_wifi_links_info() macparts = network.get_mac(station.iface) src_macaddr = table.concat(macparts,":") local station_stats = node_status.get_station_stats(station) + local freq = iwinfo.nl80211.frequency(station.iface) table.insert(links, {src_mac=src_macaddr ,dst_mac=station.station_mac, signal=station_stats.signal,chains=station_stats.chains, - rx_rate=station_stats.rx_rate,tx_rate=station_stats.tx_rate } ) + rx_rate=station_stats.rx_rate,tx_rate=station_stats.tx_rate,freq=freq } ) end return links end From fb8432f06dcf5804ceb3755b6c1a27a3ede46d89 Mon Sep 17 00:00:00 2001 From: Javier Jorge Date: Thu, 31 Aug 2023 15:51:22 -0300 Subject: [PATCH 12/12] fixed test case --- .../tests/test_shared-state_wifi_links_info.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua b/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua index 1e3dcc75e..84efb0c13 100644 --- a/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua +++ b/packages/shared-state-wifi_links_info/tests/test_shared-state_wifi_links_info.lua @@ -13,7 +13,8 @@ it('a simple test to get links info and assert requiered fields are present', fu return iwinfo.mocks.iw_station_get_result_wlan1 end) stub(node_status, "get_stations", function () return iwinfo.mocks.get_stations end) - + stub(node_status, "get_stations", function () return iwinfo.mocks.get_stations end) + stub(iwinfo.nl80211,"frequency",function (iface) return 2400 end) stub(network, "get_mac", function (iface) if string.match(iface, "wlan0") then return iwinfo.mocks.wlan0_mesh_mac @@ -28,6 +29,7 @@ it('a simple test to get links info and assert requiered fields are present', fu assert.is.same({-17,-18}, links_info[1].chains) assert.is.equal(-14, links_info[1].signal) assert.is.equal(13000, links_info[1].rx_rate) + assert.is.equal(2400, links_info[1].freq) assert.is.equal("C0:00:00:00:00:00", links_info[1].src_mac) end)