A Discrete-Event Network Simulator
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
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  */
22 #include "simulator-impl.h"
23 #include "system-thread.h"
25 #include "scheduler.h"
26 #include "synchronizer.h"
27 #include "event-impl.h"
29 #include "ptr.h"
30 #include "assert.h"
31 #include "log.h"
32 #include "system-mutex.h"
34 #include <list>
42 namespace ns3 {
57 {
58 public:
63  static TypeId GetTypeId (void);
84  };
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  virtual uint64_t GetEventCount (void) const;
113  void ScheduleRealtimeWithContext (uint32_t context, const Time &delay, EventImpl *event);
115  void ScheduleRealtime (const Time &delay, EventImpl *event);
122  void ScheduleRealtimeNowWithContext (uint32_t context, EventImpl *event);
124  void ScheduleRealtimeNow (EventImpl *event);
129  Time RealtimeNow (void) const;
149  void SetHardLimit (Time limit);
156  Time GetHardLimit (void) const;
158 private:
163  bool Running (void) const;
168  bool Realtime (void) const;
173  uint64_t NextTs (void) const;
175  void ProcessOneEvent (void);
177  virtual void DoDispose (void);
180  typedef std::list<EventId> DestroyEvents;
184  bool m_stop;
186  bool m_running;
199  uint32_t m_uid;
201  uint32_t m_currentUid;
203  uint64_t m_currentTs;
205  uint32_t m_currentContext;
207  uint64_t m_eventCount;
224 };
226 } // namespace ns3
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).
uint64_t m_eventCount
The event count.
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...
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 uint64_t GetEventCount(void) const
Get the number of events executed.
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.