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 
36 namespace ns3 {
37 
42 {
43 public:
44  static TypeId GetTypeId (void);
45 
53  };
54 
57 
58  virtual void Destroy ();
59  virtual bool IsFinished (void) const;
60  virtual void Stop (void);
61  virtual void Stop (Time const &time);
62  virtual EventId Schedule (Time const &time, EventImpl *event);
63  virtual void ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event);
64  virtual EventId ScheduleNow (EventImpl *event);
65  virtual EventId ScheduleDestroy (EventImpl *event);
66  virtual void Remove (const EventId &id);
67  virtual void Cancel (const EventId &id);
68  virtual bool IsExpired (const EventId &id) const;
69  virtual void Run (void);
70  virtual Time Now (void) const;
71  virtual Time GetDelayLeft (const EventId &id) const;
72  virtual Time GetMaximumSimulationTime (void) const;
73  virtual void SetScheduler (ObjectFactory schedulerFactory);
74  virtual uint32_t GetSystemId (void) const;
75  virtual uint32_t GetContext (void) const;
76 
77  void ScheduleRealtimeWithContext (uint32_t context, Time const &time, EventImpl *event);
78  void ScheduleRealtime (Time const &time, EventImpl *event);
79  void ScheduleRealtimeNowWithContext (uint32_t context, EventImpl *event);
80  void ScheduleRealtimeNow (EventImpl *event);
81  Time RealtimeNow (void) const;
82 
85 
86  void SetHardLimit (Time limit);
87  Time GetHardLimit (void) const;
88 
89 private:
90  bool Running (void) const;
91  bool Realtime (void) const;
92  uint64_t NextTs (void) const;
93  void ProcessOneEvent (void);
94  virtual void DoDispose (void);
95 
96  typedef std::list<EventId> DestroyEvents;
97  DestroyEvents m_destroyEvents;
98  bool m_stop;
99  bool m_running;
100 
101  // The following variables are protected using the m_mutex
104  uint32_t m_uid;
105  uint32_t m_currentUid;
106  uint64_t m_currentTs;
108 
110 
112 
117 
122 
124 };
125 
126 } // namespace ns3
127 
128 #endif /* REALTIME_SIMULATOR_IMPL_H */
void ScheduleRealtimeNowWithContext(uint32_t context, EventImpl *event)
void SetSynchronizationMode(RealtimeSimulatorImpl::SynchronizationMode mode)
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
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.
Make a best effort to keep synced to real-time.
virtual EventId Schedule(Time const &time, EventImpl *event)
Schedule a future event execution (in the same context).
System-independent thread class ns3::SystemThread declaration.
Smart pointer implementation.
SynchronizationMode
Enumeration of the types of packets supported in the class.
void ScheduleRealtimeNow(EventImpl *event)
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.
SynchronizationMode m_synchronizationMode
The policy to use if the simulation cannot keep synchronized to real-time.
void ScheduleRealtimeWithContext(uint32_t context, Time const &time, EventImpl *event)
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...
virtual void ScheduleWithContext(uint32_t context, Time const &time, EventImpl *event)
Schedule a future event execution (in a different context).
RealtimeSimulatorImpl::SynchronizationMode GetSynchronizationMode(void) const
System-independent mutex primitive, ns3::SystemMutex, and ns3::CriticalSection.
ns3::Scheduler abstract base class, ns3::Scheduler::Event and ns3::Scheduler::EventKey declarations...
virtual Time Now(void) const
Return the current simulation virtual time.
virtual void Run(void)
Run the simulation.
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
pthread_t ThreadId
Type alias for the system-dependent thread object.
Definition: system-thread.h:62
std::list< EventId > DestroyEvents
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...
Introspection did not find any typical Config paths.
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
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 void Remove(const EventId &id)
Remove an event from the event list.
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
A class which provides a relatively platform-independent Mutual Exclusion thread synchronization prim...
Definition: system-mutex.h:58
ns3::Synchronizer declaration.
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
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.
void ScheduleRealtime(Time const &time, EventImpl *event)
Debug message logging.
virtual bool IsFinished(void) const
Check if the simulation should finish.
a unique identifier for an interface.
Definition: type-id.h:51
The SimulatorImpl base class.