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 
84  };
85 
90 
91  // Inherited from SimulatorImpl
92  virtual void Destroy ();
93  virtual bool IsFinished (void) const;
94  virtual void Stop (void);
95  virtual void Stop (const Time &delay);
96  virtual EventId Schedule (const Time &delay, EventImpl *event);
97  virtual void ScheduleWithContext (uint32_t context, const Time &delay, EventImpl *event);
98  virtual EventId ScheduleNow (EventImpl *event);
99  virtual EventId ScheduleDestroy (EventImpl *event);
100  virtual void Remove (const EventId &ev);
101  virtual void Cancel (const EventId &ev);
102  virtual bool IsExpired (const EventId &ev) const;
103  virtual void Run (void);
104  virtual Time Now (void) const;
105  virtual Time GetDelayLeft (const EventId &id) const;
106  virtual Time GetMaximumSimulationTime (void) const;
107  virtual void SetScheduler (ObjectFactory schedulerFactory);
108  virtual uint32_t GetSystemId (void) const;
109  virtual uint32_t GetContext (void) const;
110 
112  void ScheduleRealtimeWithContext (uint32_t context, const Time &delay, EventImpl *event);
114  void ScheduleRealtime (const Time &delay, EventImpl *event);
121  void ScheduleRealtimeNowWithContext (uint32_t context, EventImpl *event);
123  void ScheduleRealtimeNow (EventImpl *event);
128  Time RealtimeNow (void) const;
129 
141 
148  void SetHardLimit (Time limit);
155  Time GetHardLimit (void) const;
156 
157 private:
162  bool Running (void) const;
167  bool Realtime (void) const;
172  uint64_t NextTs (void) const;
174  void ProcessOneEvent (void);
176  virtual void DoDispose (void);
177 
179  typedef std::list<EventId> DestroyEvents;
183  bool m_stop;
185  bool m_running;
186 
198  uint32_t m_uid;
200  uint32_t m_currentUid;
202  uint64_t m_currentTs;
204  uint32_t m_currentContext;
209 
212 
215 
218 
221 };
222 
223 } // namespace ns3
224 
225 #endif /* REALTIME_SIMULATOR_IMPL_H */
void ProcessOneEvent(void)
Process the next event.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
Schedule an event to run at the current virtual time.
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Set the SynchronizationMode.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Ptr< Synchronizer > m_synchronizer
The synchronizer in use to track real time.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
ns3::EventImpl declarations.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
SystemThread::ThreadId m_main
Main SystemThread.
System-independent thread class ns3::SystemThread declaration.
int m_unscheduledEvents
Unique id for the next event to be scheduled.
ns3::Ptr smart pointer declaration and implementation.
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual Time Now(void) const
Return the current simulation virtual time.
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
SynchronizationMode m_synchronizationMode
SynchronizationMode policy.
bool m_running
Is the simulator currently running.
DestroyEvents m_destroyEvents
Container for events to be run at destroy time.
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual void DoDispose(void)
Destructor implementation.
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...
Ptr< Scheduler > m_events
The event list.
ns3::SimulatorImpl declaration.
uint32_t m_currentUid
Timestep of the current event.
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying...
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
SystemMutex m_mutex
Mutex to control access to key state.
virtual void Run(void)
Run the simulation.
NS_ASSERT() and NS_ASSERT_MSG() macro definitions.
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
bool m_stop
Has the stopping condition been reached?
bool Running(void) const
Is the simulator running?
void ScheduleRealtime(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
pthread_t ThreadId
Type alias for the system-dependent thread object.
Definition: system-thread.h:62
std::list< EventId > DestroyEvents
Container type for events to be run at destroy time.
virtual void Remove(const EventId &ev)
Remove an event from the event list.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
Realtime version of SimulatorImpl.
uint32_t m_uid
Unique id of the current event.
uint64_t NextTs(void) const
Get the timestep of the next event.
virtual void Cancel(const EventId &ev)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
SynchronizationMode
What to do when we can&#39;t maintain real time synchrony.
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
void SetHardLimit(Time limit)
Set the fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:58
ns3::Synchronizer declaration.
uint64_t m_currentTs
Execution context.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
Instantiate subclasses of ns3::Object.
A simulation event.
Definition: event-impl.h:44
An identifier for simulation events.
Definition: event-id.h:53
Make a best effort to keep synced to real-time.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Debug message logging.
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
a unique identifier for an interface.
Definition: type-id.h:58
uint32_t m_currentContext
The event list.
The SimulatorImpl base class.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.