用于从跟踪文件 ns-3 计算延迟的 awk 脚本

awk script to calculate delay from trace file ns-3

我想在下面的跟踪文件中测量传输和接收数据包之间的时间。

输入:

 + 0.01 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.01 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.0200001 /NodeList/0/DeviceList/2/$ns3::PointToPointNetDevice/MacRx
 + 0.11 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.11 /NodeList/1/DeviceList/1/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.12 /NodeList/0/DeviceList/2/$ns3::PointToPointNetDevice/MacRx
 + 0.12 /NodeList/0/DeviceList/3/$ns3::PointToPointNetDevice/TxQueue/Enqueue
 - 0.12 /NodeList/0/DeviceList/3/$ns3::PointToPointNetDevice/TxQueue/Dequeue
 r 0.120001 /NodeList/2/DeviceList/2/$ns3::PointToPointNetDevice/MacRx

这里+代表发送数据,r代表接收数据。跟踪文件中的第二列显示时间。

如何使用 awk 代码测量整个文件的 r 和 + 之间的时间?

预期输出如下:

输出:

  0.0100001
  0.01
  0.000001

如有帮助,将不胜感激

我生成了自己的跟踪文件,叫做trace,如下:

+ 0.1 Stuff stuff and more stuff
- 0.2 Yet more stuff
r 0.4 Something new
+ 0.8 Something else, not so new
- 1.6 Jiggery
r 3.2 Pokery
+ 6.4 Higgledy Piggledy

那么,我会用 awk 来处理你的问题,如下所示:

awk '/^+/{tx=}  /^r/{rx=; d=rx-tx; = "(d=" d ")"} 1' trace

示例输出

+ 0.1 Stuff stuff and more stuff
- 0.2 Yet more stuff
r(d=0.3) 0.4 Something new
+ 0.8 Something else, not so new
- 1.6 Jiggery
r(d=2.4) 3.2 Pokery
+ 6.4 Higgledy Piggledy

也就是说... "If you see a line starting with +, save the second field as variable tx. If you see a line starting with r, save the second field as variable rx. Calculate the difference between rx and tx and save it as d. Rebuild the first field of the line by appending (d=variable d) to the end of whatever it was. The 1 at the end tells awk to do its natural thing - i.e. print the line."