57 static TypeId tid =
TypeId (
"ns3::RealtimeSimulatorImpl")
59 .SetGroupName (
"Core")
61 .AddAttribute (
"SynchronizationMode",
62 "What to do if the simulation cannot keep up with real time.",
67 .AddAttribute (
"HardLimit",
68 "Maximum acceptable real-time jitter (used in conjunction with SynchronizationMode=HardLimit)",
138 if (ev->IsCancelled () ==
false)
157 while (
m_events->IsEmpty () ==
false)
160 scheduler->Insert (next);
192 uint64_t tsDelay = 0;
222 "RealtimeSimulatorImpl::ProcessOneEvent (): Synchronizer reports not Realtime ()");
249 tsDelay = tsNext - tsNow;
330 "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 <<
")");
415 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
426 "RealtimeSimulatorImpl::Run(): Simulator already running");
437 uint64_t tsDelay = 1000000000;
441 bool process =
false;
476 "RealtimeSimulatorImpl::Run(): Empty queue and unprocessed events");
647 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time < m_currentTs");
713 if (
id.GetUid () == 2)
737 event.
impl =
id.PeekEventImpl ();
738 event.key.m_ts =
id.GetTs ();
739 event.key.m_context =
id.GetContext ();
740 event.key.m_uid =
id.GetUid ();
744 event.impl->Cancel ();
745 event.impl->Unref ();
754 id.PeekEventImpl ()->Cancel ();
761 if (
id.GetUid () == 2)
763 if (
id.PeekEventImpl () == 0 ||
764 id.PeekEventImpl ()->IsCancelled ())
788 if (
id.PeekEventImpl () == 0 ||
791 id.PeekEventImpl ()->IsCancelled ())
804 return TimeStep (0x7fffffffffffffffLL);
NS_FATAL_x macro definitions.
ns3::BooleanValue attribute value declarations.
void ProcessOneEvent(void)
Process the next event.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
Schedule an event to run at the current virtual time.
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
Simulation virtual time values and global simulation resolution.
Ptr< Synchronizer > m_synchronizer
The synchronizer in use to track real time.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::EventImpl declarations.
void Unref(void) const
Decrement the reference count.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
SystemThread::ThreadId m_main
Main SystemThread.
uint64_t m_ts
Event time stamp.
int m_unscheduledEvents
Unique id for the next event to be scheduled.
ns3::Ptr smart pointer declaration and implementation.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual Time Now(void) const
Return the current simulation virtual time.
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
static ThreadId Self(void)
Returns the current thread Id.
RealtimeSimulatorImpl()
Constructor.
EventImpl * impl
Pointer to the event implementation.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
ns3::Simulator declaration.
virtual void DoDispose(void)
Destructor implementation.
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
bool m_running
Is the simulator currently running.
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual void DoDispose(void)
Destructor implementation.
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...
Ptr< Scheduler > m_events
The event list.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
uint32_t m_currentUid
Timestep of the current event.
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying...
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
Hold variables of type enum.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
EventKey key
Key for sorting and ordering Events.
SystemMutex m_mutex
Mutex to control access to key state.
AttributeValue implementation for Time.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
virtual void Run(void)
Run the simulation.
A class which provides a simple way to implement a Critical Section.
uint32_t m_uid
Event unique id.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
bool m_stop
Has the stopping condition been reached?
bool Running(void) const
Is the simulator running?
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
ns3::EnumValue attribute value declarations.
virtual void Remove(const EventId &ev)
Remove an event from the event list.
ns3::WallClockSynchronizer declaration.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
Realtime version of SimulatorImpl.
uint32_t m_uid
Unique id of the current event.
uint64_t NextTs(void) const
Get the timestep of the next event.
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...
SynchronizationMode
What to do when we can't maintain real time synchrony.
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
Time TimeStep(uint64_t ts)
ns3::RealTimeSimulatorImpl declaration.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
static Time Now(void)
Return the current simulation virtual time.
ns3::Synchronizer declaration.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint64_t m_currentTs
Execution context.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
static bool Equals(ThreadId id)
Compares an ThreadId with the current ThreadId .
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Instantiate subclasses of ns3::Object.
An identifier for simulation events.
static void Stop(void)
Tell the Simulator the calling event should be the last one executed.
bool IsPositive(void) const
Make a best effort to keep synced to real-time.
Time Seconds(double value)
Construct a Time in the indicated unit.
Flag for events not associated with any particular context.
~RealtimeSimulatorImpl()
Destructor.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
ns3::PointerValue attribute value declarations and template implementations.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
uint32_t m_currentContext
The event list.
uint32_t m_context
Event context.
The SimulatorImpl base class.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.