Developing lightweight computation at the DSG edge

Commit 62681240 authored by Simó Albert i Beltran's avatar Simó Albert i Beltran
Browse files

Configure switch for RouterStationPro, closes #204.

parent 0ced4a70
......@@ -50,18 +50,21 @@ qmp_get_devices() {
for dev in $(uci get qmp.interfaces.mesh_devices 2>/dev/null); do
# Lookging if device is defined as LAN, in such case dev=br-lan, but only once
for landev in $(uci get qmp.interfaces.lan_devices 2>/dev/null); do
if [ "$landev" == "$dev" ]; then
if [ $brlan_enabled -eq 0 ]; then
dev="br-lan"
brlan_enabled=1
break
else
dev=""
break
# except eth1 for RouterStation Pro
if ! ( [[ "$dev" == "eth1" ]] && qmp_is_routerstationpro ) ; then
for landev in $(uci get qmp.interfaces.lan_devices 2>/dev/null); do
if [ "$landev" == "$dev" ]; then
if [ $brlan_enabled -eq 0 ]; then
dev="br-lan"
brlan_enabled=1
break
else
dev=""
break
fi
fi
fi
done
done
fi
[ -n "$dev" ] && devices="$devices $dev"
done
......@@ -105,6 +108,10 @@ qmp_attach_device_to_interface() {
uci set wireless.$wifi_config.network="$interface"
uci commit wireless
else
if [[ "$device" == "eth1" ]] && qmp_is_routerstationpro
then
device="eth1.1"
fi
uci add_list $conf.$interface.ifname="$device"
fi
}
......@@ -129,6 +136,34 @@ qmp_configure_rescue_ip() {
uci commit $conf
}
qmp_is_routerstationpro() {
cat /proc/cpuinfo | grep -q "^machine[[:space:]]*: Ubiquiti RouterStation Pro$"
}
qmp_configure_routerstationpro_switch() {
local vids="$@"
uci set network.eth1="switch"
uci set network.eth1.enable="1"
uci set network.eth1.enable_vlan="1"
uci set network.eth1.reset="1"
uci set network.mesh_ports_vid1="switch_vlan"
uci set network.mesh_ports_vid1.vlan="1"
uci set network.mesh_prots_vid1.vid="1"
uci set network.mesh_ports_vid1.device="eth1"
uci set network.mesh_ports_vid1.ports="0t 4"
for vid in $vids
do
uci set network.mesh_ports_vid$vid="switch_vlan"
uci set network.mesh_ports_vid$vid.vlan="$vid"
uci set network.mesh_ports_vid$vid.vid="$vid"
uci set network.mesh_ports_vid$vid.device="eth1"
uci set network.mesh_ports_vid$vid.ports="0t 2t 3t"
done
}
qmp_get_ip6_slow() {
local addr_prefix="$1"
......@@ -439,7 +474,15 @@ qmp_configure_network() {
qmp_configure_prepare $conf
if qmp_uci_test qmp.interfaces.configure_switch ; then
if qmp_uci_test qmp.interfaces.mesh_devices && qmp_uci_test qmp.networks.mesh_protocol_vids && qmp_uci_test qmp.networks.mesh_vid_offset; then
local vids="$(uci -q get qmp.networks.mesh_protocol_vids | awk -F':' -v RS=" " '{print $2 + '$(uci -q get qmp.networks.mesh_vid_offset)'}')"
fi
if [[ -n "$vids" ]] && qmp_is_routerstationpro ; then
qmp_configure_routerstationpro_switch "$vids"
elif qmp_uci_test qmp.interfaces.configure_switch ; then
local switch_device="$(uci get qmp.interfaces.configure_switch)"
......@@ -460,13 +503,10 @@ qmp_configure_network() {
if qmp_uci_test qmp.interfaces.mesh_devices && qmp_uci_test qmp.networks.mesh_protocol_vids && qmp_uci_test qmp.networks.mesh_vid_offset; then
for protocol_vid in $(uci get qmp.networks.mesh_protocol_vids); do
if [[ -n "$vids" ]] ; then
local vid_suffix="$(echo $protocol_vid | awk -F':' '{print $2}')"
local vid_offset="$(uci get qmp.networks.mesh_vid_offset)"
local vid="$(( $vid_offset + $vid_suffix ))"
for vid in $vids; do
local mesh_ports="mesh_ports_vid${vid}"
......@@ -579,11 +619,19 @@ qmp_configure_network() {
done
# Configuring rescue IPs only if the device is not LAN nor WAN
[ "$dev" != "br-lan" ] && {
isWan=0
for w in $(qmp_get_devices wan); do [ "$w" == "$dev" ] && isWan=1; done
[ $isWan -eq 0 ] && qmp_configure_rescue_ip $dev
}
if
[ "$dev" != "br-lan" ] \
&& \
! \
{
qmp_get_devices lan
qmp_get_devices wan
} \
| tr " " "\n" \
| grep -q "^$dev$"
then
qmp_configure_rescue_ip $dev
fi
counter=$(( $counter + 1 ))
done
......
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