46 TypeId(
"ns3::RealtimeSimulatorImpl")
51 "SynchronizationMode",
52 "What to do if the simulation cannot keep up with real time.",
57 .AddAttribute(
"HardLimit",
58 "Maximum acceptable real-time jitter (used in conjunction with "
59 "SynchronizationMode=HardLimit)",
79 m_main = std::this_thread::get_id();
123 if (!ev->IsCancelled())
138 std::unique_lock lock{
m_mutex};
145 scheduler->Insert(next);
177 uint64_t tsDelay = 0;
195 std::unique_lock lock{
m_mutex};
208 "RealtimeSimulatorImpl::ProcessOneEvent (): Synchronizer reports not Realtime ()");
235 tsDelay = tsNext - tsNow;
307 std::unique_lock lock{
m_mutex};
316 "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty");
330 "RealtimeSimulatorImpl::ProcessOneEvent(): "
331 "next.GetTs() earlier than m_currentTs (list order error)");
369 "Hard real-time limit exceeded (jitter = "
392 std::unique_lock lock{
m_mutex};
406 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
419 m_main = std::this_thread::get_id();
427 uint64_t tsDelay = 1000000000;
431 bool process =
false;
433 std::unique_lock lock{
m_mutex};
462 std::unique_lock lock{
m_mutex};
465 "RealtimeSimulatorImpl::Run(): Empty queue and unprocessed events");
507 std::unique_lock lock{
m_mutex};
535 std::unique_lock lock{
m_mutex};
538 if (
m_main == std::this_thread::get_id())
553 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
590 std::unique_lock lock{
m_mutex};
594 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
618 std::unique_lock lock{
m_mutex};
626 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time "
660 std::unique_lock lock{
m_mutex};
712 std::unique_lock lock{
m_mutex};
715 event.
impl =
id.PeekEventImpl();
716 event.key.m_ts =
id.GetTs();
717 event.key.m_context =
id.GetContext();
718 event.key.m_uid =
id.GetUid();
722 event.impl->Cancel();
732 id.PeekEventImpl()->Cancel();
741 if (
id.PeekEventImpl() ==
nullptr ||
id.PeekEventImpl()->IsCancelled())
764 return id.PeekEventImpl() ==
nullptr ||
id.GetTs() <
m_currentTs ||
766 id.PeekEventImpl()->IsCancelled();
772 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.
@ INVALID
Invalid UID value.
@ DESTROY
ScheduleDestroy() events.
void Invoke()
Called by the simulation engine to notify the event that it is time to execute.
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.
@ NO_CONTEXT
Flag for events not associated with any particular context.
static Time Now()
Return the current simulation virtual time.
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.
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.
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
#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 ",...
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#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(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
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.