简体   繁体   English

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

[英]How to trace the nodes movement time in ns3?

So basically, I used RandomwayPoint model in NS3 and I got the result of nodes like this: 因此,基本上,我在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
......

But how to record the time of the each node's movement? 但是如何记录每个节点运动的时间呢? I think the most relevant code is about using Simulator:: Now().GetSeconds() Here is the code I wrote: 我认为最相关的代码是关于使用Simulator:: Now().GetSeconds()这是我编写的代码:

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

But I got the result equals to 0s. 但是我得到的结果等于0。 I felt confused about this, I would appreciate that if anyone can offer me a better solution and help me figure this out. 我对此感到困惑,如果有人可以为我提供更好的解决方案并帮助我解决问题,我将不胜感激。

ManyThanks. 非常感谢。

The logic is correct, Simulator::Now() provides the time. 逻辑是正确的, Simulator::Now()提供了时间。 You can print it in a single line, no need for four! 您可以将其打印在一行中,而无需四行!

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

The fact that you got t=0sec, probably is due to the fact that the nodes do not 'change' after that. 您得到t = 0sec的事实,可能是由于此后节点没有“改变”的事实。 CourseChange callback is fired only during a change in the speed or velocity (direction). 仅在速度或速度(方向)发生更改时才触发CourseChange回调。 If the node is moving with constant speed, it will not fire. 如果节点以恒定速度移动,则不会触发。

Following your comment in the previous post , you said you have used ListPositionAllocator. 在上一篇文章中发表评论之后 ,您说您已使用ListPositionAllocator。 If you only have a single entry in the list, then it will not change apart from the initial at t=0 (what you see in the output). 如果列表中只有一个条目,则它不会与t = 0处的初始条目(在输出中看到的)分开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM