A Discrete-Event Network Simulator
API
wall-clock-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 WALL_CLOCK_CLOCK_SYNCHRONIZER_H
20 #define WALL_CLOCK_CLOCK_SYNCHRONIZER_H
21 
22 #include "system-condition.h"
23 #include "synchronizer.h"
24 
31 namespace ns3 {
32 
71 {
72 public:
77  static TypeId GetTypeId (void);
78 
82  virtual ~WallClockSynchronizer ();
83 
85  static const uint64_t US_PER_NS = (uint64_t)1000;
87  static const uint64_t US_PER_SEC = (uint64_t)1000000;
89  static const uint64_t NS_PER_SEC = (uint64_t)1000000000;
90 
91 protected:
104  bool SpinWait (uint64_t ns);
128  bool SleepWait (uint64_t ns);
129 
130  // Inherited from Synchronizer
131  virtual void DoSetOrigin (uint64_t ns);
132  virtual bool DoRealtime (void);
133  virtual uint64_t DoGetCurrentRealtime (void);
134  virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay);
135  virtual void DoSignal (void);
136  virtual void DoSetCondition (bool cond);
137  virtual int64_t DoGetDrift (uint64_t ns);
138  virtual void DoEventStart (void);
139  virtual uint64_t DoEventEnd (void);
140 
150  uint64_t DriftCorrect (uint64_t nsNow, uint64_t nsDelay);
151 
157  uint64_t GetRealtime (void);
163  uint64_t GetNormalizedRealtime (void);
164 
171  void NsToTimeval (int64_t ns, struct timeval *tv);
178  uint64_t TimevalToNs (struct timeval *tv);
179 
187  void TimevalAdd (
188  struct timeval *tv1,
189  struct timeval *tv2,
190  struct timeval *result);
191 
193  uint64_t m_jiffy;
195  uint64_t m_nsEventStart;
196 
199 };
200 
201 } // namespace ns3
202 
203 #endif /* WALL_CLOCK_SYNCHRONIZER_H */
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
ns3::WallClockSynchronizer::DoSetOrigin
virtual void DoSetOrigin(uint64_t ns)
Establish a correspondence between a simulation time and a wall-clock (real) time.
Definition: wall-clock-synchronizer.cc:111
ns3::WallClockSynchronizer::DoSynchronize
virtual bool DoSynchronize(uint64_t nsCurrent, uint64_t nsDelay)
Wait until the real time is in sync with the specified simulation time.
Definition: wall-clock-synchronizer.cc:167
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
synchronizer.h
ns3::Synchronizer declaration.
ns3::WallClockSynchronizer::DriftCorrect
uint64_t DriftCorrect(uint64_t nsNow, uint64_t nsDelay)
Compute a correction to the nominal delay to account for realtime drift since the last DoSynchronize.
Definition: wall-clock-synchronizer.cc:343
ns3::WallClockSynchronizer::GetNormalizedRealtime
uint64_t GetNormalizedRealtime(void)
Get the current normalized real time, in ns.
Definition: wall-clock-synchronizer.cc:383
ns3::Synchronizer
Base class used for synchronizing the simulation events to some real time "wall clock....
Definition: synchronizer.h:52
ns3::WallClockSynchronizer::m_jiffy
uint64_t m_jiffy
Size of the system clock tick, as reported by clock_getres, in ns.
Definition: wall-clock-synchronizer.h:193
ns3::WallClockSynchronizer::GetTypeId
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
Definition: wall-clock-synchronizer.cc:42
ns3::WallClockSynchronizer::US_PER_SEC
static const uint64_t US_PER_SEC
Conversion constant between μs and seconds.
Definition: wall-clock-synchronizer.h:87
ns3::SystemCondition
A class which provides a relatively platform-independent conditional-wait thread synchronization prim...
Definition: system-condition.h:71
ns3::WallClockSynchronizer::SpinWait
bool SpinWait(uint64_t ns)
Do a busy-wait until the normalized realtime equals the argument or the condition variable becomes tr...
Definition: wall-clock-synchronizer.cc:315
ns3::WallClockSynchronizer::NS_PER_SEC
static const uint64_t NS_PER_SEC
Conversion constant between ns and s.
Definition: wall-clock-synchronizer.h:89
ns3::WallClockSynchronizer::GetRealtime
uint64_t GetRealtime(void)
Get the current absolute real time (in ns since the epoch).
Definition: wall-clock-synchronizer.cc:374
ns3::WallClockSynchronizer::DoEventStart
virtual void DoEventStart(void)
Record the normalized real time at which the current event is starting execution.
Definition: wall-clock-synchronizer.cc:301
ns3::WallClockSynchronizer::DoSetCondition
virtual void DoSetCondition(bool cond)
Set the condition variable to tell a possible simulator thread waiting in the Synchronize method that...
Definition: wall-clock-synchronizer.cc:294
ns3::WallClockSynchronizer::TimevalToNs
uint64_t TimevalToNs(struct timeval *tv)
Convert a timeval to absolute time, in ns.
Definition: wall-clock-synchronizer.cc:399
ns3::WallClockSynchronizer::WallClockSynchronizer
WallClockSynchronizer()
Constructor.
Definition: wall-clock-synchronizer.cc:51
ns3::WallClockSynchronizer::DoRealtime
virtual bool DoRealtime(void)
Return true if this synchronizer is actually synchronizing to a realtime clock.
Definition: wall-clock-synchronizer.cc:97
ns3::WallClockSynchronizer::DoGetDrift
virtual int64_t DoGetDrift(uint64_t ns)
Get the drift between the real time clock used to synchronize the simulation and the current simulati...
Definition: wall-clock-synchronizer.cc:127
ns3::WallClockSynchronizer::SleepWait
bool SleepWait(uint64_t ns)
Put our process to sleep for some number of nanoseconds.
Definition: wall-clock-synchronizer.cc:336
system-condition.h
ns3::SystemCondition declaration.
ns3::WallClockSynchronizer::DoGetCurrentRealtime
virtual uint64_t DoGetCurrentRealtime(void)
Retrieve the value of the origin of the underlying normalized wall clock time in Time resolution unit...
Definition: wall-clock-synchronizer.cc:104
ns3::WallClockSynchronizer::DoSignal
virtual void DoSignal(void)
Tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which...
Definition: wall-clock-synchronizer.cc:285
ns3::WallClockSynchronizer::~WallClockSynchronizer
virtual ~WallClockSynchronizer()
Destructor.
Definition: wall-clock-synchronizer.cc:91
ns3::WallClockSynchronizer
Class used for synchronizing the simulation events to a real-time "wall clock" using Posix clock func...
Definition: wall-clock-synchronizer.h:71
ns3::WallClockSynchronizer::m_nsEventStart
uint64_t m_nsEventStart
Time recorded by DoEventStart.
Definition: wall-clock-synchronizer.h:195
ns3::WallClockSynchronizer::TimevalAdd
void TimevalAdd(struct timeval *tv1, struct timeval *tv2, struct timeval *result)
Add two timeval.
Definition: wall-clock-synchronizer.cc:408
ns3::WallClockSynchronizer::NsToTimeval
void NsToTimeval(int64_t ns, struct timeval *tv)
Convert an absolute time in ns to a timeval.
Definition: wall-clock-synchronizer.cc:390
ns3::WallClockSynchronizer::US_PER_NS
static const uint64_t US_PER_NS
Conversion constant between μs and ns.
Definition: wall-clock-synchronizer.h:85
ns3::WallClockSynchronizer::m_condition
SystemCondition m_condition
Thread synchronizer.
Definition: wall-clock-synchronizer.h:198
ns3::WallClockSynchronizer::DoEventEnd
virtual uint64_t DoEventEnd(void)
Return the amount of real time elapsed since the last call to EventStart.
Definition: wall-clock-synchronizer.cc:308