57 TypeId(
"ns3::RealtimeSimulatorImpl")
62 "SynchronizationMode",
63 "What to do if the simulation cannot keep up with real time.",
65 MakeEnumAccessor<SynchronizationMode>(
68 .AddAttribute(
"HardLimit",
69 "Maximum acceptable real-time jitter (used in conjunction with "
70 "SynchronizationMode=HardLimit)",
90 m_main = std::this_thread::get_id();
134 if (!ev->IsCancelled())
149 std::unique_lock lock{
m_mutex};
156 scheduler->Insert(next);
188 uint64_t tsDelay = 0;
206 std::unique_lock lock{
m_mutex};
219 "RealtimeSimulatorImpl::ProcessOneEvent (): Synchronizer reports not Realtime ()");
246 tsDelay = tsNext - tsNow;
318 std::unique_lock lock{
m_mutex};
327 "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty");
341 "RealtimeSimulatorImpl::ProcessOneEvent(): "
342 "next.GetTs() earlier than m_currentTs (list order error)");
380 "Hard real-time limit exceeded (jitter = "
403 std::unique_lock lock{
m_mutex};
417 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
430 m_main = std::this_thread::get_id();
438 uint64_t tsDelay = 1000000000;
442 bool process =
false;
444 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())
564 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
601 std::unique_lock lock{
m_mutex};
605 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
629 std::unique_lock lock{
m_mutex};
637 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time "
671 std::unique_lock lock{
m_mutex};
704 if (
id.GetUid() == EventId::UID::DESTROY)
723 std::unique_lock lock{
m_mutex};
726 event.
impl =
id.PeekEventImpl();
727 event.key.m_ts =
id.GetTs();
728 event.key.m_context =
id.GetContext();
729 event.key.m_uid =
id.GetUid();
733 event.impl->Cancel();
743 id.PeekEventImpl()->Cancel();
750 if (
id.GetUid() == EventId::UID::DESTROY)
752 if (
id.PeekEventImpl() ==
nullptr ||
id.PeekEventImpl()->IsCancelled())
775 return id.PeekEventImpl() ==
nullptr ||
id.GetTs() <
m_currentTs ||
777 id.PeekEventImpl()->IsCancelled();
783 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() const
Create an Object instance of the configured TypeId.
virtual void DoDispose()
Destructor implementation.
Smart pointer class similar to boost::intrusive_ptr.
Realtime version of SimulatorImpl.
Time RealtimeNow() const
Get the current real time from the synchronizer.
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
uint64_t GetEventCount() const override
Get the number of events executed.
Ptr< Scheduler > m_events
The event list.
uint32_t GetContext() const override
Get the current simulation context.
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
uint32_t GetSystemId() const override
Get the system id of this simulator.
int m_unscheduledEvents
Unique id for the next event to be scheduled.
void Stop() override
Tell the Simulator the calling event should be the last one executed.
EventId ScheduleDestroy(EventImpl *event) override
Schedule an event to run at the end of the simulation, after the Stop() time or condition has been re...
Time GetHardLimit() const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
void Run() override
Run the simulation.
RealtimeSimulatorImpl()
Constructor.
bool m_running
Is the simulator currently running.
uint32_t m_currentContext
The event list.
bool IsExpired(const EventId &ev) const override
Check if an event has already run or been cancelled.
std::mutex m_mutex
Mutex to control access to key state.
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
void DoDispose() override
Destructor implementation.
uint64_t m_currentTs
Execution context.
void Cancel(const EventId &ev) override
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
EventId Schedule(const Time &delay, EventImpl *event) override
Schedule a future event execution (in the same context).
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
~RealtimeSimulatorImpl() override
Destructor.
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.
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.
bool IsFinished() const override
Check if the simulation should finish.
bool Realtime() const
Check that the Synchronizer is locked to the real time clock.
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()
Get the registered TypeId for this class.
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
Time GetDelayLeft(const EventId &id) const override
Get the remaining time until this event will execute.
void SetScheduler(ObjectFactory schedulerFactory) override
Set the Scheduler to be used to manage the event list.
void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event) override
Schedule a future event execution (in a different context).
EventId ScheduleNow(EventImpl *event) override
Schedule an event to run at the current virtual time.
bool Running() const
Is the simulator running?
std::thread::id m_main
Main thread.
void ProcessOneEvent()
Process the next event.
Time Now() const override
Return the current simulation virtual time.
void Remove(const EventId &ev) override
Remove an event from the event list.
void Destroy() override
Execute the events scheduled with ScheduleDestroy().
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
uint64_t NextTs() const
Get the timestep of the next event.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode() const
Get the SynchronizationMode.
Time GetMaximumSimulationTime() const override
Get the maximum representable simulation time.
void Unref() const
Decrement the reference count.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
@ NO_CONTEXT
Flag for events not associated with any particular context.
static void Stop()
Tell the Simulator the calling event should be the last one executed.
The SimulatorImpl base class.
virtual void PreEventHook(const EventId &id)
Hook called before processing each event.
Simulation virtual time values and global simulation resolution.
bool IsPositive() const
Exactly equivalent to t >= 0.
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
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...
#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.
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeEnumChecker(T 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.