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");
648 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time < m_currentTs");
714 if (
id.GetUid () == 2)
738 event.
impl =
id.PeekEventImpl ();
739 event.key.m_ts =
id.GetTs ();
740 event.key.m_context =
id.GetContext ();
741 event.key.m_uid =
id.GetUid ();
745 event.impl->Cancel ();
746 event.impl->Unref ();
755 id.PeekEventImpl ()->Cancel ();
762 if (
id.GetUid () == 2)
764 if (
id.PeekEventImpl () == 0 ||
765 id.PeekEventImpl ()->IsCancelled ())
789 if (
id.PeekEventImpl () == 0 ||
792 id.PeekEventImpl ()->IsCancelled ())
805 return TimeStep (0x7fffffffffffffffLL);
NS_FATAL_x macro definitions.
ns3::BooleanValue attribute value declarations.
void ProcessOneEvent(void)
Process the next event.
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.
bool IsPositive(void) const
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
ns3::EventImpl declarations.
uint64_t NextTs(void) const
Get the timestep of the next event.
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.
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).
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 RealtimeNow(void) const
Get the current real time from the synchronizer.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
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.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
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 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.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
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.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
SynchronizationMode
What to do when we can't maintain real time synchrony.
NS_ASSERT_MSG(false,"Ipv4AddressGenerator::MaskToIndex(): Impossible")
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.
virtual Time Now(void) const
Return the current simulation virtual time.
virtual void Run(void)
Run the simulation.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
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?
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
void Unref(void) const
Decrement the reference count.
ns3::EnumValue attribute value declarations.
virtual void Remove(const EventId &ev)
Remove an event from the event list.
ns3::WallClockSynchronizer declaration.
Realtime version of SimulatorImpl.
uint32_t m_uid
Unique id of the current 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...
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
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.
Flag for events not associated with any particular context.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
uint64_t m_currentTs
Execution context.
static bool Equals(ThreadId id)
Compares an ThreadId with the current ThreadId .
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
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.
Time Seconds(double value)
Construct a Time in the indicated unit.
bool Running(void) const
Is the simulator running?
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
virtual uint32_t GetContext(void) const
Get the current simulation context.
~RealtimeSimulatorImpl()
Destructor.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual bool IsFinished(void) const
Check if the simulation should finish.
ns3::PointerValue attribute value declarations and template implementations.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Make a best effort to keep synced to real-time.
uint32_t m_currentContext
The event list.
uint32_t m_context
Event context.
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying...
The SimulatorImpl base class.