0
如何修改代碼以便按行和列列出所有值?NS2 AWK腳本繪製圖形
現在,下面的代碼直接引導我到計算的答案。
例如;
**GeneratedPackets = 2438
ReceivedPackets = 2386
Packet Delivery Ratio = 97.8671
Total Dropped Packets = 9
Average End-to-End Delay = 31.013 ms**
不過,我想這樣的事情,爲了繪製圖表中的數據:
1 X1 Y1
2 X2 Y2
3 X3 Y3
我曾嘗試方法就像使用這樣的命令: awk -f [scriptname] .awk [tracefilename] .tr> graph.xgr
但它只顯示上面的計算。
BEGIN {
seqno = -1;
droppedPackets = 0;
receivedPackets = 0;
count = 0;
}
{
#packet delivery ratio
if($4 == "AGT" && $1 == "s" && seqno < $6) {
seqno = $6;
} else if(($4 == "AGT") && ($1 == "r")) {
receivedPackets++;
} else if ($1 == "D" && $7 == "tcp" && $8 > 512){
droppedPackets++;
}
#end-to-end delay
if($4 == "AGT" && $1 == "s") {
start_time[$6] = $2;
} else if(($7 == "tcp") && ($1 == "r")) {
end_time[$6] = $2;
} else if($1 == "D" && $7 == "tcp") {
end_time[$6] = -1;
}
}
END {
for(i=0; i<=seqno; i++) {
if(end_time[i] > 0) {
delay[i] = end_time[i] - start_time[i];
count++;
}
else
{
delay[i] = -1;
}
}
for(i=0; i<count; i++) {
if(delay[i] > 0) {
n_to_n_delay = n_to_n_delay + delay[i];
}
}
n_to_n_delay = n_to_n_delay/count;
print "\n";
print "GeneratedPackets = " seqno+1;
print "ReceivedPackets = " receivedPackets;
print "Packet Delivery Ratio = " receivedPackets/(seqno+1)*100
"%";
print "Total Dropped Packets = " droppedPackets;
print "Average End-to-End Delay = " n_to_n_delay * 1000 " ms";
print "\n";
}
嘗試重新陳述您的問題。包含一個ns2跟蹤輸入,您可以在其中定義要跟蹤的ns2跟蹤文件的哪些元素以獲得所需的輸出。你所包含的awk腳本看起來與繪圖完全不相關。 – n0741337