Skip to content

Commit

Permalink
Merge pull request libremesh#1096 from selankon/f/node-status-DSA-sup…
Browse files Browse the repository at this point in the history
…port

lime-utils: implement DSA support for node status
  • Loading branch information
G10h4ck authored Mar 19, 2024
2 parents 7bfa124 + 2c18b81 commit 4be8f34
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
41 changes: 38 additions & 3 deletions packages/ubus-lime-utils/files/usr/lib/lua/lime/node_status.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
local limewireless = require 'lime.wireless'
local iwinfo = require 'iwinfo'
local utils = require 'lime.utils'
local json = require("luci.jsonc")


-- Functions used by get_node_status
local node_status = {}
Expand Down Expand Up @@ -81,15 +83,19 @@ end
function node_status.switch_status()
local response_ports = node_status.boardjson_get_ports()
if #response_ports ~= 0 then
node_status.swconfig_get_link_status(response_ports)
if utils.is_dsa() then
node_status.dsa_get_link_status(response_ports)
else
node_status.swconfig_get_link_status(response_ports)
end
end
return response_ports
end

function node_status.boardjson_get_ports()
local response_ports = {}
local board = utils.getBoardAsTable()
if board['switch'] ~= nil and board['switch']['switch0'] ~= nil then
if board['switch'] ~= nil and board['switch']['switch0'] ~= nil then -- legacy swconfig devices support
for _, role in ipairs(board['switch']['switch0']['roles']) do
for port_number in string.gmatch(role['ports'], "%S+") do
if not tonumber(port_number) then
Expand All @@ -99,12 +105,41 @@ function node_status.boardjson_get_ports()
table.insert(response_ports, { num = tonumber(port_number), role = role['role'], device = role['device']})
end
end

end
elseif board['network'] ~= nil then -- DSA devices support
for switch_name, switch in pairs(board['network']) do
if switch['ports'] ~= nil then
for _, port in ipairs(switch.ports) do
table.insert(response_ports, { num = port, role = switch_name, device = switch_name})
end
else
table.insert(response_ports, { num = switch_name, role = switch_name, device = switch['device'] })
end
end
end
return response_ports
end

function node_status.dsa_get_link_status(ports)
for _, port in ipairs(ports) do
local dsa = utils.unsafe_shell("ip -j -p link show " .. port['num'])
local dsa_json = json.parse(dsa)

port['device'] = port['num']
port['num'] = dsa_json[1]['ifindex']
port['role'] = dsa_json[1]['link']
if dsa_json[1]['link'] == nil then
port['role'] = dsa_json[1]['ifname']
end
port['link'] = dsa_json[1]['operstate']
if dsa_json[1]['operstate'] == "LOWERLAYERDOWN" then
port['link'] = "DOWN"
end
end
return ports
end


function node_status.swconfig_get_link_status(ports)
local function add_link_status(port_number, status)
for x, obj in pairs(ports) do
Expand Down
5 changes: 5 additions & 0 deletions packages/ubus-lime-utils/tests/test_ubus_lime_utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ describe('ubus-lime-utils tests #ubuslimeutils', function()
assert.is_true(utils.deepcompare(expected, response['switch_status']))
end)

-- todo(kon): this have to be implemented, right now the available images for testing haven't DSA
-- create tests for this pr https://github.com/libremesh/lime-packages/pull/1096
--it('test get_node_status ports DSA support', function()



it('test get_most_active return most active iface with stats from iw', function()
stub(utils, "unsafe_shell", function (cmd)
Expand Down

0 comments on commit 4be8f34

Please sign in to comment.