analyse2.pl

来自「采用蚂蚁算法实现ad hoc网络路由协议,平台为ns2」· PL 代码 · 共 78 行

PL
78
字号
#!/usr/bin/perl#counting by source, how much sent/received$appPacketsSent = 0;$appPacketsReceived = 0;$appBytesSent = 0;$appBytesReceived = 0;$lastAppPacketsSent =0;$lastAppPacketsReceived =0;$tick = 5;$lastTick=0-$tick;printf "Time, CumAppSent, CumAppRecv, CumBytesSent, CumBytesRecv, CumPacketDeliveryRatioTotal, AppSent, AppRecv, PacketDeliveryRatioLast\n";while (<>) {    if(/-t (\S+)/)    {    	$time=$1;		if($time > ($lastTick+$tick) ) 	{	    $lastTick = $lastTick + $tick;	    ($thisSent, $thisRecv) = ($appPacketsSent-$lastAppPacketsSent, 	    				$appPacketsReceived-$lastAppPacketsReceived);	    	    $lastAppPacketsReceived = $appPacketsReceived;	    $lastAppPacketsSent = $appPacketsSent;	    if($thisSent>0)	    {		printf "%f, %d, %d, %d, %d, %f, %d, %d, %f\n", $lastTick, 		    $appPacketsSent, $appPacketsReceived, 		    $appBytesSent, $appBytesReceived,		    ($appPacketsReceived/$appPacketsSent),		    $thisSent, $thisRecv,		    ($thisRecv/$thisSent);	    }	    else	    {		printf "%f, %d, %d, %d, %d, , %d, %d, \n", $lastTick, 		    $appPacketsSent, $appPacketsReceived, 		    $appBytesSent, $appBytesReceived,		    $thisSent, $thisRecv;	    }	}	if (/^.*-Nl AGT/)	{		# Packet sent/received by the app stack	    if (/^r.*-Is (\S+) -Id (\S+).*-Il (\S+)/)	    {	    	$appPacketsReceived++;		$appBytesReceived+=$3;		$pair = $1."->".$2;	    	$appPacketsReceived{$pair}++;		$appBytesReceived{$pair}+=$3;	    }	    if (/^s.*-Is (\S+) -Id (\S+).*-Il (\S+)/)	    {	    	$appPacketsSent++;		$appBytesSent+=$3;		$pair = $1."->".$2;	    	$appPacketsSent{$pair}++;		$appBytesSent{$pair}+=$3;	    }	}    }}printf "TOT, %d, %d, %d, %d, %f\n", 		$appPacketsSent, $appPacketsReceived, 		$appBytesSent, $appBytesReceived,		($appPacketsReceived/$appPacketsSent);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?