1.1 --- a/src/simulator/event-impl.h Tue Aug 26 15:34:57 2008 -0700
1.2 +++ b/src/simulator/event-impl.h Tue Aug 26 23:11:11 2008 -0700
1.3 @@ -167,7 +167,7 @@
1.4 void
1.5 EventImpl::Unref (void) const
1.6 {
1.7 - register uint32_t c;
1.8 + uint32_t c;
1.9
1.10 if (m_eventLock)
1.11 {
2.1 --- a/src/simulator/realtime-simulator-impl.cc Tue Aug 26 15:34:57 2008 -0700
2.2 +++ b/src/simulator/realtime-simulator-impl.cc Tue Aug 26 23:11:11 2008 -0700
2.3 @@ -47,11 +47,13 @@
2.4 static TypeId tid = TypeId ("ns3::RealtimeSimulatorImpl")
2.5 .SetParent<Object> ()
2.6 .AddConstructor<RealtimeSimulatorImpl> ()
2.7 +#ifdef PERMIT_WALLCLOCK_SIMULATION_TIME
2.8 .AddAttribute ("ReportSimulatedTime",
2.9 "Report simulated time in Simulator::Now if true, otherwise wall-clock time (will be different).",
2.10 BooleanValue (true),
2.11 MakeBooleanAccessor (&RealtimeSimulatorImpl::m_reportSimulatedTime),
2.12 MakeBooleanChecker ())
2.13 +#endif
2.14 .AddAttribute ("SynchronizationMode",
2.15 "What to do if the simulation cannot keep up with real time.",
2.16 EnumValue (SYNC_BEST_EFFORT),
2.17 @@ -641,6 +643,7 @@
2.18 Time
2.19 RealtimeSimulatorImpl::Now (void) const
2.20 {
2.21 +#ifdef PERMIT_WALLCLOCK_SIMULATION_TIME
2.22 //
2.23 // The behavior of Now depends on the setting of the "ReportSimulatedTime"
2.24 // attribute. If this is set to true, then Now will pretend that the realtime
2.25 @@ -665,19 +668,56 @@
2.26 {
2.27 return TimeStep (m_currentTs);
2.28 }
2.29 +#else // Do not PERMIT_WALLCLOCK_SIMULATION_TIME (the normal case)
2.30 + return TimeStep (m_currentTs);
2.31 +#endif // Do not PERMIT_WALLCLOCK_SIMULATION_TIME (the normal case)
2.32 }
2.33
2.34 Time
2.35 RealtimeSimulatorImpl::GetDelayLeft (const EventId &id) const
2.36 {
2.37 + //
2.38 + // If the event has expired, there is no delay until it runs. It is not the
2.39 + // case that there is a negative time until it runs.
2.40 + //
2.41 if (IsExpired (id))
2.42 {
2.43 return TimeStep (0);
2.44 }
2.45 +
2.46 +#ifdef PERMIT_WALLCLOCK_SIMULATION_TIME
2.47 + //
2.48 + // If we're running in real-time mode, it is possible that an event has been
2.49 + // entered into the system using ScheduleNow, which used the current real
2.50 + // time as the invocation time. By the time the scheduler gets around to
2.51 + // running the event, there will be an implied negative GetDelayLeft. From
2.52 + // a client point of view, if someone were to ScheduleNow an event and follow
2.53 + // that immediately by a GetDelayLeft on that event there would be a negative
2.54 + // GetDelayLeft since it is almost certain that at least one minimum time
2.55 + // quantum has passed. We don't allow these cases to happen. GetDelayLeft
2.56 + // reports zero if the event has expired OR if it is late.
2.57 + //
2.58 + if ((m_reportSimulatedTime == false) && Running ())
2.59 + {
2.60 + uint64_t tsEvent = id.GetTs ();
2.61 + uint64_t tsNow = m_synchronizer->GetCurrentRealtime ();
2.62 +
2.63 + if (tsEvent > tsNow)
2.64 + {
2.65 + return TimeStep (tsEvent - tsNow);
2.66 + }
2.67 + else
2.68 + {
2.69 + return TimeStep (0);
2.70 + }
2.71 + }
2.72 else
2.73 {
2.74 - return TimeStep (id.GetTs () - m_synchronizer->GetCurrentRealtime ());
2.75 + return TimeStep (id.GetTs () - m_currentTs);
2.76 }
2.77 +#else // Do not PERMIT_WALLCLOCK_SIMULATION_TIME (the normal case)
2.78 + return TimeStep (id.GetTs () - m_currentTs);
2.79 +#endif // Do not PERMIT_WALLCLOCK_SIMULATION_TIME (the normal case)
2.80 }
2.81
2.82 void
2.83 @@ -739,10 +779,18 @@
2.84 }
2.85 return true;
2.86 }
2.87 +
2.88 + //
2.89 + // If the time of the event is less than the current timestamp of the
2.90 + // simulator, the simulator has gone past the invocation time of the
2.91 + // event, so the statement ev.GetTs () < m_currentTs does mean that
2.92 + // the event has been fired even in realtime mode.
2.93 + //
2.94 + // The same is true for the next line involving the m_currentUid.
2.95 + //
2.96 if (ev.PeekEventImpl () == 0 ||
2.97 ev.GetTs () < m_currentTs ||
2.98 - (ev.GetTs () == m_currentTs &&
2.99 - ev.GetUid () <= m_currentUid) ||
2.100 + (ev.GetTs () == m_currentTs && ev.GetUid () <= m_currentUid) ||
2.101 ev.PeekEventImpl ()->IsCancelled ())
2.102 {
2.103 return true;
2.104 @@ -790,5 +838,3 @@
2.105 }
2.106
2.107 }; // namespace ns3
2.108 -
2.109 -
3.1 --- a/src/simulator/realtime-simulator-impl.h Tue Aug 26 15:34:57 2008 -0700
3.2 +++ b/src/simulator/realtime-simulator-impl.h Tue Aug 26 23:11:11 2008 -0700
3.3 @@ -113,6 +113,8 @@
3.4 RealtimeEventLock m_eventLock;
3.5
3.6 Ptr<Synchronizer> m_synchronizer;
3.7 +
3.8 +#ifdef PERMIT_WALLCLOCK_SIMULATION_TIME
3.9 /*
3.10 * In calls to Simulator::Now we have a basic choice to make. We can either
3.11 * report back the time the simulator thinks it should be, or we can report
3.12 @@ -136,6 +138,7 @@
3.13 * variations in host process scheduling, for example.
3.14 */
3.15 bool m_reportSimulatedTime;
3.16 +#endif
3.17
3.18 /**
3.19 * The policy to use if the simulation cannot keep synchronized to real-time.