Advertisement
shamiul93

shell

Jan 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.72 KB | None | 0 0
  1. #INPUT: output file AND number of iterations
  2.  
  3. outputDirectory="output_wired/"
  4. rm -rf $outputDirectory
  5. rm -rf Output/
  6. rm -rf QueueMonitor/
  7. mkdir -p QueueMonitor/
  8. mkdir -p $outputDirectory
  9.  
  10. tclFile="my_wired.tcl"
  11.  
  12.  
  13. iteration_float=1.0;
  14. under="_";
  15.  
  16. outFile="$outputDirectory""OUT"
  17. tempFile="$outputDirectory""TEMPFILE"
  18. graphData="$outputDirectory""GRAPH"
  19. nodeThrData="$outputDirectory""NodeThr"
  20.  
  21.  
  22. nNodesInit=20
  23. nFlowsInit=10
  24. pcktRateInit=100
  25. speedInit=5
  26.  
  27. nNodes=$nNodesInit
  28. nFlows=$nFlowsInit
  29. pcktRate=$pcktRateInit
  30. speed=$speedInit
  31.  
  32. iteration=$(printf %.0f $iteration_float);
  33.  
  34.  
  35.  
  36. echo 'Which parameter do you want to vary?'
  37. echo '1. # of Nodes'
  38. echo '2. # of flows'
  39. echo '3. Packet rate'
  40.  
  41. # read param
  42.  
  43. echo 'Please enter the # of iteration'
  44. read nIter
  45.  
  46. round=1
  47.  
  48. while [ $round -le $nIter ]
  49. do
  50.  
  51. for (( count=0; count<=$nNodes; count++ ))
  52. do
  53. currNodeThr["$count"]=0
  54. done
  55.  
  56. ###############################START A ROUND
  57.  
  58. echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  59. echo " ROUND : $round "
  60. echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  61.  
  62. l=0;thr=0.0;del=0.0;s_packet=0.0;r_packet=0.0;d_packet=0.0;del_ratio=0.0;
  63. dr_ratio=0.0;time=0.0;total_retransmit=0.0;rTotalDelay=0.0;
  64.  
  65. i=0
  66. while [ $i -lt $iteration ]
  67. do
  68. #################START AN ITERATION
  69. echo "################EXECUTING $(($i+1)) th ITERATION################"
  70.  
  71. ns $tclFile $nNodes $nFlows $pcktRate
  72. echo "SIMULATION COMPLETE. BUILDING STAT..."
  73.  
  74. qf="QueueMonitor/qMonitor_round-$round-iteration-$iteration"
  75. awk -f queue_awk.awk qm.out > $qf
  76.  
  77.  
  78. flnm="$outputDirectory""tem""$round"
  79. awk -f wired_awk.awk wired.tr > $tempFile
  80. cp wired.tr $flnm
  81.  
  82.  
  83. # ======================================================================
  84. # UPDATING THE VALUES IN EACH ITERATION
  85. # ======================================================================
  86. while read val
  87. do
  88.  
  89. l=$(($l+1))
  90.  
  91. if [ "$l" == "1" ]; then
  92. thr=$(echo "scale=5; $thr+$val/$iteration_float" | bc)
  93. # echo -ne "throughput: $thr "
  94. elif [ "$l" == "2" ]; then
  95. del=$(echo "scale=5; $del+$val/$iteration_float" | bc)
  96. # echo -ne "delay: "
  97. elif [ "$l" == "3" ]; then
  98. s_packet=$(echo "scale=5; $s_packet+$val/$iteration_float" | bc)
  99. # echo -ne "send packet: "
  100. elif [ "$l" == "4" ]; then
  101. r_packet=$(echo "scale=5; $r_packet+$val/$iteration_float" | bc)
  102. # echo -ne "received packet: "
  103. elif [ "$l" == "5" ]; then
  104. d_packet=$(echo "scale=5; $d_packet+$val/$iteration_float" | bc)
  105. # echo -ne "drop packet: "
  106. elif [ "$l" == "6" ]; then
  107. del_ratio=$(echo "scale=5; $del_ratio+$val/$iteration_float" | bc)
  108. # echo -ne "delivery ratio: "
  109. elif [ "$l" == "7" ]; then
  110. dr_ratio=$(echo "scale=5; $dr_ratio+$val/$iteration_float" | bc)
  111. # echo -ne "drop ratio: "
  112. elif [ "$l" == "8" ]; then
  113. time=$(echo "scale=5; $time+$val/$iteration_float" | bc)
  114. # echo -ne "time: "
  115. elif [ "$l" == "9" ]; then
  116. rTotalDelay=$(echo "scale=5; $rTotalDelay+$val/$iteration_float" | bc)
  117. else
  118. nodeIdxVal="$(echo "$val" | cut -d' ' -f1)"
  119. # echo "val == $val"
  120. thisNodeThrVal="$(echo "$val" | cut -d' ' -f2)"
  121.  
  122.  
  123. currNodeThr["$nodeIdxVal"]=$(echo "scale=5; ${currNodeThr[$nodeIdxVal]}+$thisNodeThrVal/$iteration_float" | bc)
  124. echo "node index = $nodeIdxVal, ${currNodeThr[$nodeIdxVal]}"
  125. fi
  126.  
  127. # echo "val: $val"
  128. done < $tempFile
  129.  
  130. i=$(($i+1))
  131. l=0
  132. done
  133.  
  134.  
  135. ########## OUTPUT FILE GENERATION
  136.  
  137. output_file="$outFile$under$round"
  138. echo "" > $output_file # clearing the output file
  139.  
  140.  
  141. echo "# of Nodes: $nNodes " >> $output_file
  142. echo "# of flows: $nFlows " >> $output_file
  143. echo "Packet size: $pcktRate " >> $output_file
  144.  
  145.  
  146. echo "" >> $output_file
  147. echo "" >> $output_file
  148. echo "" >> $output_file
  149.  
  150.  
  151. echo "Throughput: $thr " >> $output_file
  152. echo "AverageDelay: $del " >> $output_file
  153. echo "Sent Packets: $s_packet " >> $output_file
  154. echo "Received Packets: $r_packet " >> $output_file
  155. echo "Dropped Packets: $d_packet " >> $output_file
  156. echo "PacketDeliveryRatio: $del_ratio " >> $output_file
  157. echo "PacketDropRatio: $dr_ratio " >> $output_file
  158. echo "Total time: $time " >> $output_file
  159. echo "Total Delay: $rTotalDelay " >> $output_file
  160. # ==========================================================================
  161. ##############################
  162. echo "Initial setup: "
  163. echo "# of Nodes: $nNodes "
  164. echo "# of flows: $nFlows "
  165. echo "Packet size: $pcktRate "
  166.  
  167.  
  168. echo ""
  169. echo ""
  170. echo ""
  171.  
  172.  
  173. echo "Throughput: $thr "
  174. echo "AverageDelay: $del "
  175. echo "Sent Packets: $s_packet "
  176. echo "Received Packets: $r_packet "
  177. echo "Dropped Packets: $d_packet "
  178. echo "PacketDeliveryRatio: $del_ratio "
  179. echo "PacketDropRatio: $dr_ratio "
  180. echo "Total time: $time "
  181. echo "Total Delay: $rTotalDelay "
  182.  
  183.  
  184. ############################
  185. round=$(($round+1))
  186. #
  187. ########Plotting Graph
  188.  
  189.  
  190. if [ "$param" == "1" ]; then
  191. xax="No of nodes"
  192. elif [ "$param" == "2" ]; then
  193. xax="No of flows"
  194. elif [ "$param" == "3" ]; then
  195. xax="Packet Rate"
  196. fi
  197.  
  198.  
  199. for (( count=0; count<=$nNodes; count++ ))
  200. do
  201. echo "$count ${currNodeThr["$count"]}" >> $nodeThrData
  202. done
  203.  
  204. arr4[0]=""
  205. arr4[1]=""
  206. arr4[2]="Per-Node-Throughput-Round-"
  207.  
  208. arr5[0]=""
  209. arr5[1]=""
  210. arr5[2]="Per-Node-Throughput ( bit/second )"
  211.  
  212.  
  213. ii=2
  214. while [ $ii -ge 2 ]
  215. do
  216. tem=$(($round-1))
  217. gnuplot -persist -e "set terminal png size 700,500; set output '$outputDirectory${arr4[$ii]}VS$xax-round$under$tem.png';set title 'Wired (After Modification) : ${arr5[$ii]} vs $xax - Round - $tem'; set xlabel '$xax'; set ylabel '${arr5[$ii]}'; plot '$nodeThrData' using 1:$ii with lines"
  218. ii=$(($ii-1))
  219. done
  220.  
  221. # cp $nodeThrData t.txt
  222. rm -rf $nodeThrData
  223.  
  224.  
  225. if [ "$param" == "1" ]; then
  226. echo -ne "$nNodes " >> $graphData
  227. nNodes=$(($nNodesInit*$round))
  228. elif [ "$param" == "2" ]; then
  229. echo -ne "$nFlows " >> $graphData
  230. nFlows=$(($nFlowsInit*$round))
  231. elif [ "$param" == "3" ]; then
  232. echo -ne "$pcktRate " >> $graphData
  233. pcktRate=$(($pcktRateInit*$round))
  234. fi
  235.  
  236. # echo "throughput: $thr delay: $del deliver_rat: $del_ratio drop_rat: $dr_ratio" >> $graphData
  237. echo "$thr $del $del_ratio $dr_ratio" >> $graphData
  238.  
  239.  
  240. #####################END A ROUND
  241. done
  242.  
  243. if [ "$param" == "1" ]; then
  244. param="No of nodes"
  245. elif [ "$param" == "2" ]; then
  246. param="No of flows"
  247. elif [ "$param" == "3" ]; then
  248. param="Packet Rate"
  249. fi
  250.  
  251. arr[0]=""
  252. arr[1]=""
  253. arr[2]="Throughput"
  254. arr[3]="Average Delay"
  255. arr[4]="Packet Delivery Ratio"
  256. arr[5]="Packet Drop Ratio"
  257.  
  258. arr2[0]=""
  259. arr2[1]=""
  260. arr2[2]="Throughput ( bit/second )"
  261. arr2[3]="Average Delay ( second )"
  262. arr2[4]="Packet Delivery Ratio ( % )"
  263. arr2[5]="Packet Drop Ratio ( % )"
  264.  
  265. i=5
  266. while [ $i -ge 2 ]
  267. do
  268. gnuplot -persist -e "set terminal png size 700,500; set output '$outputDirectory${arr[$i]}VS$param.png';set title 'Wired (After Modification) : ${arr[$i]} vs $param'; set xlabel '$param'; set ylabel '${arr2[i]}'; plot 'output_wired/GRAPH' using 1:$i with lines"
  269.  
  270. # gnuplot -persist -e "set terminal png size 700,500; set output '$outputDirectory${arr[$i]}VS$param.png';set title 'Wired : ${arr[$i]} vs $param'; set xlabel '$param'; set ylabel '${arr2[i]}'; plot 'output_wired/GRAPH' using 1:$i with lines"
  271.  
  272. i=$(($i-1))
  273. done
  274.  
  275. # mv $outputDirectory "Output"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement