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 
20 #ifndef NS3_DISTRIBUTED_SIMULATOR_IMPL_H
21 #define NS3_DISTRIBUTED_SIMULATOR_IMPL_H
22 
23 #include "ns3/simulator-impl.h"
24 #include "ns3/scheduler.h"
25 #include "ns3/event-impl.h"
26 #include "ns3/ptr.h"
27 
28 #include <list>
29 
30 namespace ns3 {
31 
38 {
39 public:
41  : m_txCount (0),
42  m_rxCount (0),
43  m_myId (0),
44  m_isFinished (false)
45  {
46  }
47 
55  LbtsMessage (uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time& t)
56  : m_txCount (txc),
57  m_rxCount (rxc),
58  m_myId (id),
59  m_smallestTime (t),
60  m_isFinished (isFinished)
61  {
62  }
63 
64  ~LbtsMessage ();
65 
73  uint32_t GetTxCount ();
77  uint32_t GetRxCount ();
81  uint32_t GetMyId ();
85  bool IsFinished ();
86 
87 private:
88  uint32_t m_txCount;
89  uint32_t m_rxCount;
90  uint32_t m_myId;
93 };
94 
102 {
103 public:
104  static TypeId GetTypeId (void);
105 
108 
109  // virtual from SimulatorImpl
110  virtual void Destroy ();
111  virtual bool IsFinished (void) const;
112  virtual void Stop (void);
113  virtual void Stop (Time const &delay);
114  virtual EventId Schedule (Time const &delay, EventImpl *event);
115  virtual void ScheduleWithContext (uint32_t context, Time const &delay, EventImpl *event);
116  virtual EventId ScheduleNow (EventImpl *event);
117  virtual EventId ScheduleDestroy (EventImpl *event);
118  virtual void Remove (const EventId &id);
119  virtual void Cancel (const EventId &id);
120  virtual bool IsExpired (const EventId &id) const;
121  virtual void Run (void);
122  virtual Time Now (void) const;
123  virtual Time GetDelayLeft (const EventId &id) const;
124  virtual Time GetMaximumSimulationTime (void) const;
125  virtual void SetMaximumLookAhead (const Time lookAhead);
126  virtual void SetScheduler (ObjectFactory schedulerFactory);
127  virtual uint32_t GetSystemId (void) const;
128  virtual uint32_t GetContext (void) const;
129  virtual uint64_t GetEventCount (void) const;
130 
131 private:
132  virtual void DoDispose (void);
133  void CalculateLookAhead (void);
134  bool IsLocalFinished (void) const;
135 
136  void ProcessOneEvent (void);
137  uint64_t NextTs (void) const;
138  Time Next (void) const;
139  typedef std::list<EventId> DestroyEvents;
140 
142  bool m_stop;
143  bool m_globalFinished; // Are all parallel instances completed.
145  uint32_t m_uid;
146  uint32_t m_currentUid;
147  uint64_t m_currentTs;
150  uint64_t m_eventCount;
151  // number of events that have been inserted but not yet scheduled,
152  // not counting the "destroy" events; this is used for validation
154 
155  LbtsMessage* m_pLBTS; // Allocated once we know how many systems
156  uint32_t m_myId; // MPI Rank
157  uint32_t m_systemCount; // MPI Size
158  Time m_grantedTime; // Last LBTS
159  static Time m_lookAhead; // Lookahead value
160 
161 };
162 
163 } // namespace ns3
164 
165 #endif /* NS3_DISTRIBUTED_SIMULATOR_IMPL_H */
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
virtual uint32_t GetContext(void) const
Get the current simulation context.
virtual EventId Schedule(Time const &delay, EventImpl *event)
Schedule a future event execution (in the same context).
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 SetMaximumLookAhead(const Time lookAhead)
uint64_t m_eventCount
The event count.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
virtual void DoDispose(void)
Destructor implementation.
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
virtual bool IsFinished(void) const
Check if the simulation should finish.
virtual void Cancel(const EventId &id)
Set the cancel bit on this event: the event&#39;s associated function will not be invoked when it expires...
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
Distributed simulator implementation using lookahead.
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.
virtual void Destroy()
Execute the events scheduled with ScheduleDestroy().
Structure used for all-reduce LBTS computation.
virtual void Remove(const EventId &id)
Remove an event from 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
LbtsMessage(uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time &t)
virtual void ScheduleWithContext(uint32_t context, Time const &delay, EventImpl *event)
Schedule a future event execution (in a different context).
virtual Time Now(void) const
Return the current simulation virtual time.
virtual void Run(void)
Run the simulation.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
a unique identifier for an interface.
Definition: type-id.h:58
The SimulatorImpl base class.