Commit b2c9239d authored by Vitaly Lipatov's avatar Vitaly Lipatov

check_connectivity: cleanup and improve code

parent f6613331
...@@ -98,13 +98,6 @@ apply_state() ...@@ -98,13 +98,6 @@ apply_state()
esac esac
} }
ALTSPEED=
OLDALTSPEED=
OLDAVERAGE=0
OLDMAINLOAD=0
OLDTX=0
CURCOUNT=0
CURDISCOUNT=2
calc_distance() calc_distance()
{ {
...@@ -113,20 +106,17 @@ calc_distance() ...@@ -113,20 +106,17 @@ calc_distance()
echo "$DISTANCE" echo "$DISTANCE"
} }
# slow torrent upload on
MAXAVERAGE=180 MAXAVERAGE=180
MAXTX=90 MAXTX=100
check_and_wait() channel_control()
{ {
# AVERAGE and MAINLOAD ######### channel control ##########
# note: sleep 10 inside
eval $(./get_traffic.sh)
# TODO: integrate? # TODO: integrate?
DISTANCE=$(calc_distance "$OLDMAINLOAD" "$MAINLOAD") DISTANCE=$(calc_distance "$OLDMAINLOAD" "$MAINLOAD")
# delay # delay
if [ "$DISTANCE" -ge 15 ] ; then if [ "$DISTANCE" -ge 5 ] ; then
CURCOUNT=$(($CURCOUNT+1)) CURCOUNT=$(($CURCOUNT+1))
else else
CURCOUNT=0 CURCOUNT=0
...@@ -141,41 +131,65 @@ check_and_wait() ...@@ -141,41 +131,65 @@ check_and_wait()
fi fi
OLDMAINLOAD=$CALCMAINLOAD OLDMAINLOAD=$CALCMAINLOAD
fi fi
}
torrent_control()
{
######### torrent control #############
# disable alt speed after timeout
if [ "$CURDISCOUNT" -gt 0 ] ; then
if [ "$CURDISCOUNT" = 1 ] ; then
ALTSPEED=0
fi
CURDISCOUNT=$(($CURDISCOUNT-1))
fi
# disable alt speed on heavy load or overload
if [ "$AVERAGE" -gt $MAXAVERAGE ] || [ "$TX_INET" -gt $MAXTX ] ; then
ALTSPEED=1
CURDISCOUNT=0
else
if [ "$ALTSPEED" = 1 ] && [ $CURDISCOUNT = 0 ] ; then
#DISTANCE=$(calc_distance "$OLDAVERAGE" "$AVERAGE")
#if [ "$DISTANCE" -ge 15 ] ; then
CURDISCOUNT=$(($CURDISCOUNT+10))
# OLDAVERAGE=$AVERAGE
#fi
fi
fi
}
ALTSPEED=
OLDALTSPEED=
OLDAVERAGE=0
OLDMAINLOAD=0
OLDTX=0
CURCOUNT=0
CURDISCOUNT=2
check_and_wait()
{
# AVERAGE and MAINLOAD
# note: sleep 10 inside
eval $(./get_traffic.sh)
# force alt speed when we work without reserve channel # force alt speed when we work without reserve channel
if [ "$STATE" != "both" ] ; then if [ "$STATE" != "both" ] ; then
ALTSPEED=1 ALTSPEED=1
CURDISCOUNT=0 CURDISCOUNT=0
CURCOUNT=0
else else
# on both channels # on both channels
# disable alt speed after timeout channel_control
if [ "$CURDISCOUNT" -gt 0 ] ; then torrent_control
if [ "$CURDISCOUNT" = 1 ] ; then
ALTSPEED=0
fi
CURDISCOUNT=$(($CURDISCOUNT-1))
fi
# disable alt speed on heavy load or overload
if [ "$AVERAGE" -gt $MAXAVERAGE ] || [ "$TX_INET" -gt $MAXTX ] ; then
ALTSPEED=1
CURDISCOUNT=0
else
if [ "$ALTSPEED" = 1 ] && [ $CURDISCOUNT = 0 ] ; then
#DISTANCE=$(calc_distance "$OLDAVERAGE" "$AVERAGE")
#if [ "$DISTANCE" -ge 15 ] ; then
CURDISCOUNT=$(($CURDISCOUNT+10))
# OLDAVERAGE=$AVERAGE
#fi
fi
fi
fi fi
if [ "$OLDALTSPEED" != "$ALTSPEED" ] ; then if [ "$OLDALTSPEED" != "$ALTSPEED" ] ; then
if [ "$ALTSPEED" = 1 ] ; then if [ "$ALTSPEED" = 1 ] ; then
write_log "$(date) average trafic $AVERAGE > $MAXAVERAGE or TX_INET $TX_INET > $MAXTX, enable alt speed" write_log "$(date) average trafic $AVERAGE > $MAXAVERAGE or TX_INET $TX_INET > $MAXTX or some uplink is broken, enable alt speed"
./transmission.sh --alt-speed ./transmission.sh --alt-speed
else else
write_log "$(date) average traffic $AVERAGE is normal, disable alt speed" write_log "$(date) average traffic $AVERAGE is normal, disable alt speed"
......
...@@ -19,8 +19,23 @@ TX_INET2=$tx ...@@ -19,8 +19,23 @@ TX_INET2=$tx
#echo $TX_INET $TX_INET2 #echo $TX_INET $TX_INET2
#echo $(($RX_INET+$RX_INET2)) $(($TX_INET+$TX_INET2)) #echo $(($RX_INET+$RX_INET2)) $(($TX_INET+$TX_INET2))
if [ -z "$TX_INET2" ] || [ -z "$RX_INET2" ] ; then
TX_INET2=0
RX_INET2=0
fi
if [ -z "$TX_INET" ] || [ -z "$RX_INET" ] ; then
TX_INET=0
RX_INET=0
fi
TXAVERAGE=$(($TX_INET2+$TX_INET)) TXAVERAGE=$(($TX_INET2+$TX_INET))
MAINLOAD=$((($TX_INET2-$TX_INET)/2+50)) #MAINLOAD=$((($TX_INET2-$TX_INET)/2+50))
MAINLOAD=$((100-$TX_INET))
# hack for do not use main channel if overloaded
[ "$MAINLOAD" -lt 15 ] && MAINLOAD=0
# round to 10 # round to 10
#MAINLOAD=$((($MAINLOAD/10)*10)) #MAINLOAD=$((($MAINLOAD/10)*10))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment