[packages] multiwan: Updated probabilities matrix, added rounding.
authorCraig M. Coffee <cmcoffee@gmail.com>
Wed, 12 May 2010 20:54:57 +0000 (20:54 +0000)
committerCraig M. Coffee <cmcoffee@gmail.com>
Wed, 12 May 2010 20:54:57 +0000 (20:54 +0000)
SVN-Revision: 21431

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

index 93216d12d3b3169bd2eb98d227a1d3350f92b4f7..cf3519fe171c8da2ef6e1ccf7e8687c56f05dc33 100644 (file)
@@ -8,7 +8,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=multiwan
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=multiwan
-PKG_VERSION:=1.0.8
+PKG_VERSION:=1.0.11
 PKG_RELEASE:=1
 
 include $(INCLUDE_DIR)/package.mk
 PKG_RELEASE:=1
 
 include $(INCLUDE_DIR)/package.mk
index 6997415ee6f5521e37508f6b495e58cb892afcf8..b6258050c2ec654714c3751f8f04ce9ab72c57ac 100755 (executable)
@@ -639,9 +639,11 @@ local rand_probability
 local last_probability
 local total_weight
 local total_wans
 local last_probability
 local total_weight
 local total_wans
+local roundme
+local roundlen
 local i
 local x
 local i
 local x
-local y
+local n
 
 echo "## Refreshing Load Balancer ##"
 
 
 echo "## Refreshing Load Balancer ##"
 
@@ -660,13 +662,10 @@ ip route flush table 123 > /dev/null 2>&1
                 done
          done
 
                 done
          done
 
+iptables -F MultiWanLoadBalancer -t mangle
+
 total_weight=0
 total_wans=0
 total_weight=0
 total_wans=0
-last_probability=0
-x=0
-y=0 
-
-iptables -F MultiWanLoadBalancer -t mangle
 
 i=0
 while [ $i -lt $wancount ]; do 
 
 i=0
 while [ $i -lt $wancount ]; do 
@@ -682,6 +681,12 @@ weight=`uci -q -P /var/state get multiwan.${group}.weight`
         fi
 done
 
         fi
 done
 
+last_probability=0
+roundme=0
+roundlen=0
+x=0
+n=0 
+
 i=0
 while [ $i -lt $wancount ]; do 
 i=`expr $i + 1` 
 i=0
 while [ $i -lt $wancount ]; do 
 i=`expr $i + 1` 
@@ -694,14 +699,24 @@ 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"
 
 if [ "$gateway" != "x" -a "$ifname" != "x" -a "$failchk" != "x" -a "$weight" != "disable" ]; then
 nexthop="$nexthop nexthop via $gateway dev $ifname weight $weight"
-y=$last_probability
-last_probability=$(expr $x / $(expr $wancount - $i + 1))
-rand_probability=$(expr $(expr $(expr $weight \* 100) / $total_weight) + $last_probability + $y)
+
+n=$(expr $n + $last_probability)
+last_probability=$(expr $x / $(expr $total_wans - $i + 1))
+rand_probability=$(expr $(expr $weight \* 1000) / $total_weight)
+roundlen=`expr length $rand_probability - 1`
+roundme=${rand_probability:$roundlen}
+rand_probability=$(echo $rand_probability | sed s/$roundme//)
+       
+       if [ $roundme -ge 5 ]; then
+               rand_probability=$(expr $rand_probability + 1)
+       fi
+
+rand_probability=$(expr $rand_probability + $n + $last_probability)
 x=$rand_probability
 
         if [ $rand_probability -lt 10 ]; then
                 rand_probability="0.0${rand_probability}"
 x=$rand_probability
 
         if [ $rand_probability -lt 10 ]; then
                 rand_probability="0.0${rand_probability}"
-        elif [ $rand_probability -lt 100 -a $i != $total_wans ]; then
+        elif [ $rand_probability -lt 100 ]; then
                 rand_probability="0.${rand_probability}"
         else
                 rand_probability="1.0"
                 rand_probability="0.${rand_probability}"
         else
                 rand_probability="1.0"