SHELL PROGRAMMING

Example 1:

To read rssi valuse and do some statistics

#para 1: test time
#para 2 : enable traffic control or not, 1-enalbe, 0-disable
#para 3: weight of RSSI-based throughput ,1 to 9
#para 4: weight of PER-based throughout, 9 to 1
#para 5: file to save rssi value
#para 6: file to save static rssi and Packet loss ratio

# metric about PER correlated throughput
# PER<0.5 100k
# 0.5-0.6 200k
# 0.6-0.7 400K
# 0.7-0.8 800K
# 0.8-0.9 1600K



if [ $# -lt 6 ]
then
echo "$0 : You must give/supply 6 parameters"
exit 1
fi

#rm $5

max_th=4500

time_tick=`expr $1 \* 10`
total_rssi=0
total_retry=0
total_ack=0
prev_retry=`cat /proc/driver/aironet/eth1/Stats |grep RetryLong |awk '{print $2}'`
prev_ack=`cat /proc/driver/aironet/eth1/Stats |grep RxAck |awk '{print $2}'`
for (( i=0; i<$time_tick ; i++))
do
per_rssi=0
for ((j=0;j<10;j++))
do
rssi_cur=`cat /proc/driver/aironet/eth1/Status |grep Strength |awk '{print $3}'`
echo $rssi_cur >> $5
per_rssi=`expr $per_rssi + $rssi_cur`
# sleep 0.01s
done
cur_retry=`cat /proc/driver/aironet/eth1/Stats |grep RetryLong |awk '{print $2}'`
per_retry=`expr $cur_retry - $prev_retry`
prev_retry=$cur_retry

cur_ack=`cat /proc/driver/aironet/eth1/Stats |grep RxAck |awk '{print $2}'`
per_ack=`expr $cur_ack - $prev_ack`
prev_ack=$cur_ack

((total_rssi=$total_rssi+$per_rssi))
per_rssi=`expr $per_rssi / 10`
# total_rssi=`expr $total_rssi + $per_rssi`
total_retry=`expr $total_retry + $per_retry`
((total_ack=$total_ack+$per_ack))
# echo "$per_rssi $per_retry $per_ack" >> $6



rs_index=`grep -w $per_rssi rtp | awk '{print $2}'`
#packet loss index from the table
#pl_index=`grep -w $per_rssi rtp | awk '{print $3}'`
#pl_index=`echo $pl_index*100 |bc`

#((pl_index=$pl_index/100))
#((ss_index=100-$pl_index))
if [ $per_ack -eq 0 ]
then
pl_value=100
else
((pl_value=100*$per_retry/($per_ack+$per_retry)))
fi
#!new change----------------------
#((div=($pl_value-$pl_index)*10/$ss_index))
#-------------------------------
#if [ $div -le 0 ]
#then
# div=1
#fi

#((c=$rs_index/$div))
((ss_value=100-$pl_value))
if [ $ss_value -lt 50 ]
then
div=32
elif [ $ss_value -lt 60 ]
then
div=16
elif [ $ss_value -lt 70 ]
then
div=4
elif [ $ss_value -lt 80 ]
then
div=3
elif [ $ss_value -lt 90 ]
then
div=2
else
div=1
fi

((c=$rs_index/$div))

b=kbit
c_rate=$c$b

echo "$per_rssi $per_retry $per_ack $div $c_rate" >> $6

#c_rate=4000kbit
#
#if [ $i -gt 300 ]
#then
# c_rate=250Kbit
#fi
#
#echo "traffic rate should be less $c_rate"

if [ $2 -eq 1 ]
then
if [ $i -gt 0 ]
then
tc qdisc del dev eth1 root
fi

tc qdisc add dev eth1 root handle 1: cbq avpkt 1024 bandwidth 11mbit
tc class add dev eth1 parent 1: classid 1:1 cbq rate $c_rate \
allot 1500 prio 1 bounded isolated

tc filter add dev eth1 parent 1: protocol ip prio 16 u32 \
match ip dst 10.0.0.1 flowid 1:1
fi
done
((avg_rssi=$total_rssi/$time_tick/10))
echo "average rssi is $avg_rssi"
echo "average retry_count is `expr $total_retry / $time_tick`"
echo "average ack_count is `expr $total_ack / $time_tick`"
echo "average PER is F: $total_retry and S: $total_ack"
if [ $2 -eq 1 ]
then
tc qdisc del dev eth1 root
fi