Bug 898

Summary: Wrong example for Time ns3::Now (void)
Product: ns-3 Reporter: zhangbo2050
Component: documentationAssignee: ns-bugs <ns-bugs>
Status: RESOLVED INVALID    
Severity: trivial CC: craigdo, tomh
Priority: P5    
Version: ns-3.7   
Hardware: All   
OS: All   
URL: http://www.nsnam.org/doxygen-release/index.html

Description zhangbo2050 2010-04-27 22:46:36 UTC
The example given for this function is :

It is typically used as shown below to schedule an event which expires at the absolute time "2 seconds":

 Simulator::Schedule (Seconds (2.0) - Now (), &my_function);



Which, if I'm correct, should really be:

  Simulator::Schedule (Seconds (2.0) + Now (), &my_function);

Probably just a typo, though.

Zhang Bo
Comment 1 Craig Dowell 2010-04-27 22:59:15 UTC
Unless I'm hallucinating:

  Simulator::Schedule (Seconds (2.0) + Now (), &my_function);

If Now() is 0 seconds, this schedules an event for 2 + 0 = 2 seconds in the future; at absoulute 0 + 2 = 2 seconds.

If Now() is 1 seconds, this schedules an event for 2 + 1 = 3 seconds in the future; at absoulte time 1 + 3 = 4 seconds.

If Now() is 2 seconds, this schedules an event for 2 + 2 = 4 seconds in the future; at absolute time 2 + 4 = 6 seconds.

However, in this case:

 Simulator::Schedule (Seconds (2.0) - Now (), &my_function);

If Now() is 0 seconds, this schedules an event for 2 - 0 = 2 seconds in the future; at absolute time 0 + 2 = 2 seconds.

If Now() is 1 seconds, this schedules an event for 2 - 1 = 1 seconds in the future; at absolute time 1 + 1 = 2 seconds.

If Now() is 2 seconds, this schedules an event for 2 - 2 = 0 seconds in the future; at absolute time 2 + 0 = 2 seconds.

It seems to me that the comment is correct.