【问题标题】:Calculate average packet travel speed in NS2 using AWK使用 AWK 计算 NS2 中的平均数据包传输速度
【发布时间】:2017-11-02 03:38:38
【问题描述】:

我需要计算 ns2 中的平均数据包传输速度。我必须在 awk 程序中编写这个公式。但我不知道该怎么做。 n是接收到的包数,s是发送包时的距离。任何答案都会非常有帮助。谢谢。

【问题讨论】:

  • 欢迎来到 StackOverflow。 “输入图像描述”,即描述链接的数学公式的作用。然后编写伪代码来概述算法。然后应用您对 awk 的知识来编写您自己的尝试。然后在此处添加您的 awk 代码以提出特定问题。如果您对 awk 完全陌生,学习 awk 教程可能会有所帮助。您可能想先使用tour。制作minimal reproducible example 对你自己和试图帮助你的人来说都是一件非常有帮助的事情。
  • 向我们展示您的尝试,然后我们可以开始提供支持。
  • 你的公式是错误的!总和指数 (i) 从 n 变为 nts 都不依赖于 i

标签: awk ns2


【解决方案1】:
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,但我没有得到我想要的结果。我应该如何写传输范围?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多