2018-03-27 14:22:25 +00:00
|
|
|
-- Copyright 2008 Steven Barth <steven@midlink.org>
|
|
|
|
-- Copyright 2011 Jo-Philipp Wich <jow@openwrt.org>
|
|
|
|
-- Copyright 2018 Ycarus (Yannick Chabanois) <ycarus@zugaina.org>
|
|
|
|
-- Licensed to the public under the Apache License 2.0.
|
|
|
|
|
2018-03-21 16:30:44 +00:00
|
|
|
module("luci.controller.mptcp", package.seeall)
|
|
|
|
|
|
|
|
function index()
|
2018-03-27 14:22:25 +00:00
|
|
|
entry({"admin", "network", "mptcp"}, alias("admin", "network", "mptcp", "settings"), _("MPTCP"))
|
2018-03-28 08:59:15 +00:00
|
|
|
entry({"admin", "network", "mptcp", "settings"}, cbi("mptcp"), _("Settings"),2).leaf = true
|
|
|
|
entry({"admin", "network", "mptcp", "bandwidth"}, template("mptcp/multipath"), _("Bandwidth"), 3).leaf = true
|
2018-03-27 14:22:25 +00:00
|
|
|
entry({"admin", "network", "mptcp", "multipath_bandwidth"}, call("multipath_bandwidth")).leaf = true
|
|
|
|
entry({"admin", "network", "mptcp", "interface_bandwidth"}, call("interface_bandwidth")).leaf = true
|
|
|
|
end
|
|
|
|
|
|
|
|
function interface_bandwidth(iface)
|
|
|
|
luci.http.prepare_content("application/json")
|
|
|
|
local bwc = io.popen("luci-bwc -i %q 2>/dev/null" % iface)
|
|
|
|
if bwc then
|
|
|
|
luci.http.write("[")
|
|
|
|
while true do
|
|
|
|
local ln = bwc:read("*l")
|
|
|
|
if not ln then break end
|
|
|
|
luci.http.write(ln)
|
|
|
|
end
|
|
|
|
luci.http.write("]")
|
|
|
|
bwc:close()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function multipath_bandwidth()
|
|
|
|
local result = { };
|
|
|
|
local uci = luci.model.uci.cursor()
|
|
|
|
|
2018-05-22 09:13:28 +00:00
|
|
|
uci:foreach("network", "interface", function(s)
|
2018-09-14 21:04:06 +00:00
|
|
|
local dev = s["ifname"] or ""
|
2018-05-22 09:13:28 +00:00
|
|
|
if dev ~= "lo" and dev ~= "" then
|
|
|
|
local multipath = s["multipath"] or "off"
|
2018-03-27 14:22:25 +00:00
|
|
|
if multipath == "on" or multipath == "master" or multipath == "backup" or multipath == "handover" then
|
2018-09-19 07:19:12 +00:00
|
|
|
local bwc = luci.sys.exec("luci-bwc -i %q 2>/dev/null" % dev) or ""
|
|
|
|
if bwc ~= nil then
|
|
|
|
result[dev] = "[" .. string.gsub(bwc, '[\r\n]', '') .. "]"
|
|
|
|
else
|
|
|
|
result[dev] = "[]"
|
|
|
|
end
|
2018-03-27 14:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
2018-05-22 09:13:28 +00:00
|
|
|
end)
|
2018-03-27 14:22:25 +00:00
|
|
|
|
|
|
|
luci.http.prepare_content("application/json")
|
|
|
|
luci.http.write_json(result)
|
2018-03-21 16:30:44 +00:00
|
|
|
end
|