From: Craig M. Coffee Date: Tue, 11 May 2010 01:27:26 +0000 (+0000) Subject: [packages] multiwan: updated load balancer algorithm X-Git-Url: http://git.openwrt.org/?p=openwrt%2Fsvn-archive%2Farchive.git;a=commitdiff_plain;hb=884fcdfbfd60cfd236a5d96b89a691167979b225 [packages] multiwan: updated load balancer algorithm SVN-Revision: 21424 --- diff --git a/net/multiwan/Makefile b/net/multiwan/Makefile index 563b8cc993..93216d12d3 100644 --- a/net/multiwan/Makefile +++ b/net/multiwan/Makefile @@ -8,8 +8,8 @@ include $(TOPDIR)/rules.mk PKG_NAME:=multiwan -PKG_VERSION:=1.0.7 -PKG_RELEASE:=2 +PKG_VERSION:=1.0.8 +PKG_RELEASE:=1 include $(INCLUDE_DIR)/package.mk diff --git a/net/multiwan/files/usr/bin/multiwan b/net/multiwan/files/usr/bin/multiwan index f94166a34b..6997415ee6 100755 --- a/net/multiwan/files/usr/bin/multiwan +++ b/net/multiwan/files/usr/bin/multiwan @@ -638,7 +638,10 @@ local pre_nexthop_chk local rand_probability local last_probability local total_weight +local total_wans local i +local x +local y echo "## Refreshing Load Balancer ##" @@ -658,7 +661,10 @@ ip route flush table 123 > /dev/null 2>&1 done total_weight=0 +total_wans=0 last_probability=0 +x=0 +y=0 iptables -F MultiWanLoadBalancer -t mangle @@ -672,6 +678,7 @@ ifname=$(query_config ifname $group) weight=`uci -q -P /var/state get multiwan.${group}.weight` if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then total_weight=$(expr $total_weight + $weight) + total_wans=$i fi done @@ -687,12 +694,14 @@ weight=`uci -q -P /var/state get multiwan.${group}.weight` if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight" -rand_probability=$(expr $(expr $weight \* 100) / $total_weight + $last_probability) -last_probability=$rand_probability +y=$last_probability +last_probability=$(expr $x / $(expr $wancount - $i + 1)) +rand_probability=$(expr $(expr $(expr $weight \* 100) / $total_weight) + $last_probability + $y) +x=$rand_probability if [ $rand_probability -lt 10 ]; then rand_probability="0.0${rand_probability}" - elif [ $rand_probability -lt 100 -a $i != $wancount ]; then + elif [ $rand_probability -lt 100 -a $i != $total_wans ]; then rand_probability="0.${rand_probability}" else rand_probability="1.0"