所以我最近编写了一个python脚本,它解析ns2跟踪文件并计算吞吐量。我也有一个perl脚本,我从互联网上下载,做同样的事情,但有点不同。我很难理解粒度(在perl脚本中使用)的含义。有人可以帮帮我吗?谢谢。代码如下。
trace = open('window_size_23.tr' , 'r')
s = 0
prev = 0.0
start = 0.0
end = 0.0
for line in trace:
words = line.split(' ')
if line.startswith('r') and 'tcp' in line and words[3] == '1' and
words[8] == '0.0' and words[9] == '1.0':
s = s + int(words[5])
if prev == 0.0:
start = float(words[1])
prev = float(words[1])
end = prev
throughput = (s*8.0)/((end - start)*1000000)
print throughput, start, end
这是perl脚本
$infile=$ARGV[0];
$destnode=$ARGV[1];
$fromport=$ARGV[2];
$toport=$ARGV[3];
$granularity=$ARGV[4];
$sum=0;
$grantsum=0;
$clock=0;
open (DATA,"<$infile") || die "Can't open $infile $!";
while (<DATA>)
{
@x = split(' ');
if ($x[1]-$clock <= $granularity)
{
if ($x[0] eq 'r')
{
if ($x[3] eq $destnode && $x[8] eq $fromport && $x[9]
eq $toport)
{
if ($x[4] eq 'tcp')
{
$sum=$sum+$x[5];
$grantsum=$grantsum+$x[5];
}
}
}
}
else
{
$throughput=0.000008*$sum/$granularity;
print STDOUT "$clock $throughput\n";
$clock=$clock+$granularity;
if ($x[0] eq 'r' && $x[3] eq $destnode && $x[8] eq
$fromport && $x[9] eq $toport && $x[4] eq 'tcp')
{
$sum=$x[5];
$grantsum=$grantsum+$x[5];
}
else
{
$sum=0;
}
while ($x[1]-$clock > $granularity)
{
print STDOUT "$clock 0.0\n";
$clock=$clock+$granularity;
}
}
}
$throughput=0.000008*$sum/$granularity;
print STDOUT "$clock $throughput\n";
$clock=$clock+$granularity;
print STDERR "Avg throughput $fromport - $toport = ",
0.000008*$grantsum/$clock,"MBytes/sec \n";
close DATA;
exit(0);
答案 0 :(得分:0)
。 Example→“..粒度(即不同的抽象级别)..”
。 https://www.researchgate.net/post/Bandwidth_Estimation_in_ns212 →“..具有精细粒度时间戳(毫秒,如果不是微秒)。”
所有ns2 awk,perl脚本https://drive.google.com/file/d/0B7S255p3kFXNdkdRalVpWk56MmM/view?usp=sharing
分析工具(awk,python):APP-Tool https://github.com/WiNG-NITK/APP-Tool
示例,APP-Tool→吞吐量→图像