A Discrete-Event Network Simulator
API
realtime-simulator-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */
18 
19 #ifndef REALTIME_SIMULATOR_IMPL_H
20 #define REALTIME_SIMULATOR_IMPL_H
21 
22 #include "simulator-impl.h"
23 #include "system-thread.h"
24 
25 #include "scheduler.h"
26 #include "synchronizer.h"
27 #include "event-impl.h"
28 
29 #include "ptr.h"
30 #include "assert.h"
31 #include "log.h"
32 #include "system-mutex.h"
33 
34 #include <list>
35 
42 namespace ns3 {
43 
57 {
58 public:
63  static TypeId GetTypeId (void);
64 
69  {
85  };
86 
91 
92  // Inherited from SimulatorImpl
93  virtual void Destroy ();
94  virtual bool IsFinished (void) const;
95  virtual void Stop (void);
96  virtual void Stop (const Time &delay);
97  virtual EventId Schedule (const Time &delay, EventImpl *event);
98  virtual void ScheduleWithContext (uint32_t context, const Time &delay, EventImpl *event);
99  virtual EventId ScheduleNow (EventImpl *event);
100  virtual EventId ScheduleDestroy (EventImpl *event);
101  virtual void Remove (const EventId &ev);
102  virtual void Cancel (const EventId &ev);
103  virtual bool IsExpired (const EventId &ev) const;
104  virtual void Run (void);
105  virtual Time Now (void) const;
106  virtual Time GetDelayLeft (const EventId &id) const;
107  virtual Time GetMaximumSimulationTime (void) const;
108  virtual void SetScheduler (ObjectFactory schedulerFactory);
109  virtual uint32_t GetSystemId (void) const;
110  virtual uint32_t GetContext (void) const;
111  virtual uint64_t GetEventCount (void) const;
112 
114  void ScheduleRealtimeWithContext (uint32_t context, const Time &delay, EventImpl *event);
116  void ScheduleRealtime (const Time &delay, EventImpl *event);
123  void ScheduleRealtimeNowWithContext (uint32_t context, EventImpl *event);
125  void ScheduleRealtimeNow (EventImpl *event);
130  Time RealtimeNow (void) const;
131 
143 
150  void SetHardLimit (Time limit);
157  Time GetHardLimit (void) const;
158 
159 private:
164  bool Running (void) const;
169  bool Realtime (void) const;
174  uint64_t NextTs (void) const;
176  void ProcessOneEvent (void);
178  virtual void DoDispose (void);
179 
181  typedef std::list<EventId> DestroyEvents;
185  bool m_stop;
187  bool m_running;
188 
200  uint32_t m_uid;
202  uint32_t m_currentUid;
204  uint64_t m_currentTs;
208  uint64_t m_eventCount;
213 
216 
219 
222 
225 };
226 
227 } // namespace ns3
228 
229 #endif /* REALTIME_SIMULATOR_IMPL_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::RealtimeSimulatorImpl::m_events
Ptr< Scheduler > m_events
The event list.
Definition: realtime-simulator-impl.h:196
ns3::RealtimeSimulatorImpl::GetEventCount
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
Definition: realtime-simulator-impl.cc:823
ns3::RealtimeSimulatorImpl::SetSynchronizationMode
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
Definition: realtime-simulator-impl.cc:829
ns3::RealtimeSimulatorImpl::Schedule
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
Definition: realtime-simulator-impl.cc:514
ns3::RealtimeSimulatorImpl::Run
virtual void Run(void)
Run the simulation.
Definition: realtime-simulator-impl.cc:423
ns3::RealtimeSimulatorImpl::RealtimeNow
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
Definition: realtime-simulator-impl.cc:670
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::RealtimeSimulatorImpl::SYNC_BEST_EFFORT
@ SYNC_BEST_EFFORT
Make a best effort to keep synced to real-time.
Definition: realtime-simulator-impl.h:75
ns3::RealtimeSimulatorImpl::Remove
virtual void Remove(const EventId &ev)
Remove an event from the event list.
Definition: realtime-simulator-impl.cc:713
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::RealtimeSimulatorImpl::m_uid
uint32_t m_uid
Unique id of the current event.
Definition: realtime-simulator-impl.h:200
ns3::RealtimeSimulatorImpl
Realtime version of SimulatorImpl.
Definition: realtime-simulator-impl.h:57
ns3::SystemThread::ThreadId
pthread_t ThreadId
Type alias for the system-dependent thread object.
Definition: system-thread.h:62
ns3::RealtimeSimulatorImpl::SetScheduler
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
Definition: realtime-simulator-impl.cc:147
ns3::RealtimeSimulatorImpl::Now
virtual Time Now(void) const
Return the current simulation virtual time.
Definition: realtime-simulator-impl.cc:600
ns3::RealtimeSimulatorImpl::m_currentContext
uint32_t m_currentContext
The event list.
Definition: realtime-simulator-impl.h:206
ns3::RealtimeSimulatorImpl::Cancel
virtual void Cancel(const EventId &ev)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: realtime-simulator-impl.cc:752
ns3::RealtimeSimulatorImpl::Stop
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: realtime-simulator-impl.cc:497
synchronizer.h
ns3::Synchronizer declaration.
ns3::SystemMutex
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:59
ns3::RealtimeSimulatorImpl::ScheduleRealtimeNow
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Definition: realtime-simulator-impl.cc:663
ns3::RealtimeSimulatorImpl::GetMaximumSimulationTime
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
Definition: realtime-simulator-impl.cc:804
assert.h
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
ns3::RealtimeSimulatorImpl::ScheduleRealtimeNowWithContext
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
Schedule an event to run at the current virtual time.
Definition: realtime-simulator-impl.cc:637
ns3::RealtimeSimulatorImpl::ScheduleDestroy
virtual EventId ScheduleDestroy(EventImpl *event)
Schedule an event to run at the end of the simulation, after the Stop() time or condition has been re...
Definition: realtime-simulator-impl.cc:676
ns3::RealtimeSimulatorImpl::m_synchronizer
Ptr< Synchronizer > m_synchronizer
The synchronizer in use to track real time.
Definition: realtime-simulator-impl.h:215
ns3::RealtimeSimulatorImpl::ScheduleNow
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Definition: realtime-simulator-impl.cc:579
ns3::RealtimeSimulatorImpl::SynchronizationMode
SynchronizationMode
What to do when we can't maintain real time synchrony.
Definition: realtime-simulator-impl.h:69
ns3::RealtimeSimulatorImpl::NextTs
uint64_t NextTs(void) const
Get the timestep of the next event.
Definition: realtime-simulator-impl.cc:414
scheduler.h
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::RealtimeSimulatorImpl::ScheduleWithContext
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
Definition: realtime-simulator-impl.cc:543
ns3::RealtimeSimulatorImpl::RealtimeSimulatorImpl
RealtimeSimulatorImpl()
Constructor.
Definition: realtime-simulator-impl.cc:77
ns3::RealtimeSimulatorImpl::SetHardLimit
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
Definition: realtime-simulator-impl.cc:843
ns3::RealtimeSimulatorImpl::IsFinished
virtual bool IsFinished(void) const
Check if the simulation should finish.
Definition: realtime-simulator-impl.cc:399
ns3::RealtimeSimulatorImpl::m_hardLimit
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
Definition: realtime-simulator-impl.h:221
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::RealtimeSimulatorImpl::~RealtimeSimulatorImpl
~RealtimeSimulatorImpl()
Destructor.
Definition: realtime-simulator-impl.cc:102
ns3::RealtimeSimulatorImpl::ScheduleRealtimeWithContext
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
Definition: realtime-simulator-impl.cc:609
ns3::RealtimeSimulatorImpl::GetContext
virtual uint32_t GetContext(void) const
Get the current simulation context.
Definition: realtime-simulator-impl.cc:817
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition: object-factory.h:48
event-impl.h
ns3::EventImpl declarations.
ns3::RealtimeSimulatorImpl::m_running
bool m_running
Is the simulator currently running.
Definition: realtime-simulator-impl.h:187
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::RealtimeSimulatorImpl::ProcessOneEvent
void ProcessOneEvent(void)
Process the next event.
Definition: realtime-simulator-impl.cc:169
ns3::RealtimeSimulatorImpl::m_currentTs
uint64_t m_currentTs
Execution context.
Definition: realtime-simulator-impl.h:204
ns3::RealtimeSimulatorImpl::GetDelayLeft
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
Definition: realtime-simulator-impl.cc:698
system-thread.h
System-independent thread class ns3::SystemThread declaration.
ns3::RealtimeSimulatorImpl::m_unscheduledEvents
int m_unscheduledEvents
Unique id for the next event to be scheduled.
Definition: realtime-simulator-impl.h:198
simulator-impl.h
ns3::SimulatorImpl declaration.
ns3::RealtimeSimulatorImpl::GetSystemId
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
Definition: realtime-simulator-impl.cc:811
log.h
Debug message logging.
system-mutex.h
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
ns3::SimulatorImpl
The SimulatorImpl base class.
Definition: simulator-impl.h:49
ns3::RealtimeSimulatorImpl::ScheduleRealtime
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
Definition: realtime-simulator-impl.cc:630
ns3::RealtimeSimulatorImpl::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: realtime-simulator-impl.cc:108
ns3::RealtimeSimulatorImpl::m_eventCount
uint64_t m_eventCount
The event count.
Definition: realtime-simulator-impl.h:208
ns3::RealtimeSimulatorImpl::m_mutex
SystemMutex m_mutex
Mutex to control access to key state.
Definition: realtime-simulator-impl.h:212
ns3::EventImpl
A simulation event.
Definition: event-impl.h:45
ns3::RealtimeSimulatorImpl::GetHardLimit
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
Definition: realtime-simulator-impl.cc:850
ns3::RealtimeSimulatorImpl::m_main
SystemThread::ThreadId m_main
Main SystemThread.
Definition: realtime-simulator-impl.h:224
ns3::RealtimeSimulatorImpl::m_destroyEvents
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
Definition: realtime-simulator-impl.h:183
ns3::RealtimeSimulatorImpl::Realtime
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
Definition: realtime-simulator-impl.cc:491
ns3::RealtimeSimulatorImpl::Destroy
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: realtime-simulator-impl.cc:122
ns3::RealtimeSimulatorImpl::m_stop
bool m_stop
Has the stopping condition been reached?
Definition: realtime-simulator-impl.h:185
ns3::RealtimeSimulatorImpl::Running
bool Running(void) const
Is the simulator running?
Definition: realtime-simulator-impl.cc:485
ns3::RealtimeSimulatorImpl::m_synchronizationMode
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
Definition: realtime-simulator-impl.h:218
ns3::RealtimeSimulatorImpl::DestroyEvents
std::list< EventId > DestroyEvents
Container type for events to be run at destroy time.
Definition: realtime-simulator-impl.h:181
ns3::RealtimeSimulatorImpl::GetTypeId
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
Definition: realtime-simulator-impl.cc:55
ns3::RealtimeSimulatorImpl::GetSynchronizationMode
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
Definition: realtime-simulator-impl.cc:836
ns3::RealtimeSimulatorImpl::m_currentUid
uint32_t m_currentUid
Timestep of the current event.
Definition: realtime-simulator-impl.h:202
ns3::RealtimeSimulatorImpl::IsExpired
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
Definition: realtime-simulator-impl.cc:761
ptr.h
ns3::Ptr smart pointer declaration and implementation.
ns3::RealtimeSimulatorImpl::SYNC_HARD_LIMIT
@ SYNC_HARD_LIMIT
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying.
Definition: realtime-simulator-impl.h:84