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 NS_LOG_LOGIC("Interrupted ...");
282 break;
283 }
284
285 //
286 // If we get to this point, we have been interrupted during a wait by a real-time
287 // schedule operation. This means all bets are off regarding tsDelay and we need
288 // to re-evaluate what it is we want to do. We'll loop back around in the
289 // for-loop and start again from scratch.
290 //
291 }
292
293 //
294 // If we break out of the for-loop above, we have waited until the time specified
295 // by the event that was at the head of the event list when we started the process.
296 // Since there is a bunch of code that was executed outside a critical section (the
297 // Synchronize call) we cannot be sure that the event at the head of the event list
298 // is the one we think it is. What we can be sure of is that it is time to execute
299 // whatever event is at the head of this list if the list is in time order.
300 //
301 Scheduler::Event next;
302
303 {
304 std::unique_lock lock{m_mutex};
305
306 //
307 // We do know we're waiting for an event, so there had better be an event on the
308 // event queue. Let's pull it off. When we release the critical section, the
309 // event we're working on won't be on the list and so subsequent operations won't
310 // mess with us.
311 //
312 NS_ASSERT_MSG(m_events->IsEmpty() == false,
313 "RealtimeSimulatorImpl::ProcessOneEvent(): event queue is empty");
314 next = m_events->RemoveNext();
315
316 PreEventHook(EventId(next.impl, next.key.m_ts, next.key.m_context, next.key.m_uid));
317
319 m_eventCount++;
320
321 //
322 // We cannot make any assumption that "next" is the same event we originally waited
323 // for. We can only assume that only that it must be due and cannot cause time
324 // to move backward.
325 //
327 "RealtimeSimulatorImpl::ProcessOneEvent(): "
328 "next.GetTs() earlier than m_currentTs (list order error)");
329 NS_LOG_LOGIC("handle " << next.key.m_ts);
330
331 //
332 // Update the current simulation time to be the timestamp of the event we're
333 // executing. From the rest of the simulation's point of view, simulation time
334 // is frozen until the next event is executed.
335 //
336 m_currentTs = next.key.m_ts;
338 m_currentUid = next.key.m_uid;
339
340 //
341 // We're about to run the event and we've done our best to synchronize this
342 // event execution time to real time. Now, if we're in SYNC_HARD_LIMIT mode
343 // we have to decide if we've done a good enough job and if we haven't, we've
344 // been asked to commit ritual suicide.
345 //
346 // We check the simulation time against the current real time to make this
347 // judgement.
348 //
350 {
351 uint64_t tsFinal = m_synchronizer->GetCurrentRealtime();
352 uint64_t tsJitter;
353
354 if (tsFinal >= m_currentTs)
355 {
356 tsJitter = tsFinal - m_currentTs;
357 }
358 else
359 {
360 tsJitter = m_currentTs - tsFinal;
361 }
362
363 if (tsJitter > static_cast<uint64_t>(m_hardLimit.GetTimeStep()))
364 {
365 NS_FATAL_ERROR("RealtimeSimulatorImpl::ProcessOneEvent (): "
366 "Hard real-time limit exceeded (jitter = "
367 << tsJitter << ")");
368 }
369 }
370 }
371
372 //
373 // We have got the event we're about to execute completely disentangled from the
374 // event list so we can execute it outside a critical section without fear of someone
375 // changing things out from under us.
376
377 EventImpl* event = next.impl;
378 m_synchronizer->EventStart();
379 event->Invoke();
380 m_synchronizer->EventEnd();
381 event->Unref();
382}
383
384bool
386{
387 bool rc;
388 {
389 std::unique_lock lock{m_mutex};
390 rc = m_events->IsEmpty() || m_stop;
391 }
392
393 return rc;
394}
395
396//
397// Peeks into event list. Should be called with critical section locked.
398//
399uint64_t
401{
402 NS_ASSERT_MSG(m_events->IsEmpty() == false,
403 "RealtimeSimulatorImpl::NextTs(): event queue is empty");
404 Scheduler::Event ev = m_events->PeekNext();
405 return ev.key.m_ts;
406}
407
408void
410{
411 NS_LOG_FUNCTION(this);
412
413 NS_ASSERT_MSG(m_running == false, "RealtimeSimulatorImpl::Run(): Simulator already running");
414
415 // Set the current threadId as the main threadId
416 m_main = std::this_thread::get_id();
417
418 m_stop = false;
419 m_running = true;
420 m_synchronizer->SetOrigin(m_currentTs);
421
422 // Sleep until signalled
423 uint64_t tsNow = 0;
424 uint64_t tsDelay = 1000000000; // wait time of 1 second (in nanoseconds)
425
426 while (!m_stop)
427 {
428 bool process = false;
429 {
430 std::unique_lock lock{m_mutex};
431
432 if (!m_events->IsEmpty())
433 {
434 process = true;
435 }
436 else
437 {
438 // Get current timestamp while holding the critical section
439 tsNow = m_synchronizer->GetCurrentRealtime();
440 }
441 }
442
443 if (process)
444 {
446 }
447 else
448 {
449 // Sleep until signalled and re-check event queue
450 m_synchronizer->Synchronize(tsNow, tsDelay);
451 }
452 }
453
454 //
455 // If the simulator stopped naturally by lack of events, make a
456 // consistency test to check that we didn't lose any events along the way.
457 //
458 {
459 std::unique_lock lock{m_mutex};
460
461 NS_ASSERT_MSG(m_events->IsEmpty() == false || m_unscheduledEvents == 0,
462 "RealtimeSimulatorImpl::Run(): Empty queue and unprocessed events");
463 }
464
465 m_running = false;
466}
467
468bool
470{
471 return m_running;
472}
473
474bool
476{
477 return m_synchronizer->Realtime();
478}
479
480void
482{
483 NS_LOG_FUNCTION(this);
484 m_stop = true;
485}
486
489{
490 NS_LOG_FUNCTION(this << delay);
491 return Simulator::Schedule(delay, &Simulator::Stop);
492}
493
494//
495// Schedule an event for a _relative_ time in the future.
496//
499{
500 NS_LOG_FUNCTION(this << delay << impl);
501
503 {
504 std::unique_lock lock{m_mutex};
505 //
506 // This is the reason we had to bring the absolute time calculation in from the
507 // simulator.h into the implementation. Since the implementations may be
508 // multi-threaded, we need this calculation to be atomic. You can see it is
509 // here since we are running in a CriticalSection.
510 //
511 Time tAbsolute = Simulator::Now() + delay;
512 NS_ASSERT_MSG(delay.IsPositive(), "RealtimeSimulatorImpl::Schedule(): Negative delay");
513 ev.impl = impl;
514 ev.key.m_ts = (uint64_t)tAbsolute.GetTimeStep();
515 ev.key.m_context = GetContext();
516 ev.key.m_uid = m_uid;
517 m_uid++;
519 m_events->Insert(ev);
520 m_synchronizer->Signal();
521 }
522
523 return EventId(impl, ev.key.m_ts, ev.key.m_context, ev.key.m_uid);
524}
525
526void
528{
529 NS_LOG_FUNCTION(this << context << delay << impl);
530
531 {
532 std::unique_lock lock{m_mutex};
533 uint64_t ts;
534
535 if (m_main == std::this_thread::get_id())
536 {
537 ts = m_currentTs + delay.GetTimeStep();
538 }
539 else
540 {
541 //
542 // If the simulator is running, we're pacing and have a meaningful
543 // realtime clock. If we're not, then m_currentTs is where we stopped.
544 //
545 ts = m_running ? m_synchronizer->GetCurrentRealtime() : m_currentTs;
546 ts += delay.GetTimeStep();
547 }
548
550 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
552 ev.impl = impl;
553 ev.key.m_ts = ts;
554 ev.key.m_context = context;
555 ev.key.m_uid = m_uid;
556 m_uid++;
558 m_events->Insert(ev);
559 m_synchronizer->Signal();
560 }
561}
562
565{
566 NS_LOG_FUNCTION(this << impl);
567 return Schedule(Time(0), impl);
568}
569
570Time
572{
573 return TimeStep(m_currentTs);
574}
575
576//
577// Schedule an event for a _relative_ time in the future.
578//
579void
581 const Time& time,
582 EventImpl* impl)
583{
584 NS_LOG_FUNCTION(this << context << time << impl);
585
586 {
587 std::unique_lock lock{m_mutex};
588
589 uint64_t ts = m_synchronizer->GetCurrentRealtime() + time.GetTimeStep();
591 "RealtimeSimulatorImpl::ScheduleRealtime(): schedule for time < m_currentTs");
593 ev.impl = impl;
594 ev.key.m_ts = ts;
595 ev.key.m_uid = m_uid;
596 m_uid++;
598 m_events->Insert(ev);
599 m_synchronizer->Signal();
600 }
601}
602
603void
605{
606 NS_LOG_FUNCTION(this << time << impl);
608}
609
610void
612{
613 NS_LOG_FUNCTION(this << context << impl);
614 {
615 std::unique_lock lock{m_mutex};
616
617 //
618 // If the simulator is running, we're pacing and have a meaningful
619 // realtime clock. If we're not, then m_currentTs is were we stopped.
620 //
621 uint64_t ts = m_running ? m_synchronizer->GetCurrentRealtime() : m_currentTs;
623 "RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext(): schedule for time "
624 "< m_currentTs");
626 ev.impl = impl;
627 ev.key.m_ts = ts;
628 ev.key.m_uid = m_uid;
629 ev.key.m_context = context;
630 m_uid++;
632 m_events->Insert(ev);
633 m_synchronizer->Signal();
634 }
635}
636
637void
643
644Time
646{
647 return TimeStep(m_synchronizer->GetCurrentRealtime());
648}
649
652{
653 NS_LOG_FUNCTION(this << impl);
654
655 EventId id;
656 {
657 std::unique_lock lock{m_mutex};
658
659 //
660 // Time doesn't really matter here (especially in realtime mode). It is
661 // overridden by the uid of DESTROY which identifies this as an event to be
662 // executed at Simulator::Destroy time.
663 //
664 id = EventId(Ptr<EventImpl>(impl, false), m_currentTs, 0xffffffff, EventId::UID::DESTROY);
665 m_destroyEvents.push_back(id);
666 m_uid++;
667 }
668
669 return id;
670}
671
672Time
674{
675 //
676 // If the event has expired, there is no delay until it runs. It is not the
677 // case that there is a negative time until it runs.
678 //
679 if (IsExpired(id))
680 {
681 return TimeStep(0);
682 }
683
684 return TimeStep(id.GetTs() - m_currentTs);
685}
686
687void
689{
690 if (id.GetUid() == EventId::UID::DESTROY)
691 {
692 // destroy events.
693 for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
694 {
695 if (*i == id)
696 {
697 m_destroyEvents.erase(i);
698 break;
699 }
700 }
701 return;
702 }
703 if (IsExpired(id))
704 {
705 return;
706 }
707
708 {
709 std::unique_lock lock{m_mutex};
710
711 Scheduler::Event event;
712 event.impl = id.PeekEventImpl();
713 event.key.m_ts = id.GetTs();
714 event.key.m_context = id.GetContext();
715 event.key.m_uid = id.GetUid();
716
717 m_events->Remove(event);
719 event.impl->Cancel();
720 event.impl->Unref();
721 }
722}
723
724void
726{
727 if (!IsExpired(id))
728 {
729 id.PeekEventImpl()->Cancel();
730 }
731}
732
733bool
735{
736 if (id.GetUid() == EventId::UID::DESTROY)
737 {
738 if (id.PeekEventImpl() == nullptr || id.PeekEventImpl()->IsCancelled())
739 {
740 return true;
741 }
742 // destroy events.
743 for (auto i = m_destroyEvents.begin(); i != m_destroyEvents.end(); i++)
744 {
745 if (*i == id)
746 {
747 return false;
748 }
749 }
750 return true;
751 }
752
753 //
754 // If the time of the event is less than the current timestamp of the
755 // simulator, the simulator has gone past the invocation time of the
756 // event, so the statement ev.GetTs () < m_currentTs does mean that
757 // the event has been fired even in realtime mode.
758 //
759 // The same is true for the next line involving the m_currentUid.
760 //
761 return id.PeekEventImpl() == nullptr || id.GetTs() < m_currentTs ||
762 (id.GetTs() == m_currentTs && id.GetUid() <= m_currentUid) ||
763 id.PeekEventImpl()->IsCancelled();
764}
765
766Time
768{
769 return TimeStep(0x7fffffffffffffffLL);
770}
771
772// System ID for non-distributed simulation is always zero
775{
776 return 0;
777}
778
784
785uint64_t
790
791void
797
804
805void
807{
808 NS_LOG_FUNCTION(this << limit);
809 m_hardLimit = limit;
810}
811
812Time
814{
815 NS_LOG_FUNCTION(this);
816 return m_hardLimit;
817}
818
819} // 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:44
@ INVALID
Invalid UID value.
Definition event-id.h:50
@ VALID
Schedule(), etc.
Definition event-id.h:58
@ DESTROY
ScheduleDestroy() events.
Definition event-id.h:54
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:430
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:96
bool IsPositive() const
Exactly equivalent to t >= 0.
Definition nstime.h:324
Time TimeStep(uint64_t ts)
Scheduler interface.
Definition nstime.h:1478
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:441
AttributeValue implementation for Time.
Definition nstime.h:1483
a unique identifier for an interface.
Definition type-id.h:49
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:999
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:75
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition enum.h:223
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition nstime.h:1484
Ptr< const AttributeChecker > MakeTimeChecker()
Helper to make an unbounded Time checker.
Definition nstime.h:1504
#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:194
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:274
#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:1381
Debug message logging.
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.
Definition enum.h:181
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.