[packages] multiwan: updated load balancer algorithm

git-svn-id: svn://svn.openwrt.org/openwrt/packages@21424 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
craigc 2010-05-11 01:27:26 +00:00
parent 6752f94032
commit a585129a0e
2 changed files with 14 additions and 5 deletions

View File

@ -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

View File

@ -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"