A Discrete-Event Network Simulator
API
default-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) 2005,2006 INRIA
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  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #ifndef DEFAULT_SIMULATOR_IMPL_H
22 #define DEFAULT_SIMULATOR_IMPL_H
23 
24 #include "simulator-impl.h"
25 #include "scheduler.h"
26 #include "event-impl.h"
27 #include "system-thread.h"
28 #include "system-mutex.h"
29 
30 #include "ptr.h"
31 
32 #include <list>
33 
40 namespace ns3 {
41 
48 {
49 public:
54  static TypeId GetTypeId (void);
55 
60 
61  // Inherited
62  virtual void Destroy ();
63  virtual bool IsFinished (void) const;
64  virtual void Stop (void);
65  virtual void Stop (const Time &delay);
66  virtual EventId Schedule (const Time &delay, EventImpl *event);
67  virtual void ScheduleWithContext (uint32_t context, const Time &delay, EventImpl *event);
68  virtual EventId ScheduleNow (EventImpl *event);
69  virtual EventId ScheduleDestroy (EventImpl *event);
70  virtual void Remove (const EventId &id);
71  virtual void Cancel (const EventId &id);
72  virtual bool IsExpired (const EventId &id) const;
73  virtual void Run (void);
74  virtual Time Now (void) const;
75  virtual Time GetDelayLeft (const EventId &id) const;
76  virtual Time GetMaximumSimulationTime (void) const;
77  virtual void SetScheduler (ObjectFactory schedulerFactory);
78  virtual uint32_t GetSystemId (void) const;
79  virtual uint32_t GetContext (void) const;
80  virtual uint64_t GetEventCount (void) const;
81 
82 private:
83  virtual void DoDispose (void);
84 
86  void ProcessOneEvent (void);
88  void ProcessEventsWithContext (void);
89 
92  {
94  uint32_t context;
96  uint64_t timestamp;
99  };
101  typedef std::list<struct EventWithContext> EventsWithContext;
111 
113  typedef std::list<EventId> DestroyEvents;
117  bool m_stop;
120 
122  uint32_t m_uid;
124  uint32_t m_currentUid;
126  uint64_t m_currentTs;
130  uint64_t m_eventCount;
136 
139 };
140 
141 } // namespace ns3
142 
143 #endif /* DEFAULT_SIMULATOR_IMPL_H */
ns3::DefaultSimulatorImpl::ScheduleNow
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Definition: default-simulator-impl.cc:282
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::DefaultSimulatorImpl::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: default-simulator-impl.cc:298
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::DefaultSimulatorImpl::GetDelayLeft
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
Definition: default-simulator-impl.cc:316
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DefaultSimulatorImpl::Stop
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: default-simulator-impl.cc:213
ns3::SystemThread::ThreadId
pthread_t ThreadId
Type alias for the system-dependent thread object.
Definition: system-thread.h:62
ns3::DefaultSimulatorImpl::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: default-simulator-impl.cc:50
ns3::SystemMutex
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:59
ns3::DefaultSimulatorImpl::GetEventCount
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
Definition: default-simulator-impl.cc:416
ns3::DefaultSimulatorImpl::ProcessOneEvent
void ProcessOneEvent(void)
Process the next event.
Definition: default-simulator-impl.cc:139
ns3::DefaultSimulatorImpl::Cancel
virtual void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: default-simulator-impl.cc:362
scheduler.h
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations.
ns3::DefaultSimulatorImpl::m_eventsWithContextEmpty
bool m_eventsWithContextEmpty
Flag true if all events with context have been moved to the primary event queue.
Definition: default-simulator-impl.h:108
ns3::DefaultSimulatorImpl::m_main
SystemThread::ThreadId m_main
Main execution thread.
Definition: default-simulator-impl.h:138
ns3::DefaultSimulatorImpl::Schedule
virtual EventId Schedule(const Time &delay, EventImpl *event)
Schedule a future event execution (in the same context).
Definition: default-simulator-impl.cc:230
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::DefaultSimulatorImpl::m_destroyEvents
DestroyEvents m_destroyEvents
The container of events to run at Destroy.
Definition: default-simulator-impl.h:115
ns3::DefaultSimulatorImpl
The default single process simulator implementation.
Definition: default-simulator-impl.h:48
ns3::DefaultSimulatorImpl::ProcessEventsWithContext
void ProcessEventsWithContext(void)
Move events from a different context into the main event queue.
Definition: default-simulator-impl.cc:164
ns3::DefaultSimulatorImpl::ScheduleWithContext
virtual void ScheduleWithContext(uint32_t context, const Time &delay, EventImpl *event)
Schedule a future event execution (in a different context).
Definition: default-simulator-impl.cc:250
ns3::DefaultSimulatorImpl::DefaultSimulatorImpl
DefaultSimulatorImpl()
Constructor.
Definition: default-simulator-impl.cc:60
ns3::DefaultSimulatorImpl::m_currentTs
uint64_t m_currentTs
Timestamp of the current event.
Definition: default-simulator-impl.h:126
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition: object-factory.h:48
ns3::DefaultSimulatorImpl::Now
virtual Time Now(void) const
Return the current simulation virtual time.
Definition: default-simulator-impl.cc:309
ns3::DefaultSimulatorImpl::m_eventsWithContextMutex
SystemMutex m_eventsWithContextMutex
Mutex to control access to the list of events with context.
Definition: default-simulator-impl.h:110
event-impl.h
ns3::EventImpl declarations.
ns3::DefaultSimulatorImpl::Run
virtual void Run(void)
Run the simulation.
Definition: default-simulator-impl.cc:194
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::DefaultSimulatorImpl::GetSystemId
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
Definition: default-simulator-impl.cc:133
ns3::DefaultSimulatorImpl::m_unscheduledEvents
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the Destroy events; this...
Definition: default-simulator-impl.h:135
ns3::DefaultSimulatorImpl::GetMaximumSimulationTime
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
Definition: default-simulator-impl.cc:404
ns3::DefaultSimulatorImpl::m_events
Ptr< Scheduler > m_events
The event priority queue.
Definition: default-simulator-impl.h:119
ns3::DefaultSimulatorImpl::Destroy
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: default-simulator-impl.cc:99
system-thread.h
System-independent thread class ns3::SystemThread declaration.
simulator-impl.h
ns3::SimulatorImpl declaration.
ns3::DefaultSimulatorImpl::GetContext
virtual uint32_t GetContext(void) const
Get the current simulation context.
Definition: default-simulator-impl.cc:410
ns3::DefaultSimulatorImpl::EventsWithContext
std::list< struct EventWithContext > EventsWithContext
Container type for the events from a different context.
Definition: default-simulator-impl.h:101
ns3::DefaultSimulatorImpl::m_uid
uint32_t m_uid
Next event unique id.
Definition: default-simulator-impl.h:122
ns3::DefaultSimulatorImpl::m_eventCount
uint64_t m_eventCount
The event count.
Definition: default-simulator-impl.h:130
ns3::DefaultSimulatorImpl::DestroyEvents
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy()
Definition: default-simulator-impl.h:113
ns3::DefaultSimulatorImpl::EventWithContext::timestamp
uint64_t timestamp
Event timestamp.
Definition: default-simulator-impl.h:96
ns3::DefaultSimulatorImpl::EventWithContext::context
uint32_t context
The event context.
Definition: default-simulator-impl.h:94
ns3::DefaultSimulatorImpl::m_currentContext
uint32_t m_currentContext
Execution context of the current event.
Definition: default-simulator-impl.h:128
system-mutex.h
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
ns3::SimulatorImpl
The SimulatorImpl base class.
Definition: simulator-impl.h:49
ns3::DefaultSimulatorImpl::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: default-simulator-impl.cc:85
ns3::DefaultSimulatorImpl::IsFinished
virtual bool IsFinished(void) const
Check if the simulation should finish.
Definition: default-simulator-impl.cc:158
ns3::EventImpl
A simulation event.
Definition: event-impl.h:45
ns3::DefaultSimulatorImpl::EventWithContext
Wrap an event with its execution context.
Definition: default-simulator-impl.h:92
ns3::DefaultSimulatorImpl::SetScheduler
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
Definition: default-simulator-impl.cc:115
ns3::DefaultSimulatorImpl::IsExpired
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
Definition: default-simulator-impl.cc:371
ns3::DefaultSimulatorImpl::~DefaultSimulatorImpl
~DefaultSimulatorImpl()
Destructor.
Definition: default-simulator-impl.cc:79
ptr.h
ns3::Ptr smart pointer declaration and implementation.
ns3::DefaultSimulatorImpl::EventWithContext::event
EventImpl * event
The event implementation.
Definition: default-simulator-impl.h:98
ns3::DefaultSimulatorImpl::m_currentUid
uint32_t m_currentUid
Unique id of the current event.
Definition: default-simulator-impl.h:124
ns3::DefaultSimulatorImpl::m_stop
bool m_stop
Flag calling for the end of the simulation.
Definition: default-simulator-impl.h:117
ns3::DefaultSimulatorImpl::Remove
virtual void Remove(const EventId &id)
Remove an event from the event list.
Definition: default-simulator-impl.cc:329
ns3::DefaultSimulatorImpl::m_eventsWithContext
EventsWithContext m_eventsWithContext
The container of events from a different context.
Definition: default-simulator-impl.h:103