A Discrete-Event Network Simulator
API
null-message-simulator-impl.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright 2013. Lawrence Livermore National Security, LLC.
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: Steven Smith <smith84@llnl.gov>
19  *
20  */
21 
22 #ifndef NULLMESSAGE_SIMULATOR_IMPL_H
23 #define NULLMESSAGE_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 #include <iostream>
32 #include <fstream>
33 
34 namespace ns3 {
35 
36 class NullMessageEvent;
37 class NullMessageMpiInterface;
38 class RemoteChannelBundle;
39 
46 {
47 public:
48  static TypeId GetTypeId (void);
49 
51 
53 
54  // virtual from SimulatorImpl
55  virtual void Destroy ();
56  virtual bool IsFinished (void) const;
57  virtual void Stop (void);
58  virtual void Stop (Time const &delay);
59  virtual EventId Schedule (Time const &delay, EventImpl *event);
60  virtual void ScheduleWithContext (uint32_t context, Time const &delay, 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 void RunOneEvent (void);
68  virtual Time Now (void) const;
69  virtual Time GetDelayLeft (const EventId &id) const;
70  virtual Time GetMaximumSimulationTime (void) const;
71  virtual void SetScheduler (ObjectFactory schedulerFactory);
72  virtual uint32_t GetSystemId (void) const;
73  virtual uint32_t GetContext (void) const;
74  virtual uint64_t GetEventCount (void) const;
75 
81  static NullMessageSimulatorImpl * GetInstance (void);
82 
83 private:
84  friend class NullMessageEvent;
87 
92 
97 
98  virtual void DoDispose (void);
99 
104  void CalculateLookAhead (void);
105 
109  void ProcessOneEvent (void);
110 
114  Time Next (void) const;
115 
119  void CalculateSafeTime (void);
120 
126  Time GetSafeTime (void);
127 
134 
142 
149  void RescheduleNullMessageEvent (uint32_t nodeSysId);
150 
160  Time CalculateGuaranteeTime (uint32_t systemId);
161 
170 
171  typedef std::list<EventId> DestroyEvents;
172 
174  bool m_stop;
176  uint32_t m_uid;
177  uint32_t m_currentUid;
178  uint64_t m_currentTs;
181  uint64_t m_eventCount;
182  // number of events that have been inserted but not yet scheduled,
183  // not counting the "destroy" events; this is used for validation
185 
186  uint32_t m_myId; // MPI Rank
187  uint32_t m_systemCount; // MPI Size
188 
189  /*
190  * The time for which it is safe for this task to execute events
191  * without danger of out-of-order events.
192  */
194 
195  /*
196  * Null Message performance tuning parameter. Controls when Null
197  * messages are sent. When value is 1 the minimum number of Null
198  * messages are sent conserving bandwidth. The delay in arrival of
199  * lookahead information is the greatest resulting in maximum
200  * unnecessary blocking of the receiver. When the value is near 0
201  * Null Messages are sent with high frequency, costing more
202  * bandwidth and Null Message processing time, but there is minimum
203  * unnecessary block of the receiver.
204  */
206 
207  /*
208  * Singleton instance.
209  */
211 };
212 
213 } // namespace ns3
214 
215 #endif /* NULLMESSAGE_SIMULATOR_IMPL_H */
Time CalculateGuaranteeTime(uint32_t systemId)
virtual void Remove(const EventId &id)
Remove an event from the event list.
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 Destroy()
Execute the events scheduled with ScheduleDestroy().
void HandleArrivingMessagesNonBlocking(void)
Non blocking receive of pending messages.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
virtual bool IsFinished(void) const
Check if the simulation should finish.
void ProcessOneEvent(void)
Process the next event on the queue.
void RescheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
Collection of NS3 channels between local and remote nodes.
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 uint32_t GetContext(void) const
Get the current simulation context.
void CalculateSafeTime(void)
Calculate the SafeTime.
static NullMessageSimulatorImpl * GetInstance(void)
Time GetSafeTime(void)
Get the current SafeTime; the maximum time that events can be processed based on information received...
virtual uint64_t GetEventCount(void) const
Get the number of events executed.
static NullMessageSimulatorImpl * g_instance
virtual void Run(void)
Run the simulation.
virtual bool IsExpired(const EventId &id) const
Check if an event has already run or been cancelled.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void CalculateLookAhead(void)
Calculate the look ahead allowable for this MPI task.
virtual void ScheduleWithContext(uint32_t context, Time const &delay, EventImpl *event)
Schedule a future event execution (in a different context).
void HandleArrivingMessagesBlocking(void)
Blocking receive of arriving messages.
virtual Time Now(void) const
Return the current simulation virtual time.
Simulator implementation using MPI and a Null Message algorithm.
Instantiate subclasses of ns3::Object.
A simulation event.
Definition: event-impl.h:44
virtual uint32_t GetSystemId(void) const
Get the system id of this simulator.
An identifier for simulation events.
Definition: event-id.h:53
virtual Time GetMaximumSimulationTime(void) const
Get the maximum representable simulation time.
virtual void Stop(void)
Tell the Simulator the calling event should be the last one executed.
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...
void ScheduleNullMessageEvent(Ptr< RemoteChannelBundle > bundle)
void NullMessageEventHandler(RemoteChannelBundle *bundle)
virtual EventId Schedule(Time const &delay, EventImpl *event)
Schedule a future event execution (in the same context).
virtual void DoDispose(void)
Destructor implementation.
a unique identifier for an interface.
Definition: type-id.h:58
virtual void SetScheduler(ObjectFactory schedulerFactory)
Set the Scheduler to be used to manage the event list.
virtual Time GetDelayLeft(const EventId &id) const
Get the remaining time until this event will execute.
The SimulatorImpl base class.
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.