我需要以ns2计算平均数据包传输速度。我必须在awk程序中编写这个公式。但我不知道该怎么做。
n
是接收到的数据包的数量,s
是数据包传输时的距离。任何答案都会非常有帮助。感谢。
答案 0 :(得分:0)
function topla( array ) {sum=0; for (i in array) {sum=sum+250/array[i];}return sum;}
BEGIN {
total_packets_sent = 0;
total_packets_received = 0;
total_packets_dropped = 0;
first_packet_sent = 0;
last_packet_sent = 0;
last_packet_received = 0;}
{event = $1; time = $2; node = $3; type = $4; reason = $5; packetid = $6;
if ( time < simulation_start || simulation_start == 0 )
simulation_start = time;
if ( time > simulation_end )
simulation_end = time;
if ( type == "AGT" ) {
nodes[node] = node; # to count number of nodes
if ( time < node_start_time[node] || node_start_time[node] == 0 )
node_start_time[node] = time;
if ( time > node_end_time[node] )
node_end_time[node] = time;
if ( event == "s" ) {
flows[node] = node; # to count number of flows
if ( time < first_packet_sent || first_packet_sent == 0 )
first_packet_sent = time;
if ( time > last_packet_sent )
last_packet_sent = time;
# rate
packets_sent[node]++;
total_packets_sent++;
# delay
pkt_start_time[packetid] = time;
}
else if ( event == "r" ) {
if ( time > last_packet_received )
last_packet_received = time;
# throughput
packets_received[node]++;
total_packets_received++;
# delay
pkt_end_time[packetid] = time;
}
}}`
END {
# delay
for ( pkt in pkt_end_time) {
end = pkt_end_time[pkt];
start = pkt_start_time[pkt];
delta = end - start;
if ( delta > 0 ) {
delay[pkt] = delta;
}
}
result=topla(delay)/total_packets_received;
printf(result)
}
我写了这个awk程序。但它给出了除零尝试误差的分割。我在topla函数中写入传输范围为250,但我没有得到我想要的结果。我该如何写出传输范围?