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 
28 #ifndef NULLMESSAGE_SIMULATOR_IMPL_H
29 #define NULLMESSAGE_SIMULATOR_IMPL_H
30 
31 #include <ns3/simulator-impl.h>
32 #include <ns3/scheduler.h>
33 #include <ns3/event-impl.h>
34 #include <ns3/ptr.h>
35 
36 #include <list>
37 #include <iostream>
38 #include <fstream>
39 
40 namespace ns3 {
41 
42 class NullMessageEvent;
43 class NullMessageMpiInterface;
44 class RemoteChannelBundle;
45 
52 {
53 public:
58  static TypeId GetTypeId (void);
59 
62 
65 
66  // virtual from SimulatorImpl
67  virtual void Destroy ();
68  virtual bool IsFinished (void) const;
69  virtual void Stop (void);
70  virtual void Stop (Time const &delay);
71  virtual EventId Schedule (Time const &delay, EventImpl *event);
72  virtual void ScheduleWithContext (uint32_t context, Time const &delay, EventImpl *event);
73  virtual EventId ScheduleNow (EventImpl *event);
74  virtual EventId ScheduleDestroy (EventImpl *event);
75  virtual void Remove (const EventId &id);
76  virtual void Cancel (const EventId &id);
77  virtual bool IsExpired (const EventId &id) const;
78  virtual void Run (void);
79 
80  virtual Time Now (void) const;
81  virtual Time GetDelayLeft (const EventId &id) const;
82  virtual Time GetMaximumSimulationTime (void) const;
83  virtual void SetScheduler (ObjectFactory schedulerFactory);
84  virtual uint32_t GetSystemId (void) const;
85  virtual uint32_t GetContext (void) const;
86  virtual uint64_t GetEventCount (void) const;
87 
93  static NullMessageSimulatorImpl * GetInstance (void);
94 
95 private:
96  friend class NullMessageEvent;
99 
104 
108  void HandleArrivingMessagesBlocking (void);
109 
110  virtual void DoDispose (void);
111 
116  void CalculateLookAhead (void);
117 
121  void ProcessOneEvent (void);
122 
126  Time Next (void) const;
127 
131  void CalculateSafeTime (void);
132 
138  Time GetSafeTime (void);
139 
146 
154 
161  void RescheduleNullMessageEvent (uint32_t nodeSysId);
162 
172  Time CalculateGuaranteeTime (uint32_t systemId);
173 
182 
184  typedef std::list<EventId> DestroyEvents;
185 
189  bool m_stop;
192 
194  uint32_t m_uid;
196  uint32_t m_currentUid;
198  uint64_t m_currentTs;
202  uint64_t m_eventCount;
208 
209  uint32_t m_myId;
210  uint32_t m_systemCount;
217 
229 
232 };
233 
234 } // namespace ns3
235 
236 #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().
uint64_t m_currentTs
Timestamp of the current event.
void HandleArrivingMessagesNonBlocking(void)
Non blocking receive of pending messages.
virtual EventId ScheduleNow(EventImpl *event)
Schedule an event to run at the current virtual time.
Ptr< Scheduler > m_events
The event priority queue.
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)
uint32_t m_currentUid
Unique id of the current event.
Collection of ns-3 channels between local and remote nodes.
Singleton for managing the RemoteChannelBundles for each process.
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)
uint32_t m_uid
Next event unique id.
DestroyEvents m_destroyEvents
The container of events to run at Destroy()
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
Singleton 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 lookahead 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.
bool m_stop
Flag calling for the end of the simulation.
Time m_safeTime
The time for which it is safe for this task to execute events without danger of out-of-order events...
std::list< EventId > DestroyEvents
Container type for the events to run at Simulator::Destroy().
NullMessageSimulatorImpl()
Default constructor.
int m_unscheduledEvents
Number of events that have been inserted but not yet scheduled, not counting the "destroy" events; th...
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.
uint32_t m_currentContext
Execution context of the current event.
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.
double m_schedulerTune
Null Message performance tuning parameter.
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.
static TypeId GetTypeId(void)
Register this type.
The SimulatorImpl base class.
uint32_t m_systemCount
MPI communicator size.
Interface between ns-3 and MPI for the Null Message distributed simulation implementation.