Developing lightweight computation at the DSG edge

Commit 074b4988 authored by p4u's avatar p4u
Browse files

New feature Bandwidth test in tools tab of web interface

parent 457f3f4d
......@@ -74,7 +74,7 @@
<% for i,o in ipairs(originators) do %>
<tr>
<td><%=o.name%></td>
<td>
<td style="text-align:left;">
<% if o.desc.DESC_ADV ~= nil then %>
<% for j,h in ipairs(o.desc.DESC_ADV.extensions[2].HNA6_EXTENSION) do %>
<%=h.address%>&nbsp;&nbsp;&nbsp;&nbsp;
......
......@@ -41,6 +41,7 @@ config 'qmp' 'networks'
option 'babel_mesh_prefix48' 'fd03:0:0'
option 'netserver' '1'
config 'qmp' 'tunnels'
option 'search_ipv4_tunnel' '0.0.0.0/0'
......
......@@ -46,16 +46,20 @@ configure() {
ifup -a
/etc/init.d/dnsmasq restart
touch "$CONTROL_FILE"
# echo "Done, rebooting system to complete configuration"
# reboot
}
#This function is executed in each boot
startup() {
$QMP_DIR/qmp_control.sh apply_netserver
}
start() {
if [ ! -f "$CONTROL_FILE" ]; then
configure
else
echo "QMP configured. Remove $CONTROL_FILE to force reconfiguration"
fi
startup
if [ ! -f "$CONTROL_FILE" ]; then
configure
else
echo "QMP configured. Remove $CONTROL_FILE to force reconfiguration"
fi
}
stop() {
......
......@@ -23,6 +23,7 @@ QMP_PATH="/etc/qmp"
. $QMP_PATH/qmp_functions.sh
. $QMP_PATH/qmp_gw.sh
. $QMP_PATH/qmp_wireless.sh
. $QMP_PATH/qmp_network.sh
offer_default_gw() {
qmp_gw_offer_default
......@@ -50,6 +51,10 @@ apply_network() {
/etc/init.d/firewall restart
}
apply_netserver() {
[ "$(qmp_uci_get networks.netserver)" == "1" ] && qmp_enable_netserver || qmp_disable_netserver
}
help() {
echo "Use: $0 <function> [params]"
echo ""
......@@ -58,6 +63,7 @@ help() {
echo " search_default_gw : Search for a default gw in the network"
echo " apply_wifi : Apply current wifi configuration"
echo " apply_network : Apply current network configuration"
echo " apply_netserver : Start/stop nerserver depending on qmp configuration"
echo ""
}
......
# Copyright (C) 2011 Fundacio Privada per a la Xarxa Oberta, Lliure i Neutral guifi.net
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# The full GNU General Public License is included in this distribution in
# the file called "COPYING".
##############################
# Global variable definition
##############################
QMP_PATH="/etc/qmp"
TMP="/tmp"
QMPINFO="/etc/qmp/qmpinfo"
#######################
# Importing files
######################
SOURCE_NET=1
[ -z "$SOURCE_COMMON" ] && . $QMP_PATH/qmp_common.sh
qmp_enable_netserver() {
qmp_uci_set networks.netserver 1
killall -9 netserver
netserver -6 -p 12865
}
qmp_disable_netserver() {
qmp_uci_set networks.netserver 0
killall -9 netserver
}
......@@ -32,6 +32,8 @@ function print_help()
print(" channels <dev> : supported channels and supported HT40 type (+/-) ")
print(" ipv4 : print all ipv4 from this computer (excluding localhost)")
print(" hostname : print device hostname")
print(" bwtest <ipv6> : perform a bandwidth test")
print(" nodes : list all nodes on MESH network")
print("")
end
......@@ -48,7 +50,7 @@ end
function print_channels()
local partial
local output = ""
local data = qmp.get_channels(dev)
local data = qmp.get_channels(op1)
for _,d in ipairs(data) do
output = d.channel
if d.ht40p then output = output .. " ht40+" end
......@@ -59,7 +61,7 @@ function print_channels()
end
function print_txpower()
local data = qmp.get_txpower(dev)
local data = qmp.get_txpower(op1)
for _,v in ipairs(data) do
print(v)
end
......@@ -76,13 +78,35 @@ function print_hostname()
print(qmp.get_hostname())
end
function bw_test()
if #op1 < 5 then
print_help()
os.exit(1)
end
local bwt = qmpinfo.bandwidth_test(op1)
if bwt == nil then
print("Cannot connecto to "..op1.." netserver")
else
print ("Bandwidth: "..bwt.." Mbit/s")
end
end
function nodes()
for _,n in ipairs(qmpinfo.nodes()) do
if #n == 2 then
print(n[1].." "..n[2])
end
end
end
if #arg < 1 then
print_help()
os.exit(1)
end
local question = arg[1]
dev = arg[2]
op1 = arg[2]
if question == "modes" then
print_modes()
......@@ -94,6 +118,10 @@ elseif question == "ipv4" then
print_ipv4()
elseif question == "hostname" then
print_hostname()
elseif question == "bwtest" then
bw_test()
elseif question == "nodes" then
nodes()
else
print_help()
end
......
......@@ -149,4 +149,28 @@ function qmpinfo.get_uname()
return uname
end
function qmpinfo.bandwidth_test(ip)
local bwtest = util.trim(util.exec("netperf -6 -p 12865 -H "..ip.." -fm -v0 -P0"))
local result = nil
if #bwtest < 10 then
result = bwtest
end
return result
end
function qmpinfo.nodes()
local nodes = util.split(util.exec('bmx6 -c --originators | awk \'{print $1 "|" $3}\' | grep -e ".*:.*:"'))
local ni
result = {}
for _,n in ipairs(nodes) do
if n ~= "" then
ni = util.split(n,"|")
ni[1] = util.split(ni[1],".")[1]
table.insert(result,ni)
end
end
return result
end
return qmpinfo
/etc/qmp/qmpinfo
\ No newline at end of file
......@@ -39,6 +39,7 @@ function index()
entry({"qmp","network"}, cbi("qmp/config"), "Network", 5).dependent=false
entry({"qmp","wireless"}, cbi("qmp/wireless"), "Wireless", 6).dependent=false
entry({"qmp","splash"}, call("action_splash"), "Splash", 7).dependent=false
entry({"qmp","tools"}, call("action_tools"), "Tools", 8).dependent=false
end
function action_status()
......@@ -51,6 +52,13 @@ function action_status()
luci.template.render("qmp/overview",{ipv4=ipv4,hostname=hostname,uname=uname})
end
function action_tools()
package.path = package.path .. ";/etc/qmp/?.lua"
local qmp = require "qmpinfo"
local nodes = qmp.nodes()
luci.template.render("qmp/tools",{nodes=nodes})
end
function action_splash()
luci.template.render("qmp/splash")
end
<%+header%>
<script type="text/javascript">
function do_bwtest(ip,index) {
var output = document.getElementById('output_'+index);
if (output) {
output.innerHTML ='<%:Collecting data...%>&lt;img src="/luci-static/resources/icons/loading.gif" height="20px" alt="Loading" style="vertical-align:middle"/&gt; ';
output.style.display = 'inline';
var result = new XMLHttpRequest();
result.open("GET", "/cgi-bin/bwtest?"+ip, true);
result.onreadystatechange = function() {
if (result.readyState == 4) {
output.innerHTML= parse_result(result.responseText);
}
}
result.send(null);
}
}
function parse_result(txt) {
var t = new String(txt);
if (t.indexOf("Cannot") >= 0)
return("&lt;font color='#f00'&gt;<%:Cannot connecto to netserver%>&lt;/font&gt;");
else
return("&lt;font color='#0a0'&gt;"+txt+"&lt;/font&gt;");
}
</script>
<h2>Bandwidth test</h2>
<p><strong>Nodes found in the network:</strong></p>
<form>
<% for i,n in ipairs(nodes) do %>
<div style="height:30px;width:550px;float:left">
<input type="button" value="<%=n[1]%>" onclick="do_bwtest('<%=n[2]%>',<%=i%>)" />&nbsp;&nbsp; <%=n[2]%>
<span style="display:none;margin-left:5px;border:1px solid #000;padding:0.1em 0.4em" id="output_<%=i%>"></span>
</div>
<% end %>
<div style="clear:both;height:30px;float:left">
<strong>Specify Custom ip:</strong>
<input type="text" name="custom" />
<input type="button" value="Start" onclick='do_bwtest(this.form.custom.value,"custom")' />&nbsp;&nbsp; <%=n%>
<span style="display:none;margin-left:5px;border:1px solid #000;padding:0.1em 0.4em" id="output_custom"></span>
</div>
</form>
<%+footer%>
#!/bin/sh
echo "content-type: text/plain"
echo ""
#TODO: Securize Query
QUERY="$QUERY_STRING"
[ ! -z "$QUERY" ] && {
/etc/qmp/qmpinfo bwtest $QUERY
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment