问题
So basically, I used RandomwayPoint model in NS3 and I got the result of nodes like this:
/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:
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. I felt confused about this, I would appreciate that if anyone can offer me a better solution and help me figure this out.
ManyThanks.
回答1:
The logic is correct, Simulator::Now()
provides the time. 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. CourseChange callback is fired only during a change in the speed or velocity (direction). 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. 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).
来源:https://stackoverflow.com/questions/44629448/how-to-trace-the-nodes-movement-time-in-ns3