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;
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;
148  void SetHardLimit (Time limit);
155  Time GetHardLimit (void) const;
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);
179  typedef std::list<EventId> DestroyEvents;
181  DestroyEvents m_destroyEvents;
183  bool m_stop;
185  bool m_running;
198  uint32_t m_uid;
200  uint32_t m_currentUid;
202  uint64_t m_currentTs;
204  uint32_t m_currentContext;
221 };
223 } // namespace ns3
void ProcessOneEvent(void)
Process the next event.
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.
uint64_t NextTs(void) const
Get the timestep of the next event.
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.
Smart pointer implementation.
void ScheduleRealtimeWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
void ScheduleRealtimeNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Time RealtimeNow(void) const
Get the current real time from the synchronizer.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
Time m_hardLimit
The maximum allowable drift from real-time in SYNC_HARD_LIMIT mode.
Time GetHardLimit(void) const
Get the current fatal error threshold for SynchronizationMode SYNC_HARD_LIMIT.
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 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.
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
Get the SynchronizationMode.
Declaration of class ns3::SimulatorImpl.
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.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
What to do when we can't maintain real time synchrony.
SystemMutex m_mutex
Mutex to control access to key state.
virtual Time Now(void) const
Return the current simulation virtual time.
virtual void Run(void)
Run the simulation.
Definition of assertion macros NS_ASSERT() and NS_ASSERT_MSG().
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
bool m_stop
Has the stopping condition been reached?
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.
Realtime version of SimulatorImpl.
uint32_t m_uid
Unique id of the current event.
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...
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
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.
virtual bool IsExpired(const EventId &ev) const
Check if an event has already run or been cancelled.
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
bool Running(void) const
Is the simulator running?
bool Realtime(void) const
Check that the Synchronizer is locked to the real time clock.
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Debug message logging.
virtual bool IsFinished(void) const
Check if the simulation should finish.
a unique identifier for an interface.
Definition: type-id.h:58
Make a best effort to keep synced to real-time.
uint32_t m_currentContext
The event list.
Keep to real time within the hard limit tolerance configured with SetHardLimit, or die trying...
The SimulatorImpl base class.