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 
80  static NullMessageSimulatorImpl * GetInstance (void);
81 
82 private:
83  friend class NullMessageEvent;
86 
91 
96 
97  virtual void DoDispose (void);
98 
103  void CalculateLookAhead (void);
104 
108  void ProcessOneEvent (void);
109 
113  Time Next (void) const;
114 
118  void CalculateSafeTime (void);
119 
125  Time GetSafeTime (void);
126 
133 
141 
148  void RescheduleNullMessageEvent (uint32_t nodeSysId);
149 
159  Time CalculateGuaranteeTime (uint32_t systemId);
160 
169 
170  typedef std::list<EventId> DestroyEvents;
171 
173  bool m_stop;
175  uint32_t m_uid;
176  uint32_t m_currentUid;
177  uint64_t m_currentTs;
179  // number of events that have been inserted but not yet scheduled,
180  // not counting the "destroy" events; this is used for validation
182 
183  uint32_t m_myId; // MPI Rank
184  uint32_t m_systemCount; // MPI Size
185 
186  /*
187  * The time for which it is safe for this task to execute events
188  * without danger of out-of-order events.
189  */
191 
192  /*
193  * Null Message performance tuning parameter. Controls when Null
194  * messages are sent. When value is 1 the minimum number of Null
195  * messages are sent conserving bandwidth. The delay in arrival of
196  * lookahead information is the greatest resulting in maximum
197  * unnecessary blocking of the receiver. When the value is near 0
198  * Null Messages are sent with high frequency, costing more
199  * bandwidth and Null Message processing time, but there is minimum
200  * unnecessary block of the receiver.
201  */
203 
204  /*
205  * Singleton instance.
206  */
208 };
209 
210 } // namespace ns3
211 
212 #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:102
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...
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.