A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  * Some updates to this code were developed under a research contract
19  * sponsored by the Army Research Laboratory. (April 30, 2013)
20  */
21 
22 #ifndef DISTRIBUTED_SIMULATOR_IMPL_H
23 #define DISTRIBUTED_SIMULATOR_IMPL_H
24 
25 #include "ns3/simulator-impl.h"
26 #include "ns3/scheduler.h"
27 #include "ns3/event-impl.h"
28 #include "ns3/ptr.h"
29 
30 #include <list>
31 
32 namespace ns3 {
33 
40 {
41 public:
43  : m_txCount (0),
44  m_rxCount (0),
45  m_myId (0),
46  m_isFinished (false)
47  {
48  }
49 
56  LbtsMessage (uint32_t rxc, uint32_t txc, uint32_t id, bool isFinished, const Time& t)
57  : m_txCount (txc),
58  m_rxCount (rxc),
59  m_myId (id),
60  m_smallestTime (t),
61  m_isFinished (isFinished)
62  {
63  }
64 
65  ~LbtsMessage ();
66 
74  uint32_t GetTxCount ();
78  uint32_t GetRxCount ();
82  uint32_t GetMyId ();
83 
84  bool IsFinished ();
85 
86 private:
87  uint32_t m_txCount;
88  uint32_t m_rxCount;
89  uint32_t m_myId;
92 };
93 
101 {
102 public:
103  static TypeId GetTypeId (void);
104 
107 
108  // virtual from SimulatorImpl
109  virtual void Destroy ();
110  virtual bool IsFinished (void) const;
111  virtual void Stop (void);
112  virtual void Stop (Time const &time);
113  virtual EventId Schedule (Time const &time, EventImpl *event);
114  virtual void ScheduleWithContext (uint32_t context, Time const &time, EventImpl *event);
115  virtual EventId ScheduleNow (EventImpl *event);
116  virtual EventId ScheduleDestroy (EventImpl *event);
117  virtual void Remove (const EventId &ev);
118  virtual void Cancel (const EventId &ev);
119  virtual bool IsExpired (const EventId &ev) const;
120  virtual void Run (void);
121  virtual Time Now (void) const;
122  virtual Time GetDelayLeft (const EventId &id) const;
123  virtual Time GetMaximumSimulationTime (void) const;
124  virtual void SetScheduler (ObjectFactory schedulerFactory);
125  virtual uint32_t GetSystemId (void) const;
126  virtual uint32_t GetContext (void) const;
127 
128 private:
129  virtual void DoDispose (void);
130  void CalculateLookAhead (void);
131  bool IsLocalFinished (void) const;
132 
133  void ProcessOneEvent (void);
134  uint64_t NextTs (void) const;
135  Time Next (void) const;
136  typedef std::list<EventId> DestroyEvents;
137 
139  bool m_stop;
140  bool m_globalFinished; // Are all parallel instances completed.
142  uint32_t m_uid;
143  uint32_t m_currentUid;
144  uint64_t m_currentTs;
146  // number of events that have been inserted but not yet scheduled,
147  // not counting the "destroy" events; this is used for validation
149 
150  LbtsMessage* m_pLBTS; // Allocated once we know how many systems
151  uint32_t m_myId; // MPI Rank
152  uint32_t m_systemCount; // MPI Size
153  Time m_grantedTime; // Last LBTS
154  static Time m_lookAhead; // Lookahead value
155 
156 };
157 
158 } // namespace ns3
159 
160 #endif /* DISTRIBUTED_SIMULATOR_IMPL_H */