[packages] multiwan: updated load balancer algorithm
authorCraig M. Coffee <cmcoffee@gmail.com>
Tue, 11 May 2010 01:27:26 +0000 (01:27 +0000)
committerCraig M. Coffee <cmcoffee@gmail.com>
Tue, 11 May 2010 01:27:26 +0000 (01:27 +0000)
SVN-Revision: 21424

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

index 563b8cc993d9a4b80c5ff338807e8b7903cec657..93216d12d3b3169bd2eb98d227a1d3350f92b4f7 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 f94166a34b244a0e9c14338666bf58fb9adfb636..6997415ee6f5521e37508f6b495e58cb892afcf8 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"