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 "ns3/system-mutex.h"
29 
30 #include "ptr.h"
31 
32 #include <list>
33 
40 namespace ns3 {
41 
48 {
49 public:
50  static TypeId GetTypeId (void);
51 
54 
55  virtual void Destroy ();
56  virtual bool IsFinished (void) const;
57  virtual void Stop (void);
58  virtual void Stop (Time const &time);
59  virtual EventId Schedule (Time const &time, EventImpl *event);
60  virtual void ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event);
61  virtual EventId ScheduleNow (EventImpl *event);
62  virtual EventId ScheduleDestroy (EventImpl *event);
63  virtual void Remove (const EventId &id);
64  virtual void Cancel (const EventId &id);
65  virtual bool IsExpired (const EventId &id) const;
66  virtual void Run (void);
67  virtual Time Now (void) const;
68  virtual Time GetDelayLeft (const EventId &id) const;
69  virtual Time GetMaximumSimulationTime (void) const;
70  virtual void SetScheduler (ObjectFactory schedulerFactory);
71  virtual uint32_t GetSystemId (void) const;
72  virtual uint32_t GetContext (void) const;
73 
74 private:
75  virtual void DoDispose (void);
76  void ProcessOneEvent (void);
77  void ProcessEventsWithContext (void);
78 
80  uint32_t context;
81  uint64_t timestamp;
83  };
84  typedef std::list<struct EventWithContext> EventsWithContext;
85  EventsWithContext m_eventsWithContext;
88 
89  typedef std::list<EventId> DestroyEvents;
90  DestroyEvents m_destroyEvents;
91  bool m_stop;
93 
94  uint32_t m_uid;
95  uint32_t m_currentUid;
96  uint64_t m_currentTs;
97  uint32_t m_currentContext;
98  // number of events that have been inserted but not yet scheduled,
99  // not counting the "destroy" events; this is used for validation
101 
103 };
104 
105 } // namespace ns3
106 
107 #endif /* DEFAULT_SIMULATOR_IMPL_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
EventsWithContext m_eventsWithContext
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
ns3::EventImpl declarations.
virtual void DoDispose(void)
Destructor implementation.
System-independent thread class ns3::SystemThread declaration.
Smart pointer implementation.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
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...
Declaration of class ns3::SimulatorImpl.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
virtual Time Now(void) const
Return the current simulation virtual time.
pthread_t ThreadId
Type alias for the system-dependent thread object.
Definition: system-thread.h:62
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
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...
std::list< struct EventWithContext > EventsWithContext
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual void Remove(const EventId &id)
Remove an event from the event list.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:58
The default single process simulator implementation.
virtual void ScheduleWithContext(uint32_t context, Time const &time, EventImpl *event)
Schedule a future event execution (in a different context).
virtual EventId Schedule(Time const &time, EventImpl *event)
Schedule a future event execution (in the same context).
Instantiate subclasses of ns3::Object.
A simulation event.
Definition: event-impl.h:44
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual void Run(void)
Run the simulation.
An identifier for simulation events.
Definition: event-id.h:53
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
SystemThread::ThreadId m_main
std::list< EventId > DestroyEvents
a unique identifier for an interface.
Definition: type-id.h:57
The SimulatorImpl base class.