Developing lightweight computation at the DSG edge

Commit 7be88d59 authored by Roger Pueyo Centelles's avatar Roger Pueyo Centelles
Browse files

Merge branch 'master' into testing


Signed-off-by: default avatarRoger Pueyo Centelles <roger.pueyo@guifi.net>
parents 79367b0f 85bda55d
......@@ -317,15 +317,51 @@ qmp_tac() {
}
qmp_get_dec_node_id() {
PRIMARY_MESH_DEVICE="$(uci get qmp.interfaces.mesh_devices | awk '{print $1}')"
LSB_PRIM_MAC="$( qmp_get_mac_for_dev $PRIMARY_MESH_DEVICE | awk -F':' '{print $6}' )"
qmp_log "Getting decimal node id"
local DEVICE_ID=""
local PRIMARY_DEVICE=""
if qmp_uci_test qmp.node.device_id; then
qmp_log "Getting device_id from qMp config"
DEVICE_ID="$(uci get qmp.node.device_id)"
elif ! [ -z "$PRIMARY_MESH_DEVICE" ] ; then
DEVICE_ID=$LSB_PRIM_MAC
qmp_log "Device id: ${DEVICE_ID}"
fi
if [ -z "$DEVICE_ID" ] && qmp_uci_test qmp.node.primary_device; then
qmp_log "Getting primary_device from qMp config"
local QMPCONFIG_PRIMARY_DEVICE="$(uci get qmp.node.primary_device)"
if [ -e "/sys/class/net/$QMPCONFIG_PRIMARY_DEVICE" ]; then
PRIMARY_DEVICE=$QMPCONFIG_PRIMARY_DEVICE
qmp_log "Primary device found: ${PRIMARY_DEVICE}"
else
qmp_log "Primary device not found: ${QMPCONFIG_PRIMARY_DEVICE}"
fi
fi
if [ -z "$DEVICE_ID" ] && [ -z "$PRIMARY_DEVICE" ] && \
qmp_uci_test qmp.interfaces.mesh_devices; then
qmp_log "Getting first mesh device from qMp config"
qmp_log "Found mesh devices: $(uci get qmp.interfaces.mesh_devices)"
local PRIMARY_DEVICE="$(uci get qmp.interfaces.mesh_devices | awk '{print $1}')"
qmp_log "Mesh primary device: $PRIMARY_DEVICE"
fi
if [ -n "$PRIMARY_DEVICE" ]; then
qmp_log "Getting MAC for device $PRIMARY_DEVICE"
LSB_PRIM_MAC="$( qmp_get_mac_for_dev $PRIMARY_DEVICE | awk -F':' '{print $6}' )"
qmp_log "Primary device LSBs: $LSB_PRIM_MAC"
if [ -n $LSB_PRIM_MAC ]; then
DEVICE_ID=${LSB_PRIM_MAC}
fi
fi
if [ -n "$DEVICE_ID" ]; then
qmp_log "Decimal node id: $(printf %d 0x$DEVICE_ID)"
echo "$(printf %d 0x$DEVICE_ID)"
else
qmp_log "Decimal node id not found, returning 0xABCD."
echo "$(printf %d 0xABCD)"
fi
echo $(printf %d 0x$DEVICE_ID)
}
# Returns the prefix /XX from netmask
......
......@@ -203,42 +203,74 @@ qmp_configure_smart_network() {
local dev=""
local phydevs=""
local ignore_devs=""
local novlan=""
local default_lan=$(qmp_get_openwrt_default_network "lan")
local default_wan=$(qmp_get_openwrt_default_network "wan")
local all_sysclassnet_devices=""
for dev in $(ls /sys/class/net/); do
all_sysclassnet_devices="${dev} ${all_sysclassnet_devices}"
done
echo "Network devices detected in /sys/class/net:"
echo " - ${all_sysclassnet_devices}"
[ "$force" != "force" ] && {
ignore_devs="$(qmp_uci_get interfaces.ignore_devices)"
ignore_devs="$(qmp_uci_get interfaces.ignore_devices) "
[ -n "${ignore_devs}" ] && \
echo "Devices to ignore in qMp config:"
echo " - ${ignore_devs}"
}
# Detect physical devices in /sys/class/net
for dev in $(ls /sys/class/net/); do
[ -e /sys/class/net/$dev/device ] || [ dev == "eth0" ] && {
local id
local ignore=0
# Check if device is in the ignore list
# Check if device is in the qMp ignore list to skip it
for id in $ignore_devs; do
[ "$id" == "$dev" ] && ignore=1
done
# [Qin] The device might be a wired device (e.g. eth0) with a switch
# and two or more virtual switched devices (e.g. eth0.1, eth0.2)
# The device might be a wired device (e.g. eth0) with a managed switch to
# drive several ports. If it uses the old switch driver, virtual switched
# devices are named with a dot (e.g. eth0.1, eth0.2). We check for
# switched device that has the current device as its upper physical device
# and add them instead (processing eth0? => add eth0.1 and eth0.2)
for sdev in $(ls /sys/class/net/$dev/ | grep upper_$dev. | cut -d "_" -f2); do
phydevs="$phydevs $sdev\n"
phydevs="$phydevs $sdev"
ignore=1
# Add $dev to ignore list (only when different from $sdev, to avoid
# adding wireless devices to it)
[ "${dev}" != "${sdev}" ] && ignore_devs="$ignore_devs $dev"
done
# The device might be a wired device (e.g. eth0) with a managed switch to
# drive several ports. If it uses the new DSA switch driver, virtual
# switched devices are named like regular interfaces (e.g., lan1, lan2).
# We check for the "dsa" subdirectory in the physical device to skip it.
[ -e /sys/class/net/$dev/dsa ] && ignore=1 && ignore_devs="$ignore_devs $dev"
if [ $ignore -eq 0 ]; then
phydevs="$phydevs $dev\n"
phydevs="$phydevs $dev"
fi
}
done
phydevs="$(echo -e "$phydevs" | grep -v -e ".*ap$" | sort -u | tr -d ' ' \t)"
phydevs=$(for i in ${phydevs}; do echo $i | grep -v -e ".*ap$" | sed '/./,$!d'; done | sort -u | tr -d ' ' \t)
ignore_devs=$(for i in ${ignore_devs}; do echo $i | grep -v -e ".*ap$" | sed '/./,$!d'; done | sort -u | tr -d ' ' \t)
echo "Physical devices to process:"
echo " - "${phydevs}
[ -n "${ignore_devs}" ] && \
echo "Devices to ignore:" && \
echo " - "${ignore_devs}
# if force is not enabled, we are not changing the existing lan/wan/mesh (only adding new ones)
[ "$force" != "force" ] && {
lan="$(qmp_uci_get interfaces.lan_devices)"
wan="$(qmp_uci_get interfaces.wan_devices)"
mesh="$(qmp_uci_get interfaces.mesh_devices)"
novlan="$(qmp_uci_get interfaces.no_vlan_devices)"
}
local j=0
......@@ -268,17 +300,17 @@ qmp_configure_smart_network() {
# OpenWrt's defaults. This avoids the per-device hooks that swapped roles
for ddev in $default_lan; do
[ "$dev" == "$ddev" ] && {
lan="$lan $dev"
mesh="$mesh $dev"
novlan="$novlan $dev"
lan="$dev $lan"
mesh="$dev $mesh"
novlan="$dev $novlan"
continue
}
done
for ddev in $default_wan; do
[ "$dev" == "$ddev" ] && {
wan="$wan $dev"
mesh="$mesh $dev"
novlan="$novlan $dev"
wan="$dev $wan"
mesh="$dev $mesh"
novlan="$dev $novlan"
continue
}
done
......@@ -315,11 +347,14 @@ qmp_configure_smart_network() {
done
echo "Network devices found:"
echo "- LAN $lan"
echo "- MESH $mesh"
echo "- WAN $wan"
echo "- NO VLAN $novlan"
echo ""
echo "Smart network configuration result:"
echo " - LAN: ${lan}"
echo " - WAN: ${wan}"
echo " - Mesh: ${mesh}"
echo " - No VLAN: ${novlan}"
echo " - Ignored: ${ignore_devs}"
echo ""
# Writes the devices to the config
qmp_uci_set interfaces.lan_devices "$(echo $lan | sed -e s/"^ "//g -e s/" $"//g)"
......
......@@ -427,6 +427,7 @@ qmp_configure_wifi() {
qmp_wifi_get_default() {
local what="$1"
local device="$2"
qmp_log "Getting default ${what} for device ${device}"
# WIRELESS MODE
#
......@@ -524,6 +525,7 @@ qmp_wifi_get_default() {
# channel AdHoc is the last available (qmp_tac = inverse order) plus index*2+1 (1 3 5 ...)
[ "$mode" == "adhoc" ] || [ "$mode" == "80211s" ] || [ -z "$mode" ] && {
qmp_log "Getting default ${what} for device ${device} in mode ${mode}"
#this is global
ADHOC_INDEX=${ADHOC_INDEX:-0}
......@@ -553,6 +555,7 @@ qmp_wifi_get_default() {
# channel AP = ( node_id + index*3 ) % ( num_channels_ap) + 1
# channel is 1, 6 or 11 for coexistence and performance
[ "$mode" = "ap" -o "$mode" = "adhoc_ap" -o "$mode" = "80211s_aplan" ] && {
qmp_log "Getting default ${what} for device ${device} in mode ${mode}"
AP_INDEX=${AP_INDEX:-0}
......
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