因此,我最近编写了一个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);
谷歌,什么是粒度 https://www.google.com/webhp?hl=all&gws_rd=ssl#hl=en&q=ns2+what+is+granularity
是的。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):应用工具https://github.com/WiNG-NITK/APP-Tool
例如,APP Tool→throughput→image
相关问题 更多 >
编程相关推荐