cmd.pl
来自「采用蚂蚁算法实现ad hoc网络路由协议,平台为ns2」· PL 代码 · 共 97 行
PL
97 行
#!/usr/bin/perl$rcv = 0;$snt = 0;$tot = 0;$drp = 0;$rst = 0;$fwd = 0;$lat = 0;$started = 0;while (<>) { # extract the time of the first packet sent if (!$started){ $started = 1; /-t (\S+)/; $starttime = $1; } # extract the time of the last packet in the simulation if (/-t (\S+)/){ $finishtime = $1; } # fill array with receive times of app packets if (/^r.*-t (\S+).*-Nl AGT.*-Ii (\d+)/){ $rcv++; $recd[$2] = $1; } # fill array with send times of app packets if (/^s.*-t (\S+).*-Nl AGT.*-Ii (\d+)/){ $snt++; $sent[$2] = $1; } # count number of DSDV routing packets sent if (/^s.*message/){ $rst++; } # count number of AODV routing packets sent if (/^s.*AODV/){ $rst++; } # count number of SWARM routing packets sent if (/^s.*swarm/){ $rst++; } # count number of DSR routing packets sent if (/^s.*DSR/){ $rst++; } # count number of dropped packets if (/^d/){ $drp++; } # count number of app packets forwarded if (/^f.*tcp/){ $fwd++; } $tot++;}for ($i = 0; $i < $snt; $i++){ if (!(!($sent[$i]) || !($recd[$i]))){ $lat += ($recd[$i] - $sent[$i]); }}printf " %d %d %d %d %d %f %d %f %f %f\n" ,$snt, $rst, $rcv, $drp, $fwd, ($lat/$snt), $tot, $starttime, $finishtime, ($finishtime-$starttime);#printf "\nTotal application packets sent ... %d\n", $snt;#printf "Total routing packets sent ... %d\n", $rst;#printf "Total application packets received ... %d\n", $rcv;#printf "Total packets dropped ... %d\n", $drp;#printf "Total application packets forwarded... %d\n", $fwd;#printf "Average Application packet delay ... %f\n", ($lat/$snt);#printf "\nLines processed is ... %d\n\n", $tot;#printf "Start Time ... %f\n", $starttime;#printf "Finish Time ... %f\n", $finishtime;#printf "Elapsed Time ... %f\n\n\n", $finishtime - $starttime;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?