--[[ @object-name:qos @object-desc: QOS管理相关接口 --]] local M = {} local rpc = require "oui.rpc" local uci = require "uci" local function valid_mac(mac) return type(mac) == "string" and mac:match("[%x:]+") == mac and #mac == 17 end --[[ @method-type:call @method-name:set_channel_bandwidth_ratio @method-desc:配置优先级通道带宽占比 @in array upload 上行带宽配置. @in number upload.priority 上行带宽优先级. @in number upload.min 对应优先级的最小上行带宽. @in number upload.max 对应优先级的最大上行带宽. @in array download 下行带宽配置. @in number download.priority 下行带宽优先级. @in number download.min 对应优先级的最小下行带宽. @in number download.max 对应优先级的最大下行带宽. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"block_client\",{\"mac\":\"84:7a:88:79:e5:13\",\"enable\":true}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.set_channel_bandwidth_ratio() end --[[ @method-type:call @method-name:add_device_group @method-desc:添加客户端组 @in string group_name 组名称. @in number priority 组优先级. @in array ?clients 客户端列表. @in string ?clients.mac 客户端的mac地址. @in string ?clients.name 客户端的名称. @out number group_id 组id. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"block_client\",{\"mac\":\"84:7a:88:79:e5:13\",\"enable\":true}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.add_device_group() end --[[ @method-type:call @method-name:delete_device_group @method-desc:删除客户端组 @in number group_id 组id. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"block_client\",{\"mac\":\"84:7a:88:79:e5:13\",\"enable\":true}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.delete_device_group() end --[[ @method-type:call @method-name:modify_device_group @method-desc:修改客户端组信息 @in number group_id 组id. @in string group_name 组名称. @in number priority 组优先级. @in array clients 客户端列表. @in string clients.mac 客户端的mac地址. @in string clients.name 客户端的名称. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"block_client\",{\"mac\":\"84:7a:88:79:e5:13\",\"enable\":true}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.modify_device_group() end --[[ @method-type:call @method-name:get_device_group @method-desc:获取客户端组信息 @in number group_id 组id. @out string group_name 组名称. @out number priority 组优先级. @out array clients 客户端列表. @out string clients.mac 客户端的mac地址. @out string clients.name 客户端的名称. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"block_client\",{\"mac\":\"84:7a:88:79:e5:13\",\"enable\":true}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.get_device_group() end --[[ @method-type:call @method-name:set_other_client_priority @method-desc:设置其他客户端的优先级 @in number priority 其他客户端的优先级[1-高优先级,2-中优先级,3-低优先级]. (界面中考虑加个按钮) @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"set_config\",{}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.set_other_client_priority() os.execute("/etc/qos/htb.sh") end --[[ @method-type:call @method-name:get_client_list (在点击添加客户端限速规则时调用) @method-desc:获取客户端列表 @out array clients 客户端列表. @out string clients.mac 客户端的mac地址. @out number ?clients.upload 客户端的上行 【KB/S】. @out number ?clients.download 客户端的下行 【KB/S】. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"get_client_list\",{}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\":1,\"result\":{\"clients\":[{\"mac\":\"18:c0:4d:dc:4f:cc\",\"download\":10,\"upload\":2},{\"mac\":\"18:c0:4d:dc:4f:dd\",\"download\":11,\"upload\":3}]}} --]] function M.get_client_list() local c = uci.cursor() local clients = {} c:foreach("qos", "queue", function(s) clients[#clients + 1] = { mac = s.mac, name = s.name, upload = tonumber(s.upload), download = tonumber(s.download) } end) return {clients = clients} end --[[ @method-type:call @method-name:set_speed_limit_rule @method-desc:设置客户端设备限速规则 @in string mac 客户端的mac地址. @in number upload 上行 【KB/S】.设置为0时,不进行限速 @in number download 下行 【KB/S】.设置为0时,不进行限速 @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"set_speed_limit_rule\",{\"mac\":\"18:c0:4d:dc:4f:cc\",\"download\":10,\"upload\":2}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.set_speed_limit_rule(param) local mac = param.mac local upload = param.upload local download = param.download if valid_mac(mac) and type(upload) == "number" and type(download) == "number" then local c = uci.cursor() local flag = 0 local eqos_conf_status = c:foreach("qos", "queue", function(s) local conf_mac = s.mac if mac == conf_mac then flag = 1 end end) local rs_file = assert(io.popen("tc class list dev br-lan")) local eqos_status = rs_file:read() or "" rs_file:close() if eqos_status == "" or eqos_conf_status == false then -- 千兆宽带 assert(os.execute("gl_eqos start 125000 125000")) end local set_cmd = "gl_eqos add ".. mac .. " " .. download .. " " .. upload if flag == 1 then os.execute("gl_eqos del ".. mac .. " only_remove_ts") end os.execute(set_cmd) os.execute("/etc/init.d/gl_eqos reload") else return rpc.ERROR_CODE_INVALID_PARAMS end end --[[ @method-type:call @method-name:remove_speed_limit_rule @method-desc:删除客户端设备限速规则 @in string mac 客户端的mac地址. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"remove_speed_limit_rule\",{\"mac\":\"18:c0:4d:dc:4f:cc\"}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.remove_speed_limit_rule(param) local mac = param.mac if not valid_mac(mac) then return rpc.ERROR_CODE_INVALID_PARAMS end local c = uci.cursor() c:delete("qos", mac) c:commit("qos") os.execute("gl_eqos del " .. mac:gsub("%X", "")) end --[[ @method-type:call @method-name:set_model @method-desc:设置qos模式 @in string model qos的启动模式 [ speed_limit | priority | cake ]. (限制客户端速率模式,应该加个应用按钮) @in array ?wan_list qos wan口的配置信息. @in string ?wan_list.name wan口名称 wan-有线网络,wwan-无线中继,tethering-热点共享,modem1-移动网络1,modem2-移动网络2. @in bool ?wan_list.up 对应的wan口是否开启,false-未开启,true-开启.(前端不显示未开启的wan口的上下行配置信息) @in number ?wan_list.upload 对应wan口的上行,单位为kbit. @in number ?wan_list.download 对应wan口的下行,单位为kbit. @in string ?cake_model cake当前工作模式. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"switch_model\",{\"model\":\"cake\"}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.set_model(param) local model = param.model if model == "cake" then os.execute("/etc/qos/cake.sh") elseif model == "htb" then os.execute("/etc/qos/htb.sh") end end --[[ @method-type:call @method-name:enable_qos @method-desc:开启或关闭qos功能 @in bool enable true-开启qos功能 ,false-关闭qos功能. @out number ?err_code Error code, -1:Invalid user,-5:No parameter found. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"set_config\",{}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.enable_qos() os.execute("/etc/qos/htb.sh") end --[[ @method-type:call @method-name:get_config @method-desc:获取qos配置信息 @out bool enable qos开关状态. @out string model qos当前工作模式.(当前是什么模式,就返回对应模式的配置信息) @out array ?wan_list qos wan口的配置信息. @out string ?wan_list.name wan口名称 wan-有线网络,wwan-无线中继,tethering-热点共享,modem1-移动网络1,modem2-移动网络2. @out bool ?wan_list.up 对应的wan口是否开启,false-未开启,true-开启.(前端不显示未开启的wan口的上下行配置信息) @out number ?wan_list.upload 对应wan口的上行,单位为kbit. @out number ?wan_list.download 对应wan口的下行,单位为kbit. @out string ?cake_model cake当前工作模式. @out array ?group_device 设备组的信息. @out string ?group_device.name 设备组的名称. @out number ?group_device.id 设备组的id. @out number ?group_device.number 设备组的设备总数. @out number ?other_clients_priority 其他客户端的优先级[1-高优先级,2-中优先级,3-低优先级]. (界面中考虑加个按钮) @out array ?speed_limit_clients 限速的客户端列表. @out string ?speed_limit_clients.name 客户端的名称. @out string ?speed_limit_clients.mac 客户端的mac地址. @out string ?speed_limit_clients.ip 客户端的ip地址. @out string ?speed_limit_clients.upload 客户端的上行. @out string ?speed_limit_clients.download 客户端的下行. @out string ?err_msg Error message. @in-example: {\"jsonrpc\":\"2.0\",\"method\":\"call\",\"id\":1,\"params\":[\"\",\"qos\",\"get_config\",{}]} @out-example:{\"jsonrpc\":\"2.0\",\"id\": 1,\"result\": null} --]] function M.get_config() os.execute("/etc/qos/htb.sh") end return M