A Discrete-Event Network Simulator
API
distributed-simulator-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation;
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15  *
16  * Author: George Riley <riley@ece.gatech.edu>
17  *
18  */
19 
26 #ifndef NS3_DISTRIBUTED_SIMULATOR_IMPL_H
27 #define NS3_DISTRIBUTED_SIMULATOR_IMPL_H
28 
29 #include "ns3/simulator-impl.h"
30 #include "ns3/scheduler.h"
31 #include "ns3/event-impl.h"
32 #include "ns3/ptr.h"
33 
34 #include <list>
35 
36 namespace ns3 {
37 
44 {
45 public:
47  : m_txCount (0),
48  m_rxCount (0),
49  m_myId (0),
50  m_isFinished (false)
51  {
52  }
53 
61  LbtsMessage (uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time& t)
62  : m_txCount (txc),
63  m_rxCount (rxc),
64  m_myId (id),
65  m_smallestTime (t),
66  m_isFinished (isFinished)
67  {
68  }
69 
70  ~LbtsMessage ();
71 
79  uint32_t GetTxCount ();
83  uint32_t GetRxCount ();
87  uint32_t GetMyId ();
91  bool IsFinished ();
92 
93 private:
94  uint32_t m_txCount;
95  uint32_t m_rxCount;
96  uint32_t m_myId;
98  bool m_isFinished;
99 };
100 
108 {
109 public:
114  static TypeId GetTypeId (void);
115 
120 
121  // virtual from SimulatorImpl
122  virtual void Destroy ();
123  virtual bool IsFinished (void) const;
124  virtual void Stop (void);
125  virtual void Stop (Time const &delay);
126  virtual EventId Schedule (Time const &delay, EventImpl *event);
127  virtual void ScheduleWithContext (uint32_t context, Time const &delay, EventImpl *event);
128  virtual EventId ScheduleNow (EventImpl *event);
129  virtual EventId ScheduleDestroy (EventImpl *event);
130  virtual void Remove (const EventId &id);
131  virtual void Cancel (const EventId &id);
132  virtual bool IsExpired (const EventId &id) const;
133  virtual void Run (void);
134  virtual Time Now (void) const;
135  virtual Time GetDelayLeft (const EventId &id) const;
136  virtual Time GetMaximumSimulationTime (void) const;
137  virtual void SetScheduler (ObjectFactory schedulerFactory);
138  virtual uint32_t GetSystemId (void) const;
139  virtual uint32_t GetContext (void) const;
140  virtual uint64_t GetEventCount (void) const;
141 
155  virtual void BoundLookAhead (const Time lookAhead);
156 
157 private:
158  // Inherited from Object
159  virtual void DoDispose (void);
160 
169  void CalculateLookAhead (void);
176  bool IsLocalFinished (void) const;
177 
179  void ProcessOneEvent (void);
187  uint64_t NextTs (void) const;
193  Time Next (void) const;
194 
196  typedef std::list<EventId> DestroyEvents;
197 
201  bool m_stop;
206 
208  uint32_t m_uid;
210  uint32_t m_currentUid;
212  uint64_t m_currentTs;
216  uint64_t m_eventCount;
222 
228  uint32_t m_myId;
229  uint32_t m_systemCount;
231  static Time m_lookAhead;
233 };
234 
235 } // namespace ns3
236 
237 #endif /* NS3_DISTRIBUTED_SIMULATOR_IMPL_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::DistributedSimulatorImpl::m_currentUid
uint32_t m_currentUid
Unique id of the current event.
Definition: distributed-simulator-impl.h:210
ns3::DistributedSimulatorImpl::m_myId
uint32_t m_myId
MPI rank.
Definition: distributed-simulator-impl.h:228
ns3::DistributedSimulatorImpl::m_grantedTime
Time m_grantedTime
End of current window.
Definition: distributed-simulator-impl.h:230
ns3::DistributedSimulatorImpl::ScheduleWithContext
virtual void ScheduleWithContext(uint32_t context, Time const &delay, EventImpl *event)
Schedule a future event execution (in a different context).
Definition: distributed-simulator-impl.cc:493
ns3::EventId
An identifier for simulation events.
Definition: event-id.h:54
ns3::DistributedSimulatorImpl::DestroyEvents
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy().
Definition: distributed-simulator-impl.h:196
ns3::DistributedSimulatorImpl::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: distributed-simulator-impl.cc:524
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::DistributedSimulatorImpl::m_eventCount
uint64_t m_eventCount
The event count.
Definition: distributed-simulator-impl.h:216
ns3::DistributedSimulatorImpl
Distributed simulator implementation using lookahead.
Definition: distributed-simulator-impl.h:108
ns3::DistributedSimulatorImpl::Schedule
virtual EventId Schedule(Time const &delay, EventImpl *event)
Schedule a future event execution (in the same context).
Definition: distributed-simulator-impl.cc:473
ns3::DistributedSimulatorImpl::~DistributedSimulatorImpl
~DistributedSimulatorImpl()
Destructor.
Definition: distributed-simulator-impl.cc:127
ns3::DistributedSimulatorImpl::GetMaximumSimulationTime
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
Definition: distributed-simulator-impl.cc:630
ns3::DistributedSimulatorImpl::DistributedSimulatorImpl
DistributedSimulatorImpl()
Default constructor.
Definition: distributed-simulator-impl.cc:100
ns3::DistributedSimulatorImpl::ProcessOneEvent
void ProcessOneEvent(void)
Process the next event.
Definition: distributed-simulator-impl.cc:311
ns3::DistributedSimulatorImpl::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: distributed-simulator-impl.cc:587
ns3::DistributedSimulatorImpl::GetContext
virtual uint32_t GetContext(void) const
Get the current simulation context.
Definition: distributed-simulator-impl.cc:638
ns3::DistributedSimulatorImpl::IsLocalFinished
bool IsLocalFinished(void) const
Check if this rank is finished.
Definition: distributed-simulator-impl.cc:336
ns3::DistributedSimulatorImpl::GetEventCount
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
Definition: distributed-simulator-impl.cc:644
ns3::LbtsMessage::~LbtsMessage
~LbtsMessage()
Definition: distributed-simulator-impl.cc:49
ns3::DistributedSimulatorImpl::ScheduleNow
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Definition: distributed-simulator-impl.cc:508
ns3::DistributedSimulatorImpl::GetDelayLeft
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
Definition: distributed-simulator-impl.cc:541
ns3::LbtsMessage::m_smallestTime
Time m_smallestTime
Earliest next event timestamp.
Definition: distributed-simulator-impl.h:97
ns3::DistributedSimulatorImpl::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: distributed-simulator-impl.cc:133
ns3::DistributedSimulatorImpl::Next
Time Next(void) const
Get the time of the next event, as returned by NextTs().
Definition: distributed-simulator-impl.cc:358
ns3::DistributedSimulatorImpl::IsFinished
virtual bool IsFinished(void) const
Check if the simulation should finish.
Definition: distributed-simulator-impl.cc:330
ns3::LbtsMessage
Structure used for all-reduce LBTS computation.
Definition: distributed-simulator-impl.h:44
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::LbtsMessage::IsFinished
bool IsFinished()
Definition: distributed-simulator-impl.cc:77
ns3::DistributedSimulatorImpl::Destroy
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
Definition: distributed-simulator-impl.cc:148
ns3::DistributedSimulatorImpl::IsExpired
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
Definition: distributed-simulator-impl.cc:596
ns3::DistributedSimulatorImpl::m_stop
bool m_stop
Flag calling for the end of the simulation.
Definition: distributed-simulator-impl.h:201
ns3::DistributedSimulatorImpl::m_currentContext
uint32_t m_currentContext
Execution context of the current event.
Definition: distributed-simulator-impl.h:214
ns3::LbtsMessage::GetSmallestTime
Time GetSmallestTime()
Definition: distributed-simulator-impl.cc:54
ns3::LbtsMessage::m_isFinished
bool m_isFinished
true when this rank has no more events.
Definition: distributed-simulator-impl.h:98
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition: object-factory.h:48
ns3::DistributedSimulatorImpl::GetSystemId
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
Definition: distributed-simulator-impl.cc:448
ns3::DistributedSimulatorImpl::m_unscheduledEvents
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the "destroy" events; th...
Definition: distributed-simulator-impl.h:221
ns3::LbtsMessage::GetTxCount
uint32_t GetTxCount()
Definition: distributed-simulator-impl.cc:60
ns3::DistributedSimulatorImpl::Remove
virtual void Remove(const EventId &id)
Remove an event from the event list.
Definition: distributed-simulator-impl.cc:554
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::DistributedSimulatorImpl::m_destroyEvents
DestroyEvents m_destroyEvents
The container of events to run at Destroy()
Definition: distributed-simulator-impl.h:199
ns3::LbtsMessage::m_txCount
uint32_t m_txCount
Count of transmitted messages.
Definition: distributed-simulator-impl.h:94
ns3::LbtsMessage::m_myId
uint32_t m_myId
System Id of the rank sending this LBTS.
Definition: distributed-simulator-impl.h:96
ns3::DistributedSimulatorImpl::GetTypeId
static TypeId GetTypeId(void)
Register this type.
Definition: distributed-simulator-impl.cc:90
ns3::DistributedSimulatorImpl::BoundLookAhead
virtual void BoundLookAhead(const Time lookAhead)
Add additional bound to lookahead constraints.
Definition: distributed-simulator-impl.cc:279
ns3::DistributedSimulatorImpl::m_currentTs
uint64_t m_currentTs
Timestamp of the current event.
Definition: distributed-simulator-impl.h:212
ns3::DistributedSimulatorImpl::m_globalFinished
bool m_globalFinished
Are all parallel instances completed.
Definition: distributed-simulator-impl.h:203
ns3::LbtsMessage::GetRxCount
uint32_t GetRxCount()
Definition: distributed-simulator-impl.cc:66
ns3::SimulatorImpl
The SimulatorImpl base class.
Definition: simulator-impl.h:49
ns3::DistributedSimulatorImpl::m_uid
uint32_t m_uid
Next event unique id.
Definition: distributed-simulator-impl.h:208
ns3::DistributedSimulatorImpl::m_pLBTS
LbtsMessage * m_pLBTS
Container for Lbts messages, one per rank.
Definition: distributed-simulator-impl.h:227
ns3::LbtsMessage::LbtsMessage
LbtsMessage(uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time &t)
Definition: distributed-simulator-impl.h:61
ns3::EventImpl
A simulation event.
Definition: event-impl.h:45
ns3::DistributedSimulatorImpl::CalculateLookAhead
void CalculateLookAhead(void)
Calculate lookahead constraint based on network latency.
Definition: distributed-simulator-impl.cc:168
ns3::DistributedSimulatorImpl::m_lookAhead
static Time m_lookAhead
Current window size.
Definition: distributed-simulator-impl.h:231
ns3::LbtsMessage::GetMyId
uint32_t GetMyId()
Definition: distributed-simulator-impl.cc:71
ns3::DistributedSimulatorImpl::NextTs
uint64_t NextTs(void) const
Get the timestep of the next event.
Definition: distributed-simulator-impl.cc:342
ns3::DistributedSimulatorImpl::Stop
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
Definition: distributed-simulator-impl.cc:454
ns3::LbtsMessage::LbtsMessage
LbtsMessage()
Definition: distributed-simulator-impl.h:46
ns3::DistributedSimulatorImpl::m_systemCount
uint32_t m_systemCount
MPI communicator size.
Definition: distributed-simulator-impl.h:229
ns3::DistributedSimulatorImpl::SetScheduler
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
Definition: distributed-simulator-impl.cc:293
ns3::DistributedSimulatorImpl::Now
virtual Time Now(void) const
Return the current simulation virtual time.
Definition: distributed-simulator-impl.cc:535
ns3::LbtsMessage::m_rxCount
uint32_t m_rxCount
Count of received messages.
Definition: distributed-simulator-impl.h:95
ns3::DistributedSimulatorImpl::Run
virtual void Run(void)
Run the simulation.
Definition: distributed-simulator-impl.cc:364
ns3::DistributedSimulatorImpl::m_events
Ptr< Scheduler > m_events
The event priority queue.
Definition: distributed-simulator-impl.h:205