56 static TypeId tid =
TypeId (
"ns3::RealtimeSimulatorImpl")
58 .SetGroupName (
"Core")
60 .AddAttribute (
"SynchronizationMode",
61 "What to do if the simulation cannot keep up with real time.",
66 .AddAttribute (
"HardLimit",
67 "Maximum acceptable real-time jitter (used in conjunction with SynchronizationMode=HardLimit)",
89 m_main = std::this_thread::get_id ();
133 if (ev->IsCancelled () ==
false)
148 std::unique_lock lock {
m_mutex};
152 while (
m_events->IsEmpty () ==
false)
155 scheduler->Insert (next);
187 uint64_t tsDelay = 0;
205 std::unique_lock lock {
m_mutex};
217 "RealtimeSimulatorImpl::ProcessOneEvent (): Synchronizer reports not Realtime ()");
244 tsDelay = tsNext - tsNow;
316 std::unique_lock lock {
m_mutex};
325 "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty");
340 "RealtimeSimulatorImpl::ProcessOneEvent(): "
341 "next.GetTs() earlier than m_currentTs (list order error)");
379 "Hard real-time limit exceeded (jitter = " << tsJitter <<
")");
401 std::unique_lock lock {
m_mutex};
415 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
426 "RealtimeSimulatorImpl::Run(): Simulator already running");
429 m_main = std::this_thread::get_id ();
437 uint64_t tsDelay = 1000000000;
441 bool process =
false;
443 std::unique_lock lock {
m_mutex};
473 std::unique_lock lock {
m_mutex};
476 "RealtimeSimulatorImpl::Run(): Empty queue and unprocessed events");
518 std::unique_lock lock {
m_mutex};
546 std::unique_lock lock {
m_mutex};
549 if (
m_main == std::this_thread::get_id ())
598 std::unique_lock lock {
m_mutex};
625 std::unique_lock lock {
m_mutex};
633 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time < m_currentTs");
666 std::unique_lock lock {
m_mutex};
674 EventId::UID::DESTROY);
700 if (
id.GetUid () == EventId::UID::DESTROY)
721 std::unique_lock lock {
m_mutex};
724 event.
impl =
id.PeekEventImpl ();
725 event.key.m_ts =
id.GetTs ();
726 event.key.m_context =
id.GetContext ();
727 event.key.m_uid =
id.GetUid ();
731 event.impl->Cancel ();
732 event.impl->Unref ();
741 id.PeekEventImpl ()->Cancel ();
748 if (
id.GetUid () == EventId::UID::DESTROY)
750 if (
id.PeekEventImpl () == 0
751 ||
id.PeekEventImpl ()->IsCancelled ())
775 if (
id.PeekEventImpl () == 0
778 ||
id.PeekEventImpl ()->IsCancelled ())
791 return TimeStep (0x7fffffffffffffffLL);
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::BooleanValue attribute value declarations.
Hold variables of type enum.
An identifier for simulation events.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
virtual void DoDispose(void)
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
Realtime version of SimulatorImpl.
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Ptr< Scheduler > m_events
The event list.
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
virtual void DoDispose(void)
Destructor implementation.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
int m_unscheduledEvents
Unique id for the next event to be scheduled.
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
RealtimeSimulatorImpl()
Constructor.
bool m_running
Is the simulator currently running.
uint32_t m_currentContext
The event list.
virtual void Cancel(const EventId &ev)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
virtual void Remove(const EventId &ev)
Remove an event from the event list.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
std::mutex m_mutex
Mutex to control access to key state.
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
uint64_t NextTs(void) const
Get the timestep of the next event.
virtual void Run(void)
Run the simulation.
uint64_t m_currentTs
Execution context.
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
uint32_t m_uid
Unique id of the current event.
uint64_t m_eventCount
The event count.
uint32_t m_currentUid
Timestep of the current event.
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
Schedule an event to run at the current virtual time.
bool m_stop
Has the stopping condition been reached?
Ptr< Synchronizer > m_synchronizer
The synchronizer in use to track real time.
SynchronizationMode
What to do when we can't maintain real time synchrony.
@ SYNC_BEST_EFFORT
Make a best effort to keep synced to real-time.
@ SYNC_HARD_LIMIT
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying.
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual Time Now(void) const
Return the current simulation virtual time.
~RealtimeSimulatorImpl()
Destructor.
virtual uint32_t GetContext(void) const
Get the current simulation context.
bool Running(void) const
Is the simulator running?
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
void ProcessOneEvent(void)
Process the next event.
std::thread::id m_main
Main thread.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
virtual EventId ScheduleDestroy(EventImpl *event)
Schedule an event to run at the end of the simulation, after the Stop() time or condition has been re...
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
void Unref(void) const
Decrement the reference count.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now(void)
Return the current simulation virtual time.
@ NO_CONTEXT
Flag for events not associated with any particular context.
The SimulatorImpl base class.
virtual void PreEventHook(const EventId &id)
Hook called before processing each event.
Simulation virtual time values and global simulation resolution.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
bool IsPositive(void) const
Exactly equivalent to t >= 0.
AttributeValue implementation for Time.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
ns3::EnumValue attribute value declarations.
ns3::EventImpl declarations.
NS_FATAL_x macro definitions.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
ns3::PointerValue attribute value declarations and template implementations.
ns3::Ptr smart pointer declaration and implementation.
ns3::RealtimeSimulatorImpl declaration.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::Simulator declaration.
EventKey key
Key for sorting and ordering Events.
EventImpl * impl
Pointer to the event implementation.
uint32_t m_context
Event context.
uint64_t m_ts
Event time stamp.
uint32_t m_uid
Event unique id.
ns3::Synchronizer declaration.
ns3::WallClockSynchronizer declaration.