如何跟踪 ns3 中的节点移动时间?

How to trace the nodes movement time in ns3?

所以基本上,我在 NS3 中使用了 RandomwayPoint 模型,我得到了这样的节点结果:

/NodeList/5/$ns3::MobilityModel/CourseChange x = 10, y = 20
/NodeList/6/$ns3::MobilityModel/CourseChange x = 30, y = 40
/NodeList/7/$ns3::MobilityModel/CourseChange x = 50, y = 80
/NodeList/5/$ns3::MobilityModel/CourseChange x = 10, y = 20
/NodeList/6/$ns3::MobilityModel/CourseChange x = 30, y = 40
/NodeList/7/$ns3::MobilityModel/CourseChange x = 50, y = 80
/NodeList/5/$ns3::MobilityModel/CourseChange x = 10, y = 20
/NodeList/6/$ns3::MobilityModel/CourseChange x = 30, y = 40
/NodeList/7/$ns3::MobilityModel/CourseChange x = 50, y = 80
At time 2s client sent 1024 bytes to 10.1.2.4 port 9
At time 2.01596s server received 1024 bytes from 10.1.3.3 port 49153
At time 2.01596s server sent 1024 bytes to 10.1.3.3 port 49153
At time 2.02464s client received 1024 bytes from 10.1.2.4 port 9
......

但是如何记录每个节点移动的时间呢? 我认为最相关的代码是关于使用 Simulator:: Now().GetSeconds() 这是我写的代码:

     std::ostringstream oss2(std::ostringstream::ate);
     oss2.str("TimeStamp:");
     oss2 << Simulator::Now().GetSeconds ();
     std::cout << oss2.str() << "\t";

但是我得到的结果等于0。我对此感到困惑,如果有人能为我提供更好的解决方案并帮助我解决这个问题,我将不胜感激。

非常感谢。

逻辑正确,Simulator::Now()提供时间。您可以单行打印,不需要四行!

std::cout << "TimeStamp:" << Simulator::Now().GetSeconds() << "\t";

你得到 t=0sec 的事实,可能是因为在那之后节点没有 'change'。 CourseChange 回调仅在速度或速度(方向)发生变化时触发。如果节点以恒定速度移动,则不会触发。

根据您在之前 中的评论,您说您使用了 ListPositionAllocator。如果您在列表中只有一个条目,那么除了 t=0 时的初始值(您在输出中看到的内容)之外,它不会发生变化。