[packages] multiwan: updated load balancer algorithm
authorcraigc <craigc@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 11 May 2010 01:27:26 +0000 (01:27 +0000)
committercraigc <craigc@3c298f89-4303-0410-b956-a3cf2f4a3e73>
Tue, 11 May 2010 01:27:26 +0000 (01:27 +0000)
git-svn-id: svn://svn.openwrt.org/openwrt/packages@21424 3c298f89-4303-0410-b956-a3cf2f4a3e73

net/multiwan/Makefile
net/multiwan/files/usr/bin/multiwan

index 563b8cc..93216d1 100644 (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
 
index f94166a..6997415 100755 (executable)
@@ -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"