Commit f6613331 authored by Vitaly Lipatov's avatar Vitaly Lipatov

check_connectivity: rewrite channels control code

parent 560eccab
...@@ -4,7 +4,11 @@ cd $(dirname $0) ...@@ -4,7 +4,11 @@ cd $(dirname $0)
write_log() write_log()
{ {
echo "$*" | tee -a /var/log/check_connectivity.log | mail -s "Etersoft router state is changed" vitaly.lipatov@gmail.com if [ -n "$FOREGROUND" ] ; then
echo "$*"
else
echo "$*" | tee -a /var/log/check_connectivity.log | mail -s "Etersoft router state is changed" vitaly.lipatov@gmail.com
fi
} }
fatal() fatal()
...@@ -94,9 +98,13 @@ apply_state() ...@@ -94,9 +98,13 @@ apply_state()
esac esac
} }
ALTSPEED=
OLDALTSPEED= OLDALTSPEED=
OLDAVERAGE= OLDAVERAGE=0
OLDMAINLOAD= OLDMAINLOAD=0
OLDTX=0
CURCOUNT=0
CURDISCOUNT=2
calc_distance() calc_distance()
{ {
...@@ -105,31 +113,72 @@ calc_distance() ...@@ -105,31 +113,72 @@ calc_distance()
echo "$DISTANCE" echo "$DISTANCE"
} }
MAXAVERAGE=180
MAXTX=90
check_and_wait() check_and_wait()
{ {
# AVERAGE and MAINLOAD # AVERAGE and MAINLOAD
# note: sleep 10 inside # note: sleep 10 inside
eval $(./get_traffic.sh) eval $(./get_traffic.sh)
# TODO: integrate?
DISTANCE=$(calc_distance "$OLDMAINLOAD" "$MAINLOAD") DISTANCE=$(calc_distance "$OLDMAINLOAD" "$MAINLOAD")
if [ "$DISTANCE" -ge 20 ] ; then
write_log "$(date) set main procent to $MAINLOAD for hop route table" # delay
./set_hop.sh $MAINLOAD if [ "$DISTANCE" -ge 15 ] ; then
OLDMAINLOAD=$MAINLOAD CURCOUNT=$(($CURCOUNT+1))
else
CURCOUNT=0
fi
if [ "$CURCOUNT" -ge 5 ] ; then
CALCMAINLOAD=$((($OLDMAINLOAD+$MAINLOAD)/2))
write_log "$(date) set main procent to $CALCMAINLOAD (step $CURCOUNT, target $MAINLOAD) for hop route table (TX=$TX_INET TX2=$TX_INET2)"
./set_hop.sh $CALCMAINLOAD
if [ "$CALCMAINLOAD" = "$MAINLOAD" ] ; then
CURCOUNT=0
fi
OLDMAINLOAD=$CALCMAINLOAD
fi fi
if [ "$STATE" != "both" ] || [ "$AVERAGE" -ge 170 ] ; then # force alt speed when we work without reserve channel
if [ "$STATE" != "both" ] ; then
ALTSPEED=1 ALTSPEED=1
CURDISCOUNT=0
else else
ALTSPEED=0 # on both channels
# 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
fi fi
if [ "$OLDALTSPEED" != "$ALTSPEED" ] ; then if [ "$OLDALTSPEED" != "$ALTSPEED" ] ; then
if [ "$ALTSPEED" = 1 ] ; then if [ "$ALTSPEED" = 1 ] ; then
write_log "$(date) average speed is too hi $AVERAGE, enable alt speed" write_log "$(date) average trafic $AVERAGE > $MAXAVERAGE or TX_INET $TX_INET > $MAXTX, enable alt speed"
./transmission.sh --alt-speed ./transmission.sh --alt-speed
else else
write_log "$(date) average speed is normal $AVERAGE, disable alt speed" write_log "$(date) average traffic $AVERAGE is normal, disable alt speed"
./transmission.sh --no-alt-speed ./transmission.sh --no-alt-speed
fi fi
OLDALTSPEED="$ALTSPEED" OLDALTSPEED="$ALTSPEED"
...@@ -155,5 +204,12 @@ while true ; do ...@@ -155,5 +204,12 @@ while true ; do
done done
} }
if [ "$1" = "foreground" ] ; then
FOREGROUND=1
write_log "Running in foreground"
main_cycle
exit
fi
main_cycle & main_cycle &
echo $! >/var/run/check_connectivity.pid echo $! >/var/run/check_connectivity.pid
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