Developing lightweight computation at the DSG edge

Commit 102b990b authored by p4u's avatar p4u
Browse files

Merge branch 'testing' into gsoc

parents 3dbf09af d5cf2c4a
......@@ -52,11 +52,11 @@ qmp_gw_masq_wan() {
#Looking for a firewall zone with name wan
while [ ! -z "$v" ]; do
v=$(qmp_uci_get_raw firewall.@zone[$j].name)
[ "$v" == "wan" ] && { wan=$j; break; }
[ "$v" == "wan" ] && { wan=$j; break; }
j=$(( $j +1 ))
done
if [ -z "$wan" ]; then
if [ -z "$wan" ]; then
#if not found, we are going to create it
cfg="$(qmp_uci_add_raw_get_cfg firewall zone)"
qmp_uci_set_cfg firewall.$cfg.input=ACCEPT
......@@ -66,7 +66,7 @@ qmp_gw_masq_wan() {
qmp_uci_set_cfg firewall.$cfg.masq=$masq
qmp_uci_commit firewall
else
else
#if found we just change parameters
qmp_uci_set_raw firewall.@zone[$wan].input=ACCEPT
qmp_uci_set_raw firewall.@zone[$wan].output=ACCEPT
......
......@@ -42,8 +42,12 @@ qmp_disable_netserver() {
killall -9 netserver || true
}
## DISABLED
# Publish or unpublish lan HNA depending on qmp configuration
qmp_publish_lan() {
echo "Publish LAN is a garbage, doing nothing..."
return
is_publish_on=$(qmp_uci_get networks.publish_lan)
[ -z "$is_publish_on" ] && is_publish_on=0
......@@ -56,8 +60,8 @@ qmp_publish_lan() {
echo "Publishing LAN network: $lan_netid/$lan_prefix"
qmp_publish_hna_bmx6 $lan_netid/$lan_prefix qMp_lan
else
qmp_unpublish_hna_bmx6 qMp_lan
fi
qmp_unpublish_hna_bmx6 qMp_lan
fi
}
# Usage: qmp_publish_hna_bmx6_ipv4 10.22.33.64/27 [name_id]
......@@ -71,10 +75,10 @@ qmp_publish_hna_bmx6() {
is_ipv6=$(echo $netid | grep : -c)
is_ipv4=$(echo $netid | grep . -c)
[ $is_ipv6 -eq $is_ipv4 ] && { echo "Error in IP format"; return; }
[ $is_ipv6 -eq $is_ipv4 ] && { echo "Error in IP format"; return; }
# if not name_id provided, getting one from netid md5sum
[ -z "$name_id" ] && name_id="$(echo $netid | md5sum | cut -c1-5)"
[ -z "$name_id" ] && name_id="$(echo $netid | md5sum | cut -c1-5)"
if [ $is_ipv4 ]; then
# Checking if netmask is in ipv4 format and converting it to ipv6
......@@ -83,17 +87,17 @@ qmp_publish_hna_bmx6() {
else
hna="$netid/$netmask"
fi
uci set bmx6.$name_id=hna
uci set bmx6.$name_id.hna="$hna"
uci commit
bmx6 -c --test -a $hna > /dev/null
if [ $? -eq 0 ]; then
if [ $? -eq 0 ]; then
bmx6 -c --configReload
else
echo "ERROR in bmx6, check log"
echo "ERROR in bmx6, check log"
fi
}
......
......@@ -61,7 +61,7 @@ qmp_update_get_checksum_from_image() {
qmp_update_extract_timestamp() {
image_name="$1"
echo "$image_name" | awk -F\- '{print $3}' | awk -F_ '{print $1}' | sed s/"\..*"//
echo "$image_name" | awk -F\- '{print $4}' | awk -F_ '{print $1}' | sed s/"\..*"//
}
qmp_update_get_config() {
......@@ -82,7 +82,7 @@ qmp_update_check() {
qmp_update_get_config
device_hash="$(qmp_update_get_local_hash)"
my_device="$(qmp_update_get_my_device $url/$devices $device_hash $filter)"
qmp_debug "My device is $my_device"
......@@ -93,15 +93,15 @@ qmp_update_check() {
last_timestamp="$(qmp_update_extract_timestamp $last_image)"
current_timestamp="$(qmp_update_get_current_timestamp)"
if [ $current_timestamp -lt $last_timestamp ]; then
if [ $current_timestamp -lt $last_timestamp ]; then
checksum="$(qmp_update_get_checksum_from_image $url/$images $last_image)"
echo "$url/$last_image $checksum"
fi
}
qmp_update_save_config() {
cd /
cd /
tar czf /tmp/qmp_saved_config.tar.gz $@
[ $? -ne 0 ] && qmp_error "Cannot save config: $@"
echo "/tmp/qmp_saved_config.tar.gz"
......@@ -112,7 +112,7 @@ qmp_update_save_config() {
qmp_update_upgrade_system() {
image_url="$1"
if [ -z "$image_url" ]; then
if [ -z "$image_url" ]; then
last_update_info="$(qmp_update_check)"
image_url="$(echo $last_update_info | awk '{print $1}')"
checksum="$(echo $last_update_info | awk '{print $2}')"
......@@ -131,14 +131,14 @@ qmp_update_upgrade_system() {
else
output_image=$image_url
fi
# Checking checksum
if [ -n "$checksum" ]; then
checksum_local="$(md5sum /tmp/qmp_upgrade_image.bin | awk '{print $1}')"
[ "$checksum_local" != "$checksum" ] && qmp_error "Upgrade not possible, checksum missmatch. Try again!"
qmp_log "Checksum correct!"
fi
# Saving configuration
preserve="$(qmp_uci_get update.preserve)"
if [ -z "$preserve" ]; then
......@@ -152,6 +152,7 @@ qmp_update_upgrade_system() {
read -p "Do you want to upgrade system using image $image_url? [N,y] " a
if [ "$a" == "y" ]; then
[ $(echo $image_url | grep Alix -c) -eq 1 ] && { echo "Detected Alix, applying sysupgrade patch..."; rm -rf /overlay/* 2>/dev/null; }
[ -n "$config" ] && sysupgrade -f $config $output_image
[ -z "$config" ] && sysupgrade -n $output_image
fi
......
......@@ -37,7 +37,7 @@ SOURCE_WIRELESS=1
. $QMP_PATH/qmp_common.sh
###########################
# Find wireless interface
# Find wireless interface
##########################
# Returns the index from wifi-iface (config/wireless) associated to the device or first free if not found
......@@ -47,7 +47,7 @@ qmp_find_wireless_iface() {
while true; do
d=$(qmp_uci_get_raw wireless.@wifi-iface[$i].device)
r=$?
[ "$d" == "$device" ] && break
[ "$d" == "$device" ] && break
[ $r -ne 0 ] && { qmp_uci_add_raw wireless wifi-iface; break; }
i=$(( $i + 1 ))
done
......@@ -74,7 +74,7 @@ qmp_check_channel() {
wrong=0
[ -z "$channel" ] || [ -z "$chaninfo" ] && wrong=1
[ "$mode" == "adhoc" ] && [ -z "$(echo $chaninfo | grep adhoc)" ] && wrong=1
[ "$ht40" == "+" ] && [ -z "$(echo $chaninfo | grep +)" ] && wrong=1
[ "$ht40" == "+" ] && [ -z "$(echo $chaninfo | grep +)" ] && wrong=1
[ "$ht40" == "-" ] && [ -z "$(echo $chaninfo | grep -)" ] && wrong=1
# If something wrong, asking for default parameter
......@@ -86,8 +86,8 @@ qmp_check_channel() {
#############################
# Configure driver from wifi
#############################
# This function reload modules from madwifi and mac80211
# Also depending on which driver is configured in config file, modifies the files from /etc/modules.d
# This function reload modules from madwifi and mac80211
# Also depending on which driver is configured in config file, modifies the files from /etc/modules.d
qmp_configure_wifi_driver() {
mac80211_modules="mac80211 ath ath5k ath9k_hw ath9k_common ath9k"
......@@ -95,15 +95,15 @@ qmp_configure_wifi_driver() {
#Removing all modules
echo "Removing wifi modules..."
for m in $(qmp_reverse_order $mac80211_modules); do
rmmod -f $m 2>/dev/null
done
for m in $(qmp_reverse_order $madwifi_modules); do
for m in $(qmp_reverse_order $mac80211_modules); do
rmmod -f $m 2>/dev/null
done
done
for m in $(qmp_reverse_order $madwifi_modules); do
rmmod -f $m 2>/dev/null
done
rmmod -a
#Loading driver modules
echo "Loading wifi modules..."
driver="$(qmp_uci_get wireless.driver)"
......@@ -139,31 +139,31 @@ qmp_configure_wifi_device() {
id=$1
device=$2
# checking if device is configured as "none"
# checking if device is configured as "none"
mode="$(qmp_uci_get @wireless[$id].mode)"
[ "$mode" == "none" ] && { echo "Interface $device disabled by qmp system"; return; }
[ "$mode" == "none" ] && { echo "Interface $device disabled by qmp system"; return; }
# spliting channel in channel number and ht40 mode
# spliting channel in channel number and ht40 mode
channel_raw="$(qmp_uci_get @wireless[$id].channel)"
channel="$(echo $channel_raw | tr -d +-)"
# is ht40 (802.11n) enabled?
ht40="$(echo $channel_raw | tr -d [0-9])"
[ ! -z "$ht40" ] && { mode="${mode}-n"; htmode="HT40$ht40"; }
mac="$(qmp_uci_get @wireless[$id].mac)"
name="$(qmp_uci_get @wireless[$id].name)"
driver="$(qmp_uci_get wireless.driver)"
country="$(qmp_uci_get wireless.country)"
bssid="$(qmp_uci_get wireless.bssid)"
txpower="$(qmp_uci_get @wireless[$id].txpower)"
echo "------------------------"
echo "Mac: $mac"
echo "Mode: $mode"
echo "Driver: $driver"
echo "Channel: $channel"
echo "Country: $country"
echo "Country: $country"
echo "Name: $name"
echo "------------------------"
......@@ -213,7 +213,7 @@ qmp_configure_wifi() {
devices="$(qmp_get_wifi_devices)"
macs="$(qmp_get_wifi_mac_devices)"
i=1
for d in $devices; do
for d in $devices; do
m=$(echo $macs | cut -d' ' -f$i)
j=0
while [ ! -z "$(qmp_uci_get @wireless[$j])" ]; do
......@@ -223,7 +223,7 @@ qmp_configure_wifi() {
done
i=$(( $i + 1 ))
done
echo ""
echo "Done. All devices configured according qmp configuration"
}
......@@ -267,14 +267,14 @@ qmp_wifi_get_default() {
if [ $bg_this_device -eq 1 -a $bg_devices -eq 1 ]; then
echo "ap"
else
#If only one B/G device and only two devices, using the non B/G one as adhoc
if [ $bg_devices -eq 1 -a $devices -eq 2 ]; then
echo "adhoc"
else
#Else depending on index
if [ $index -eq 1 ]; then
if [ $index -eq 1 ]; then
echo "ap"
else
echo "adhoc"
......@@ -286,7 +286,7 @@ qmp_wifi_get_default() {
# Lower channel -> ap
elif [ "$what" == "channel" ]; then
[ -z "$device" ] && qmp_error "Device not found?"
[ -z "$device" ] && qmp_error "Device not found?"
mode="$3"
# we are using index var to put devices in different channels
......@@ -303,25 +303,25 @@ qmp_wifi_get_default() {
# channel AdHoc is the last available (qmp_tac = inverse order) plus index*2+1 (1 3 5 ...)
[ "$mode" == "adhoc" ] || [ -z "$mode" ] && channel_info="$(qmp_tac $channels_cmd | grep adhoc | awk NR==${index}+${index}*2+1)"
# channel AP = ( node_id + index*3 ) % ( num_channels_ap) + 1
[ "$mode" == "ap" ] && channel_info="$($channels_cmd | awk NR==\(\($(qmp_get_dec_node_id)+$index*3\)%$num_channels_ap\)+1)"
[ "$mode" == "ap" ] && channel_info="$($channels_cmd | awk NR==\(\($(qmp_get_dec_node_id)+$index*3\)%$num_channels_ap\)+1)"
# if there is some problem, channel 6 is used
if [ -z "$channel_info" ]; then
qmp_log "Warning, not usable channels found in device $device "
[ "$1" == "channel" ] && echo "6"
[ "$1" == "channel" ] && echo "6"
return
fi
# let's see if we can use ht40 mode
# if it is avaiable, channel must be configured with + or - symbol
# if it is avaiable, channel must be configured with + or - symbol
channel="$(echo $channel_info | cut -d' ' -f1)"
ht40="$(echo $channel_info | cut -d' ' -f2)"
[ "$ht40" == "ht40+" ] && channel="${channel}+"
[ "$ht40" == "ht40-" ] && channel="${channel}-"
echo "$channel"
echo "$channel"
# REST OF DEFAULT VAULES
# The rest of default values are taken from the template
......@@ -333,11 +333,11 @@ qmp_wifi_get_default() {
qmp_configure_wifi_initial() {
#First we are going to configure default parameters if they are not present
[ -z "$(qmp_uci_get wireless)" ] && qmp_uci_set wireless qmp
[ -z "$(qmp_uci_get wireless.driver)" ] && qmp_uci_set wireless.driver $(qmp_wifi_get_default driver)
[ -z "$(qmp_uci_get wireless.country)" ] && qmp_uci_set wireless.country $(qmp_wifi_get_default country)
[ -z "$(qmp_uci_get wireless.bssid)" ] && qmp_uci_set wireless.bssid $(qmp_wifi_get_default bssid)
#First we are going to configure default parameters if they are not present
[ -z "$(qmp_uci_get wireless)" ] && qmp_uci_set wireless qmp
[ -z "$(qmp_uci_get wireless.driver)" ] && qmp_uci_set wireless.driver $(qmp_wifi_get_default driver)
[ -z "$(qmp_uci_get wireless.country)" ] && qmp_uci_set wireless.country $(qmp_wifi_get_default country)
[ -z "$(qmp_uci_get wireless.bssid)" ] && qmp_uci_set wireless.bssid $(qmp_wifi_get_default bssid)
#Changing to configured countrycode
iw reg set $(qmp_uci_get wireless.country)
......@@ -352,11 +352,11 @@ qmp_configure_wifi_initial() {
j=0
while [ ! -z "$(qmp_uci_get @wireless[$j])" ]; do
configured_mac="$(qmp_uci_get @wireless[$j].mac | tr [A-Z] [a-z])"
if [ "$configured_mac" == "$m" ]; then
if [ "$configured_mac" == "$m" ]; then
#If we found configured device, we are going to check all needed parameters
found=1
found=1
device="$(qmp_get_dev_from_mac $m)"
id_configured="$id_configured $j"
id_configured="$id_configured $j"
echo "Found configured device: $m"
[ -z "$(qmp_uci_get @wireless[$j].mode)" ] && qmp_uci_set @wireless[$j].mode $(qmp_wifi_get_default mode $device)
[ -z "$(qmp_uci_get @wireless[$j].name)" ] && qmp_uci_set @wireless[$j].name $(qmp_wifi_get_default name)
......@@ -366,23 +366,23 @@ qmp_configure_wifi_initial() {
# if not, using default one
sleep 1 && mode="$(qmp_uci_get @wireless[$j].mode)"
channel="$(qmp_uci_get @wireless[$j].channel)"
if [ -z "$channel" ]; then
if [ -z "$channel" ]; then
qmp_uci_set @wireless[$j].channel $(qmp_wifi_get_default channel $device $mode)
else
newchan="$(qmp_check_channel $device $channel $mode)"
if [ "$newchan" != "$channel" ]; then
qmp_log Warning: "Channel $channel for device $device in mode $mode is not right, using default one"
qmp_uci_set @wireless[$j].channel $newchan
fi
fi
qmp_uci_set @wireless[$j].channel $newchan
fi
fi
qmp_uci_set @wireless[$j].device $device
break
fi
j=$(( $j + 1 ))
done
[ $found -eq 0 ] && to_configure="$to_configure $m"
done
......@@ -410,4 +410,4 @@ qmp_configure_wifi_initial() {
[ -z "$(qmp_uci_get wireless.driver)" ] && qmp_uci_set wireless.driver $(qmp_wifi_get_default driver)
[ -z "$(qmp_uci_get wireless.country)" ] && qmp_uci_set wireless.country $(qmp_wifi_get_default country)
[ -z "$(qmp_uci_get wireless.bssid)" ] && qmp_uci_set wireless.bssid $(qmp_wifi_get_default bssid)
}
}
......@@ -79,19 +79,19 @@ function print_hostname()
print(qmp.get_hostname())
end
function bw_test()
function bw_test()
if #op1 < 5 then
print_help()
os.exit(1)
print_help()
os.exit(1)
end
local bwt = qmpinfo.bandwidth_test(op1)
local bwt = qmpinfo.bandwidth_test(op1)
if bwt == nil then
print("Cannot connecto to "..op1.." netserver")
else
print ("Bandwidth: "..bwt.." Mbit/s")
end
end
print ("Bandwidth: "..bwt.." Mbit/s")
end
end
function nodes()
for _,n in ipairs(qmpinfo.nodes()) do
......@@ -120,7 +120,7 @@ if #arg < 1 then
end
local question = arg[1]
op1 = arg[2]
op1 = arg[2]
if question == "modes" then
print_modes()
......@@ -133,9 +133,9 @@ elseif question == "ipv4" then
elseif question == "hostname" then
print_hostname()
elseif question == "bwtest" then
bw_test()
bw_test()
elseif question == "nodes" then
nodes()
nodes()
elseif question == "key" then
key()
elseif question == "links" then
......
......@@ -63,7 +63,7 @@ function qmpinfo.get_modes(dev)
local iw = iwinfo[iwinfo.type(dev)]
if iw ~= nil then modes = iw.hwmodelist(dev) end
return modes
end
......@@ -76,33 +76,33 @@ function qmpinfo.get_txpower(dev)
table.insert(txpower_supported,v.dbm)
end
end
return txpower_supported
end
function qmpinfo.get_channels(dev)
local clist = {} -- output channel list
local iw = iwinfo[iwinfo.type(dev)]
local ch = {}
-- if there are not wireless cards, returning a dummy value
if iw == nil then
ch.channel=0
ch.adhoc=false
ch.ht40p=false
ch.ht40m=false
table.insert(clist,ch)
return clist
end
local clist = {} -- output channel list
local iw = iwinfo[iwinfo.type(dev)]
local ch = {}
-- if there are not wireless cards, returning a dummy value
if iw == nil then
ch.channel=0
ch.adhoc=false
ch.ht40p=false
ch.ht40m=false
table.insert(clist,ch)
return clist
end
local freqs = iw.freqlist(dev) --freqs list
local c -- current channel
local nc = 0 -- next channel
local pc = 0 -- previous channel
local adhoc
local ht40_support = qmpinfo.get_modes(dev).n
for i,f in ipairs(freqs) do
c = f.channel
......@@ -119,13 +119,13 @@ function qmpinfo.get_channels(dev)
-- 2.4Ghz band
if c < 15 then
if c < 4 then
if c < 4 then
ch.ht40p = true
elseif c < 10 then
ch.ht40m = true
elseif c < 10 then
ch.ht40m = true
ch.ht40p = true
else
else
ch.ht40m = true
end
......@@ -139,10 +139,10 @@ function qmpinfo.get_channels(dev)
else pc = freqs[i-1].channel
end
if nc ~= nil and nc-c == 4 then
ch.ht40p = true
if nc ~= nil and nc-c == 4 then
ch.ht40p = true
end
if pc ~= nil and c-pc == 4 then
ch.ht40m = true
end
......@@ -157,7 +157,7 @@ function qmpinfo.get_channels(dev)
table.insert(clist,ch)
end
end
return clist
end
......@@ -166,7 +166,7 @@ function qmpinfo.get_ipv4()
local ipv4 = {}
local ipv4_raw = util.exec("ip -4 a | grep inet | awk '{print $2}' | awk -F/ '{print $1}' | grep -v 127.0.0.1")
for _,v in ipairs(util.split(ipv4_raw)) do
if #util.trim(v) > 1 then
if #util.trim(v) > 1 then
table.insert(ipv4,util.trim(v))
end
end
......@@ -183,15 +183,15 @@ function qmpinfo.get_uname()
return uname
end
function qmpinfo.bandwidth_test(ip)
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
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 ".*:.*:"'))
......
wireless.@wifi-iface[#QMP_INDEX].mode=ap
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].mode=ap
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].device=#QMP_DEVICE
wireless.#QMP_DEVICE=wifi-device
wireless.#QMP_DEVICE.type=mac80211
......
wireless.@wifi-iface[#QMP_INDEX].mode=sta
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].device=#QMP_DEVICE
wireless.#QMP_DEVICE=wifi-device
wireless.#QMP_DEVICE.type=mac80211
......
wireless.@wifi-iface[#QMP_INDEX].mode=ap
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].mode=ap
wireless.@wifi-iface[#QMP_INDEX].ssid=#QMP_SSID
wireless.@wifi-iface[#QMP_INDEX].encryption=none
wireless.@wifi-iface[#QMP_INDEX].device=#QMP_DEVICE
wireless.#QMP_DEVICE=wifi-device
wireless.#QMP_DEVICE.type=atheros
......