ns3::WallClockSynchronizer Class Reference

Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock functions. More...

#include <wall-clock-synchronizer.h>

Inheritance diagram for ns3::WallClockSynchronizer:
Inheritance graph
[legend]
Collaboration diagram for ns3::WallClockSynchronizer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 WallClockSynchronizer ()
virtual ~WallClockSynchronizer ()

Static Public Attributes

static const uint64_t US_PER_NS = (uint64_t)1000
static const uint64_t US_PER_SEC = (uint64_t)1000000
static const uint64_t NS_PER_SEC = (uint64_t)1000000000

Protected Member Functions

virtual bool DoRealtime (void)
 Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this.
virtual uint64_t DoGetCurrentRealtime (void)
 Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units.
virtual void DoSetOrigin (uint64_t ns)
 Establish a correspondence between a simulation time and a wall-clock (real) time.
virtual int64_t DoGetDrift (uint64_t ns)
 Declaration of method used to retrieve drift between the real time clock used to synchronize the simulation and the current simulation time.
virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay)
 Wait until the real time is in sync with the specified simulation time.
virtual void DoSignal (void)
 Declaration of the method used to tell a posible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time.
virtual void DoSetCondition (bool cond)
 Declaration of the method used to set the condition variable that tells a posible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time.
virtual void DoEventStart (void)
virtual uint64_t DoEventEnd (void)
bool SpinWait (uint64_t)
bool SleepWait (uint64_t)
uint64_t DriftCorrect (uint64_t nsNow, uint64_t nsDelay)
uint64_t GetRealtime (void)
uint64_t GetNormalizedRealtime (void)
void NsToTimeval (int64_t ns, struct timeval *tv)
uint64_t TimevalToNs (struct timeval *tv)
void TimevalAdd (struct timeval *tv1, struct timeval *tv2, struct timeval *result)

Protected Attributes

uint64_t m_cpuTick
uint64_t m_realtimeTick
uint64_t m_jiffy
uint64_t m_nsEventStart
SystemCondition m_condition

Detailed Description

Class used for synchronizing the simulation events to a real-time "wall clock" using Posix Clock functions.

Enable this synchronizer using:

DefaultValue::Bind ("Synchronizer", "WallClockSynchronizer");

before calling any simulator functions.

The simulation clock is maintained as a 64-bit integer in a unit specified by the user through the TimeStepPrecision::Set function. This means that it is not possible to specify event expiration times with anything better than this user-specified accuracy.

There are a couple of more issues at this level. Posix clocks provide access to several clocks we could use as a wall clock. We don't care about time in the sense of 0430 CEST, we care about some piece of hardware that ticks at some regular period. The most accurate posix clock in this respect is the CLOCK_PROCESS_CPUTIME_ID clock. This is a high-resolution register in the CPU. For example, on Intel machines this corresponds to the timestamp counter (TSC) register. The resolution of this counter will be on the order of nanoseconds.

Now, just because we can measure time in nanoseconds doesn't mean we can put our process to sleep to nanosecond resolution. We are eventualy going to use the function clock_nanosleep () to sleep until a simulation Time specified by the caller.

MORE ON JIFFIES, SLEEP, PROCESSES, etc., as required

Nanosleep takes a struct timespec as an input so we have to deal with conversion between Time and struct timespec here. They are both interpreted as elapsed times.

Definition at line 62 of file wall-clock-synchronizer.h.


Constructor & Destructor Documentation

ns3::WallClockSynchronizer::WallClockSynchronizer (  ) 

Definition at line 31 of file wall-clock-synchronizer.cc.

References m_jiffy, NS_LOG_FUNCTION_NOARGS, NS_LOG_INFO, and NS_PER_SEC.

ns3::WallClockSynchronizer::~WallClockSynchronizer (  )  [virtual]

Definition at line 71 of file wall-clock-synchronizer.cc.

References NS_LOG_FUNCTION_NOARGS.


Member Function Documentation

uint64_t ns3::WallClockSynchronizer::DoEventEnd ( void   )  [protected, virtual]
void ns3::WallClockSynchronizer::DoEventStart ( void   )  [protected, virtual]
uint64_t ns3::WallClockSynchronizer::DoGetCurrentRealtime ( void   )  [protected, virtual]

Retrieve the value of the origin of the underlying normalized wall clock time in nanosecond units.

Implements ns3::Synchronizer.

Definition at line 84 of file wall-clock-synchronizer.cc.

References GetNormalizedRealtime(), and NS_LOG_FUNCTION_NOARGS.

int64_t ns3::WallClockSynchronizer::DoGetDrift ( uint64_t  ns  )  [protected, virtual]

Declaration of method used to retrieve drift between the real time clock used to synchronize the simulation and the current simulation time.

Implements ns3::Synchronizer.

Definition at line 107 of file wall-clock-synchronizer.cc.

References GetNormalizedRealtime(), and NS_LOG_FUNCTION_NOARGS.

Referenced by DoSynchronize(), and DriftCorrect().

bool ns3::WallClockSynchronizer::DoRealtime ( void   )  [protected, virtual]

Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this.

