A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
26 namespace ns3 {
27 
44 class Synchronizer : public Object
45 {
46 public:
47  static TypeId GetTypeId (void);
48 
49  Synchronizer ();
50  virtual ~Synchronizer ();
51 
57  bool Realtime (void);
58 
67  uint64_t GetCurrentRealtime (void);
68 
88  void SetOrigin (uint64_t ts);
89 
99  uint64_t GetOrigin (void);
100 
114  int64_t GetDrift (uint64_t ts);
115 
140  bool Synchronize (uint64_t tsCurrent, uint64_t tsDelay);
141 
151  void Signal (void);
152 
160  void SetCondition (bool);
161 
169  void EventStart (void);
170 
179  uint64_t EventEnd (void);
180 
181 protected:
209  virtual void DoSetOrigin (uint64_t ns) = 0;
210 
222  virtual bool DoRealtime (void) = 0;
223 
237  virtual uint64_t DoGetCurrentRealtime (void) = 0;
238 
265  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay) = 0;
266 
274  virtual void DoSignal (void) = 0;
275 
283  virtual void DoSetCondition (bool) = 0;
284 
298  virtual int64_t DoGetDrift (uint64_t ns) = 0;
299 
300  virtual void DoEventStart (void) = 0;
301  virtual uint64_t DoEventEnd (void) = 0;
302 
304  uint64_t m_simOriginNano;
305 
306 private:
317  uint64_t TimeStepToNanosecond (uint64_t ts);
318 
329  uint64_t NanosecondToTimeStep (uint64_t ns);
330 };
331 
332 } // namespace ns3
333 
334 #endif /* SYNCHRONIZER_H */
virtual int64_t DoGetDrift(uint64_t ns)=0
Declaration of method used to retrieve drift between the real time clock used to synchronize the simu...
virtual void DoSetCondition(bool)=0
Declaration of the method used to set the condition variable that tells a possible simulator thread w...
uint64_t NanosecondToTimeStep(uint64_t ns)
Convert a normalized nanosecond count into a simulator time step (which can be steps of time in a use...
uint64_t GetCurrentRealtime(void)
Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep u...
Definition: synchronizer.cc:57
void SetCondition(bool)
Set the condition variable that tells a possible simulator thread waiting in the Synchronize method t...
void EventStart(void)
Ask the synchronizer to remember what time it is.
uint64_t EventEnd(void)
Ask the synchronizer to return the time step between the instant remembered during EventStart and now...
virtual void DoSetOrigin(uint64_t ns)=0
Establish a correspondence between a simulation time and a wall-clock (real) time.
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...
Definition: synchronizer.cc:93
bool Realtime(void)
Return true if this synchronizer is actually synchronizing to a realtime clock.
Definition: synchronizer.cc:50
uint64_t GetOrigin(void)
Retrieve the value of the origin of the simulation time in simulator timestep units.
Definition: synchronizer.cc:72
Base class used for synchronizing the simulation events to some real time "wall clock.".
Definition: synchronizer.h:44
virtual uint64_t DoGetCurrentRealtime(void)=0
Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep u...
uint64_t m_realtimeOriginNano
Definition: synchronizer.h:303
virtual void DoEventStart(void)=0
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:79
virtual void DoSignal(void)=0
Declaration of the method used to tell a possible simulator thread waiting in the DoSynchronize metho...
uint64_t m_simOriginNano
Definition: synchronizer.h:304
static TypeId GetTypeId(void)
Definition: synchronizer.cc:30
void SetOrigin(uint64_t ts)
Establish a correspondence between a simulation time and the synchronizer real time.
Definition: synchronizer.cc:64
void Signal(void)
Tell a possible simulator thread waiting in the Synchronize method that an event has happened which d...
uint64_t TimeStepToNanosecond(uint64_t ts)
Convert a simulator time step (which can be steps of time in a user-specified unit) to a normalized t...
a base class which provides memory management and object aggregation
Definition: object.h:63
virtual uint64_t DoEventEnd(void)=0
a unique identifier for an interface.
Definition: type-id.h:49
virtual ~Synchronizer()
Definition: synchronizer.cc:44
virtual bool DoRealtime(void)=0
Return true if this synchronizer is actually synchronizing to a realtime clock.
virtual bool DoSynchronize(uint64_t nsCurrent, uint64_t nsDelay)=0
Wait until the real time is in sync with the specified simulation time.