A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
realtime-simulator-impl.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef REALTIME_SIMULATOR_IMPL_H
19#define REALTIME_SIMULATOR_IMPL_H
20
21#include "assert.h"
22#include "event-impl.h"
23#include "log.h"
24#include "ptr.h"
25#include "scheduler.h"
26#include "simulator-impl.h"
27#include "synchronizer.h"
28
29#include <list>
30#include <mutex>
31#include <thread>
32
39namespace ns3
40{
41
55{
56 public:
61 static TypeId GetTypeId();
62
67 {
83 };
84
88 ~RealtimeSimulatorImpl() override;
89
90 // Inherited from SimulatorImpl
91 void Destroy() override;
92 bool IsFinished() const override;
93 void Stop() override;
94 void Stop(const Time& delay) override;
95 EventId Schedule(const Time& delay, EventImpl* event) override;
96 void ScheduleWithContext(uint32_t context, const Time& delay, EventImpl* event) override;
97 EventId ScheduleNow(EventImpl* event) override;
98 EventId ScheduleDestroy(EventImpl* event) override;
99 void Remove(const EventId& ev) override;
100 void Cancel(const EventId& ev) override;
101 bool IsExpired(const EventId& ev) const override;
102 void Run() override;
103 Time Now() const override;
104 Time GetDelayLeft(const EventId& id) const override;
105 Time GetMaximumSimulationTime() const override;
106 void SetScheduler(ObjectFactory schedulerFactory) override;
107 uint32_t GetSystemId() const override;
108 uint32_t GetContext() const override;
109 uint64_t GetEventCount() const override;
110
112 void ScheduleRealtimeWithContext(uint32_t context, const Time& delay, EventImpl* event);
119 void ScheduleRealtime(const Time& delay, EventImpl* event);
132 void ScheduleRealtimeNow(EventImpl* event);
137 Time RealtimeNow() const;
138
150
157 void SetHardLimit(Time limit);
164 Time GetHardLimit() const;
165
166 private:
171 bool Running() const;
176 bool Realtime() const;
181 uint64_t NextTs() const;
183 void ProcessOneEvent();
185 void DoDispose() override;
186
188 typedef std::list<EventId> DestroyEvents;
192 bool m_stop;
195
211 uint64_t m_currentTs;
215 uint64_t m_eventCount;
219 mutable std::mutex m_mutex;
220
223
226
229
231 std::thread::id m_main;
232};
233
234} // namespace ns3
235
236#endif /* REALTIME_SIMULATOR_IMPL_H */
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
An identifier for simulation events.
Definition: event-id.h:55
A simulation event.
Definition: event-impl.h:46
Instantiate subclasses of ns3::Object.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
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.
std::list< EventId > DestroyEvents
Container type for events to be run at destroy time.
Time GetMaximumSimulationTime() const override
Get the maximum representable simulation time.
The SimulatorImpl base class.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
ns3::EventImpl declarations.
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::Ptr smart pointer declaration and implementation.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::SimulatorImpl declaration.
ns3::Synchronizer declaration.