A Discrete-Event Network Simulator
API
synchronizer.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 University of Washington
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 
19 #ifndef SYNCHRONIZER_H
20 #define SYNCHRONIZER_H
21 
22 #include <stdint.h>
23 #include "nstime.h"
24 #include "object.h"
25 
32 namespace ns3 {
33 
51 class Synchronizer : public Object
52 {
53 public:
58  static TypeId GetTypeId (void);
59 
61  Synchronizer ();
63  virtual ~Synchronizer ();
64 
73  bool Realtime (void);
74 
82  uint64_t GetCurrentRealtime (void);
83 
102  void SetOrigin (uint64_t ts);
103 
111  uint64_t GetOrigin (void);
112 
124  int64_t GetDrift (uint64_t ts);
125 
149  bool Synchronize (uint64_t tsCurrent, uint64_t tsDelay);
150 
161  void Signal (void);
162 
172  void SetCondition (bool cond);
173 
182  void EventStart (void);
183 
194  uint64_t EventEnd (void);
195 
196 protected:
221  virtual void DoSetOrigin (uint64_t ns) = 0;
222 
234  virtual bool DoRealtime (void) = 0;
235 
246  virtual uint64_t DoGetCurrentRealtime (void) = 0;
247 
271  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay) = 0;
272 
280  virtual void DoSignal (void) = 0;
281 
290  virtual void DoSetCondition (bool cond) = 0;
291 
301  virtual int64_t DoGetDrift (uint64_t ns) = 0;
302 
307  virtual void DoEventStart (void) = 0;
314  virtual uint64_t DoEventEnd (void) = 0;
315 
319  uint64_t m_simOriginNano;
320 
321 private:
329  uint64_t TimeStepToNanosecond (uint64_t ts);
330 
338  uint64_t NanosecondToTimeStep (uint64_t ns);
339 };
340 
341 } // namespace ns3
342 
343 #endif /* SYNCHRONIZER_H */
A base class which provides memory management and object aggregation.
Definition: object.h:88
Base class used for synchronizing the simulation events to some real time "wall clock....
Definition: synchronizer.h:52
bool Realtime(void)
Return true if this synchronizer is actually synchronizing to a realtime clock.
Definition: synchronizer.cc:57
uint64_t EventEnd(void)
Ask the synchronizer to return the time step between the instant remembered during EventStart and now...
void SetOrigin(uint64_t ts)
Establish a correspondence between a simulation time and the synchronizer real time.
Definition: synchronizer.cc:71
virtual uint64_t DoEventEnd(void)=0
Return the amount of real time elapsed since the last call to EventStart.
void EventStart(void)
Ask the synchronizer to remember what time it is.
virtual void DoSetCondition(bool cond)=0
Set the condition variable to tell a possible simulator thread waiting in the Synchronize method that...
virtual bool DoRealtime(void)=0
Return true if this synchronizer is actually synchronizing to a realtime clock.
uint64_t GetOrigin(void)
Retrieve the value of the origin of the simulation time in Time.resolution units.
Definition: synchronizer.cc:79
virtual bool DoSynchronize(uint64_t nsCurrent, uint64_t nsDelay)=0
Wait until the real time is in sync with the specified simulation time.
uint64_t TimeStepToNanosecond(uint64_t ts)
Convert a simulator time step (in Time resolution units) to a normalized time step in nanosecond unit...
uint64_t m_realtimeOriginNano
The real time, in ns, when SetOrigin was called.
Definition: synchronizer.h:317
uint64_t NanosecondToTimeStep(uint64_t ns)
Convert a normalized nanosecond time step into a simulator time step (in Time resolution units).
uint64_t GetCurrentRealtime(void)
Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep u...
Definition: synchronizer.cc:64
virtual int64_t DoGetDrift(uint64_t ns)=0
Get the drift between the real time clock used to synchronize the simulation and the current simulati...
void Signal(void)
Tell a possible simulator thread waiting in the Synchronize method that an event has happened which d...
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
Definition: synchronizer.cc:35
int64_t GetDrift(uint64_t ts)
Retrieve the difference between the real time clock used to synchronize the simulation and the simula...
Definition: synchronizer.cc:86
virtual uint64_t DoGetCurrentRealtime(void)=0
Retrieve the value of the origin of the underlying normalized wall clock time in Time resolution unit...
virtual void DoSignal(void)=0
Tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which...
uint64_t m_simOriginNano
The simulation time, in ns, when SetOrigin was called.
Definition: synchronizer.h:319
bool Synchronize(uint64_t tsCurrent, uint64_t tsDelay)
Wait until the real time is in sync with the specified simulation time or until the synchronizer is S...
void SetCondition(bool cond)
Set the condition variable that tells a possible simulator thread waiting in the Synchronize method t...
virtual void DoSetOrigin(uint64_t ns)=0
Establish a correspondence between a simulation time and a wall-clock (real) time.
virtual void DoEventStart(void)=0
Record the normalized real time at which the current event is starting execution.
Synchronizer()
Constructor.
Definition: synchronizer.cc:44
virtual ~Synchronizer()
Destructor.
Definition: synchronizer.cc:51
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Declaration of classes ns3::Time and ns3::TimeWithUnit, and the TimeValue implementation classes.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.