Implements ns3::Synchronizer.

Definition at line 77 of file wall-clock-synchronizer.cc.

References NS_LOG_FUNCTION_NOARGS.

void ns3::WallClockSynchronizer::DoSetCondition ( bool   )  [protected, virtual]

Declaration of the method used to set the condition variable that tells a posible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time.

See also:
Synchronizer::SetCondition

Implements ns3::Synchronizer.

Definition at line 274 of file wall-clock-synchronizer.cc.

References m_condition, NS_LOG_FUNCTION_NOARGS, and ns3::SystemCondition::SetCondition().

void ns3::WallClockSynchronizer::DoSetOrigin ( uint64_t  ns  )  [protected, virtual]

Establish a correspondence between a simulation time and a wall-clock (real) time.

Implements ns3::Synchronizer.

Definition at line 91 of file wall-clock-synchronizer.cc.

References GetRealtime(), ns3::Synchronizer::m_realtimeOriginNano, NS_LOG_FUNCTION_NOARGS, and NS_LOG_INFO.

void ns3::WallClockSynchronizer::DoSignal ( void   )  [protected, virtual]

Declaration of the method used to tell a posible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time.

See also:
Synchronizer::Signal

Implements ns3::Synchronizer.

Definition at line 265 of file wall-clock-synchronizer.cc.

References m_condition, NS_LOG_FUNCTION_NOARGS, ns3::SystemCondition::SetCondition(), and ns3::SystemCondition::Signal().

bool ns3::WallClockSynchronizer::DoSynchronize ( uint64_t  nsCurrent,
uint64_t  nsDelay 
) [protected, virtual]

Wait until the real time is in sync with the specified simulation time.

Implements ns3::Synchronizer.

Definition at line 147 of file wall-clock-synchronizer.cc.

References DoGetDrift(), DriftCorrect(), m_jiffy, NS_LOG_FUNCTION_NOARGS, NS_LOG_INFO, SleepWait(), and SpinWait().

uint64_t ns3::WallClockSynchronizer::DriftCorrect ( uint64_t  nsNow,
uint64_t  nsDelay 
) [protected]

Definition at line 349 of file wall-clock-synchronizer.cc.

References DoGetDrift().

Referenced by DoSynchronize().

uint64_t ns3::WallClockSynchronizer::GetNormalizedRealtime ( void   )  [protected]
uint64_t ns3::WallClockSynchronizer::GetRealtime ( void   )  [protected]

Definition at line 379 of file wall-clock-synchronizer.cc.

References TimevalToNs().

Referenced by DoSetOrigin(), and GetNormalizedRealtime().

void ns3::WallClockSynchronizer::NsToTimeval ( int64_t  ns,
struct timeval *  tv 
) [protected]

Definition at line 393 of file wall-clock-synchronizer.cc.

References NS_ASSERT, NS_PER_SEC, and US_PER_NS.

bool ns3::WallClockSynchronizer::SleepWait ( uint64_t  ns  )  [protected]
bool ns3::WallClockSynchronizer::SpinWait ( uint64_t  ns  )  [protected]
void ns3::WallClockSynchronizer::TimevalAdd ( struct timeval *  tv1,
struct timeval *  tv2,
struct timeval *  result 
) [protected]

Definition at line 409 of file wall-clock-synchronizer.cc.

References US_PER_SEC.

uint64_t ns3::WallClockSynchronizer::TimevalToNs ( struct timeval *  tv  )  [protected]

Definition at line 401 of file wall-clock-synchronizer.cc.

References NS_ASSERT, NS_PER_SEC, and US_PER_NS.

Referenced by GetRealtime().


Member Data Documentation

Definition at line 191 of file wall-clock-synchronizer.h.

Referenced by DoSetCondition(), DoSignal(), SleepWait(), and SpinWait().

Definition at line 186 of file wall-clock-synchronizer.h.

Definition at line 188 of file wall-clock-synchronizer.h.

Referenced by DoSynchronize(), and WallClockSynchronizer().

Definition at line 189 of file wall-clock-synchronizer.h.

Referenced by DoEventEnd(), and DoEventStart().

Definition at line 187 of file wall-clock-synchronizer.h.

const uint64_t ns3::WallClockSynchronizer::NS_PER_SEC = (uint64_t)1000000000 [static]

Definition at line 70 of file wall-clock-synchronizer.h.

Referenced by NsToTimeval(), TimevalToNs(), and WallClockSynchronizer().

const uint64_t ns3::WallClockSynchronizer::US_PER_NS = (uint64_t)1000 [static]

Definition at line 68 of file wall-clock-synchronizer.h.

Referenced by NsToTimeval(), and TimevalToNs().

const uint64_t ns3::WallClockSynchronizer::US_PER_SEC = (uint64_t)1000000 [static]

Definition at line 69 of file wall-clock-synchronizer.h.

Referenced by TimevalAdd().


The documentation for this class was generated from the following files:
Generated on Thu Dec 3 14:12:19 2009 for NS-3 by  doxygen 1.6.3