A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
realtime-simulator-impl.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "assert.h"
10#include "enum.h"
11#include "event-impl.h"
12#include "fatal-error.h"
13#include "log.h"
14#include "ptr.h"
15#include "scheduler.h"
16#include "simulator.h"
17#include "synchronizer.h"
19
20#include <mutex>
21#include <thread>
22
23/**
24 * @file
25 * @ingroup realtime
26 * ns3::RealTimeSimulatorImpl implementation.
27 */
28
29namespace ns3
30{
31
32// Note: Logging in this file is largely avoided due to the
33// number of calls that are made to these functions and the possibility
34// of causing recursions leading to stack overflow
35NS_LOG_COMPONENT_DEFINE("RealtimeSimulatorImpl");
36
38
41{
42 static TypeId tid =
43 TypeId("ns3::RealtimeSimulatorImpl")
45 .SetGroupName("Core")
46 .AddConstructor<RealtimeSimulatorImpl>()
47 .AddAttribute(
48 "SynchronizationMode",
49 "What to do if the simulation cannot keep up with real time.",
53 MakeEnumChecker(SYNC_BEST_EFFORT, "BestEffort", SYNC_HARD_LIMIT, "HardLimit"))
54 .AddAttribute("HardLimit",
55 "Maximum acceptable real-time jitter (used in conjunction with "
56 "SynchronizationMode=HardLimit)",
57 TimeValue(Seconds(0.1)),
60 return tid;
61}
62
64{
65 NS_LOG_FUNCTION(this);
66
67 m_stop = false;
68 m_running = false;
71 m_currentTs = 0;
74 m_eventCount = 0;
75
76 m_main = std::this_thread::get_id();
77
78 // Be very careful not to do anything that would cause a change or assignment
79 // of the underlying reference counts of m_synchronizer or you will be sorry.
81}
82
87
88void
90{
91 NS_LOG_FUNCTION(this);
92 while (!m_events->IsEmpty())
93 {
94 Scheduler::Event next = m_events->RemoveNext();
95 next.impl->Unref();
96 }
97 m_events = nullptr;
98 m_synchronizer = nullptr;
100}
101
102void
104{
105 NS_LOG_FUNCTION(this);
106
107 //
108 // This function is only called with the private version "disconnected" from
109 // the main simulator functions. We rely on the user not calling
110 // Simulator::Destroy while there is a chance that a worker thread could be
111 // accessing the current instance of the private object. In practice this
112 // means shutting down the workers and doing a Join() before calling the
113 // Simulator::Destroy().
114 //
115 while (!m_destroyEvents.empty())
116 {
117 Ptr<EventImpl> ev = m_destroyEvents.front().PeekEventImpl();
118 m_destroyEvents.pop_front();
119 NS_LOG_LOGIC("handle destroy " << ev);
120 if (!ev->IsCancelled())
121 {
122 ev->Invoke();
123 }
124 }
125}
126
127void
129{
130 NS_LOG_FUNCTION(this << schedulerFactory);
131
132 Ptr<Scheduler> scheduler = schedulerFactory.Create<Scheduler>();
133
134 {
135 std::unique_lock lock{m_mutex};
136
137 if (m_events)
138 {
139 while (!m_events->IsEmpty())
140 {
141 Scheduler::Event next = m_events->RemoveNext();
142 scheduler->Insert(next);
143 }
144 }
145 m_events = scheduler;
146 }
147}
148
149void
151{
152 //
153 // The idea here is to wait until the next event comes due. In the case of
154 // a realtime simulation, we want real time to be consumed between events.
155 // It is the realtime synchronizer that causes real time to be consumed by
156 // doing some kind of a wait.
157 //
158 // We need to be able to have external events (such as a packet reception event)
159 // cause us to re-evaluate our state. The way this works is that the synchronizer
160 // gets interrupted and returns. So, there is a possibility that things may change
161 // out from under us dynamically. In this case, we need to re-evaluate how long to
162 // wait in a for-loop until we have waited successfully (until a timeout) for the
163 // event at the head of the event list.
164 //
165 // m_synchronizer->Synchronize will return true if the wait was completed without
166 // interruption, otherwise it will return false indicating that something has changed
167 // out from under us. If we sit in the for-loop trying to synchronize until
168 // Synchronize() returns true, we will have successfully synchronized the execution
169 // time of the next event with the wall clock time of the synchronizer.
170 //
171
172 for (;;)
173 {
174 uint64_t tsDelay = 0;
175 uint64_t tsNext = 0;
176
177 //
178 // It is important to understand that m_currentTs is interpreted only as the
179 // timestamp of the last event we executed. Current time can a bit of a
180 // slippery concept in realtime mode. What we have here is a discrete event
181 // simulator, so the last event is, by definition, executed entirely at a single
182 // discrete time. This is the definition of m_currentTs. It really has
183 // nothing to do with the current real time, except that we are trying to arrange
184 // that at the instant of the beginning of event execution, the current real time
185 // and m_currentTs coincide.
186 //
187 // We use tsNow as the indication of the current real time.
188 //
189 uint64_t tsNow;
190
191 {
192 std::unique_lock lock{m_mutex};
193 //
194 // Since we are in realtime mode, the time to delay has got to be the
195 // difference between the current realtime and the timestamp of the next
196 // event. Since m_currentTs is actually the timestamp of the last event we
197 // executed, it's not particularly meaningful for us here since real time has
198 // certainly elapsed since it was last updated.
199 //
200 // It is possible that the current realtime has drifted past the next event
201 // time so we need to be careful about that and not delay in that case.
202 //
204 m_synchronizer->Realtime(),
205 "RealtimeSimulatorImpl::ProcessOneEvent (): Synchronizer reports not Realtime ()");
206
207 //
208 // tsNow is set to the normalized current real time. When the simulation was
209 // started, the current real time was effectively set to zero; so tsNow is
210 // the current "real" simulation time.
211 //
212 // tsNext is the simulation time of the next event we want to execute.
213 //
214 tsNow = m_synchronizer->GetCurrentRealtime();
215 tsNext = NextTs();
216
217 //
218 // tsDelay is therefore the real time we need to delay in order to bring the
219 // real time in sync with the simulation time. If we wait for this amount of
220 // real time, we will accomplish moving the simulation time at the same rate
221 // as the real time. This is typically called "pacing" the simulation time.
222 //
223 // We do have to be careful if we are falling behind. If so, tsDelay must be
224 // zero. If we're late, don't dawdle.
225 //
226 if (tsNext <= tsNow)
227 {
228 tsDelay = 0;
229 }
230 else
231 {
232 tsDelay = tsNext - tsNow;
233 }
234
235 //
236 // We've figured out how long we need to delay in order to pace the
237 // simulation time with the real time. We're going to sleep, but need
238 // to work with the synchronizer to make sure we're awakened if something
239 // external happens (like a packet is received). This next line resets
240 // the synchronizer so that any future event will cause it to interrupt.
241 //
242 m_synchronizer->SetCondition(false);
243 }
244
245 //
246 // We have a time to delay. This time may actually not be valid anymore
247 // since we released the critical section immediately above, and a real-time
248 // ScheduleReal or ScheduleRealNow may have snuck in, well, between the
249 // closing brace above and this comment so to speak. If this is the case,
250 // that schedule operation will have done a synchronizer Signal() that
251 // will set the condition variable to true and cause the Synchronize call
252 // below to return immediately.
253 //
254 // It's easiest to understand if you just consider a short tsDelay that only
255 // requires a SpinWait down in the synchronizer. What will happen is that
256 // when Synchronize calls SpinWait, SpinWait will look directly at its
257 // condition variable. Note that we set this condition variable to false
258 // inside the critical section above.
259 //
260 // SpinWait will go into a forever loop until either the time has expired or
261 // until the condition variable becomes true. A true condition indicates that
262 // the wait should stop. The condition is set to true by one of the Schedule
263 // methods of the simulator; so if we are in a wait down in Synchronize, and
264 // a Simulator::ScheduleReal is done, the wait down in Synchronize will exit and
265 // Synchronize will return false. This means we have not actually synchronized
266 // to the event expiration time. If no real-time schedule operation is done
267 // while down in Synchronize, the wait will time out and Synchronize will return
268 // true. This indicates that we have synchronized to the event time.
269 //
270 // So we need to stay in this for loop, looking for the next event timestamp and
271 // attempting to sleep until its due. If we've slept until the timestamp is due,
272 // Synchronize returns true and we break out of the sync loop. If an external
273 // event happens that requires a re-schedule, Synchronize returns false and
274 // we re-evaluate our timing by continuing in the loop.
275 //
276 // It is expected that tsDelay become shorter as external events interrupt our
277 // waits.
278 //
279 if (m_synchronizer->Synchronize(tsNow, tsDelay))
280 {
281 // Synchronize returned true: the wait completed, so break.
282 NS_LOG_LOGIC("Synchronized");
283 break;
284 }
285
286 //
287 // If we get to this point, we have been interrupted during a wait by a real-time
288 // schedule operation. This means all bets are off regarding tsDelay and we need
289 // to re-evaluate what it is we want to do. We'll loop back around in the
290 // for-loop and start again from scratch.
291 //
292 }
293
294 //
295 // If we break out of the for-loop above, we have waited until the time specified
296 // by the event that was at the head of the event list when we started the process.
297 // Since there is a bunch of code that was executed outside a critical section (the
298 // Synchronize call) we cannot be sure that the event at the head of the event list
299 // is the one we think it is. What we can be sure of is that it is time to execute
300 // whatever event is at the head of this list if the list is in time order.
301 //
302 Scheduler::Event next;
303
304 {
305 std::unique_lock lock{m_mutex};
306
307 //
308 // We do know we're waiting for an event, so there had better be an event on the
309 // event queue. Let's pull it off. When we release the critical section, the
310 // event we're working on won't be on the list and so subsequent operations won't
311 // mess with us.
312 //
313 NS_ASSERT_MSG(m_events->IsEmpty() == false,
314 "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty");
315 next = m_events->RemoveNext();
316
317 PreEventHook(EventId(next.impl, next.key.m_ts, next.key.m_context, next.key.m_uid));
318
320 m_eventCount++;
321
322 //
323 // We cannot make any assumption that "next" is the same event we originally waited
324 // for. We can only assume that only that it must be due and cannot cause time
325 // to move backward.
326 //
328 "RealtimeSimulatorImpl::ProcessOneEvent(): "
329 "next.GetTs() earlier than m_currentTs (list order error)");
330 NS_LOG_LOGIC("handle " << next.key.m_ts);
331
332 //
333 // Update the current simulation time to be the timestamp of the event we're
334 // executing. From the rest of the simulation's point of view, simulation time
335 // is frozen until the next event is executed.
336 //
337 m_currentTs = next.key.m_ts;
339 m_currentUid = next.key.m_uid;
340
341 //
342 // We're about to run the event and we've done our best to synchronize this
343 // event execution time to real time. Now, if we're in SYNC_HARD_LIMIT mode
344 // we have to decide if we've done a good enough job and if we haven't, we've
345 // been asked to commit ritual suicide.
346 //
347 // We check the simulation time against the current real time to make this
348 // judgement.
349 //
351 {
352 uint64_t tsFinal = m_synchronizer->GetCurrentRealtime();
353 uint64_t tsJitter;
354
355 if (tsFinal >= m_currentTs)
356 {
357 tsJitter = tsFinal - m_currentTs;
358 }
359 else
360 {
361 tsJitter = m_currentTs - tsFinal;
362 }
363
364 if (tsJitter > static_cast<uint64_t>(m_hardLimit.GetTimeStep()))
365 {
366 NS_FATAL_ERROR("RealtimeSimulatorImpl::ProcessOneEvent (): "
367 "Hard real-time limit exceeded (jitter = "
368 << tsJitter << ")");
369 }
370 }
371 }
372
373 //
374 // We have got the event we're about to execute completely disentangled from the
375 // event list so we can execute it outside a critical section without fear of someone
376 // changing things out from under us.
377
378 EventImpl* event = next.impl;
379 m_synchronizer->EventStart();
380 event->Invoke();
381 m_synchronizer->EventEnd();
382 event->Unref();
383}
384
385bool
387{
388 bool rc;
389 {
390 std::unique_lock lock{m_mutex};
391 rc = m_events->IsEmpty() || m_stop;
392 }
393
394 return rc;
395}
396
397//
398// Peeks into event list. Should be called with critical section locked.
399//
400uint64_t
402{
403 NS_ASSERT_MSG(m_events->IsEmpty() == false,
404 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
405 Scheduler::Event ev = m_events->PeekNext();
406 return ev.key.m_ts;
407}
408
409void
411{
412 NS_LOG_FUNCTION(this);
413
414 NS_ASSERT_MSG(m_running == false, "RealtimeSimulatorImpl::Run(): Simulator already running");
415
416 // Set the current threadId as the main threadId
417 m_main = std::this_thread::get_id();
418
419 m_stop = false;
420 m_running = true;
421 m_synchronizer->SetOrigin(m_currentTs);
422
423 // Sleep until signalled
424 uint64_t tsNow = 0;
425 uint64_t tsDelay = 1000000000; // wait time of 1 second (in nanoseconds)
426
427 while (!m_stop)
428 {
429 bool process = false;
430 {
431 std::unique_lock lock{m_mutex};
432
433 if (!m_events->IsEmpty())
434 {
435 process = true;
436 }
437 else
438 {
439 // Get current timestamp while holding the critical section
440 tsNow = m_synchronizer->GetCurrentRealtime();
441 }
442 }
443
444 if (process)
445 {
447 }
448 else
449 {
450 // Sleep until signalled and re-check event queue
451 m_synchronizer->Synchronize(tsNow, tsDelay);
452 }
453 }
454
455 //
456 // If the simulator stopped naturally by lack of events, make a
457 // consistency test to check that we didn't lose any events along the way.
458 //
459 {
460 std::unique_lock lock{m_mutex};
461
462 NS_ASSERT_MSG(m_events->IsEmpty() == false || m_unscheduledEvents == 0,
463 "RealtimeSimulatorImpl::Run(): Empty queue and unprocessed events");
464 }
465
466 m_running = false;
467}
468
469bool
471{
472 return m_running;
473}
474
475bool
477{
478 return m_synchronizer->Realtime();
479}
480
481void
483{
484 NS_LOG_FUNCTION(this);
485 m_stop = true;
486}
487
490{
491 NS_LOG_FUNCTION(this << delay);
492 return Simulator::Schedule(delay, &Simulator::Stop);
493}
494
495//
496// Schedule an event for a _relative_ time in the future.
497//
500{
501 NS_LOG_FUNCTION(this << delay << impl);
502
504 {
505 std::unique_lock lock{m_mutex};
506 //
507 // This is the reason we had to bring the absolute time calculation in from the
508 // simulator.h into the implementation. Since the implementations may be
509 // multi-threaded, we need this calculation to be atomic. You can see it is
510 // here since we are running in a CriticalSection.
511 //
512 Time tAbsolute = Simulator::Now() + delay;
513 NS_ASSERT_MSG(delay.IsPositive(), "RealtimeSimulatorImpl::Schedule(): Negative delay");
514 ev.impl = impl;
515 ev.key.m_ts = static_cast<uint64_t>(tAbsolute.GetTimeStep());
516 ev.key.m_context = GetContext();
517 ev.key.m_uid = m_uid;
518 m_uid++;
520 m_events->Insert(ev);
521 m_synchronizer->Signal();
522 }
523
524 return EventId(impl, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
525}
526
527void
529{
530 NS_LOG_FUNCTION(this << context << delay << impl);
531
532 {
533 std::unique_lock lock{m_mutex};
534 uint64_t ts;
535
536 if (m_main == std::this_thread::get_id())
537 {
538 ts = m_currentTs + delay.GetTimeStep();
539 }
540 else
541 {
542 //
543 // If the simulator is running, we're pacing and have a meaningful
544 // realtime clock. If we're not, then m_currentTs is where we stopped.
545 //
546 ts = m_running ? m_synchronizer->GetCurrentRealtime() : m_currentTs;
547 ts += delay.GetTimeStep();
548 }
549
551 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
553 ev.impl = impl;
554 ev.key.m_ts = ts;
555 ev.key.m_context = context;
556 ev.key.m_uid = m_uid;
557 m_uid++;
559 m_events->Insert(ev);
560 m_synchronizer->Signal();
561 }
562}
563
566{
567 NS_LOG_FUNCTION(this << impl);
568 return Schedule(Time(0), impl);
569}
570
571Time
573{
574 return TimeStep(m_currentTs);
575}
576
577//
578// Schedule an event for a _relative_ time in the future.
579//
580void
582 const Time& time,
583 EventImpl* impl)
584{
585 NS_LOG_FUNCTION(this << context << time << impl);
586
587 {
588 std::unique_lock lock{m_mutex};
589
590 uint64_t ts = m_synchronizer->GetCurrentRealtime() + time.GetTimeStep();
592 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
594 ev.impl = impl;
595 ev.key.m_ts = ts;
596 ev.key.m_uid = m_uid;
597 m_uid++;
599 m_events->Insert(ev);
600 m_synchronizer->Signal();
601 }
602}
603
604void
606{
607 NS_LOG_FUNCTION(this << time << impl);
609}
610
611void
613{
614 NS_LOG_FUNCTION(this << context << impl);
615 {
616 std::unique_lock lock{m_mutex};
617
618 //
619 // If the simulator is running, we're pacing and have a meaningful
620 // realtime clock. If we're not, then m_currentTs is were we stopped.
621 //
622 uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime() : m_currentTs;
624 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time "
625 "< m_currentTs");
627 ev.impl = impl;
628 ev.key.m_ts = ts;
629 ev.key.m_uid = m_uid;
630 ev.key.m_context = context;
631 m_uid++;
633 m_events->Insert(ev);
634 m_synchronizer->Signal();
635 }
636}
637
638void
644
645Time
647{
648 return TimeStep(m_synchronizer->GetCurrentRealtime());
649}
650
653{
654 NS_LOG_FUNCTION(this << impl);
655
656 EventId id;
657 {
658 std::unique_lock lock{m_mutex};
659
660 //
661 // Time doesn't really matter here (especially in realtime mode). It is
662 // overridden by the uid of DESTROY which identifies this as an event to be
663 // executed at Simulator::Destroy time.
664 //
665 id = EventId(Ptr<EventImpl>(impl, false), m_currentTs, 0xffffffff, EventId::UID::DESTROY);
666 m_destroyEvents.push_back(id);
667 m_uid++;
668 }
669
670 return id;
671}
672
673Time
675{
676 //
677 // If the event has expired, there is no delay until it runs. It is not the
678 // case that there is a negative time until it runs.
679 //
680 if (IsExpired(id))
681 {
682 return TimeStep(0);
683 }
684
685 return TimeStep(id.GetTs() - m_currentTs);
686}
687
688void
690{
691 if (id.GetUid() == EventId::UID::DESTROY)
692 {
693 // destroy events.
694 for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
695 {
696 if (*i == id)
697 {
698 m_destroyEvents.erase(i);
699 break;
700 }
701 }
702 return;
703 }
704 if (IsExpired(id))
705 {
706 return;
707 }
708
709 {
710 std::unique_lock lock{m_mutex};
711
712 Scheduler::Event event;
713 event.impl = id.PeekEventImpl();
714 event.key.m_ts = id.GetTs();
715 event.key.m_context = id.GetContext();
716 event.key.m_uid = id.GetUid();
717
718 m_events->Remove(event);
720 event.impl->Cancel();
721 event.impl->Unref();
722 }
723}
724
725void
727{
728 if (!IsExpired(id))
729 {
730 id.PeekEventImpl()->Cancel();
731 }
732}
733
734bool
736{
737 if (id.GetUid() == EventId::UID::DESTROY)
738 {
739 if (id.PeekEventImpl() == nullptr || id.PeekEventImpl()->IsCancelled())
740 {
741 return true;
742 }
743 // destroy events.
744 for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
745 {
746 if (*i == id)
747 {
748 return false;
749 }
750 }
751 return true;
752 }
753
754 //
755 // If the time of the event is less than the current timestamp of the
756 // simulator, the simulator has gone past the invocation time of the
757 // event, so the statement ev.GetTs () < m_currentTs does mean that
758 // the event has been fired even in realtime mode.
759 //
760 // The same is true for the next line involving the m_currentUid.
761 //
762 return id.PeekEventImpl() == nullptr || id.GetTs() < m_currentTs ||
763 (id.GetTs() == m_currentTs && id.GetUid() <= m_currentUid) ||
764 id.PeekEventImpl()->IsCancelled();
765}
766
767Time
769{
770 return TimeStep(0x7fffffffffffffffLL);
771}
772
773// System ID for non-distributed simulation is always zero
776{
777 return 0;
778}
779
785
786uint64_t
791
792void
798
805
806void
808{
809 NS_LOG_FUNCTION(this << limit);
810 m_hardLimit = limit;
811}
812
813Time
815{
816 NS_LOG_FUNCTION(this);
817 return m_hardLimit;
818}
819
820} // namespace ns3
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
Hold variables of type enum.
Definition enum.h:52
An identifier for simulation events.
Definition event-id.h:45
@ INVALID
Invalid UID value.
Definition event-id.h:51
@ VALID
Schedule(), etc.
Definition event-id.h:59
@ DESTROY
ScheduleDestroy() events.
Definition event-id.h:55
A simulation event.
Definition event-impl.h:35
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
virtual void DoDispose()
Destructor implementation.
Definition object.cc:431
Smart pointer class similar to boost::intrusive_ptr.
Definition ptr.h:70
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.
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.
Maintain the event list.
Definition scheduler.h:146
void Unref() const
Decrement the reference count.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:580
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:191
@ NO_CONTEXT
Flag for events not associated with any particular context.
Definition simulator.h:207
static void Stop()
Tell the Simulator the calling event should be the last one executed.
Definition simulator.cc:169
The SimulatorImpl base class.
virtual void PreEventHook(const EventId &id)
Hook called before processing each event.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:323
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1410
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:440
a unique identifier for an interface.
Definition type-id.h:50
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1003
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...
Definition assert.h:76
#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.
Definition log.h:201
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:281
#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.
Definition object.h:627
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition nstime.h:1416
Ptr< const AttributeChecker > MakeEnumChecker(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition enum.h:181
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:223
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1436
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.
Scheduler event.
Definition scheduler.h:173
EventKey key
Key for sorting and ordering Events.
Definition scheduler.h:175
EventImpl * impl
Pointer to the event implementation.
Definition scheduler.h:174
uint32_t m_context
Event context.
Definition scheduler.h:162
uint64_t m_ts
Event time stamp.
Definition scheduler.h:160
uint32_t m_uid
Event unique id.
Definition scheduler.h:161
ns3::Synchronizer declaration.
ns3::WallClockSynchronizer declaration.