ns3::Synchronizer Class Reference

Base class used for synchronizing the simulation events to some real time "wall clock.". More...

#include <synchronizer.h>

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

List of all members.

Public Member Functions

 Synchronizer ()
virtual ~Synchronizer ()
bool Realtime (void)
 Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this.
uint64_t GetCurrentRealtime (void)
 Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units.
void SetOrigin (uint64_t ts)
 Establish a correspondence between a simulation time and the synchronizer real time.
uint64_t GetOrigin (void)
 Retrieve the value of the origin of the simulation time in simulator timestep units.
int64_t GetDrift (uint64_t ts)
 Retrieve the difference between the real time clock used to synchronize the simulation and the simulation time (in simulator timestep units).
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 Sigalled.
void Signal (void)
 Tell a posible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. This will cause the thread to wake and return to the simulator proper where it can get its bearings.
void SetCondition (bool)
 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.
void EventStart (void)
 Ask the synchronizer to remember what time it is. Typically used with EventEnd to determine the real execution time of a simulation event.
uint64_t EventEnd (void)
 Ask the synchronizer to return the time step between the instant remembered during EventStart and now. Used in conjunction with EventStart to determine the real execution time of a simulation event.

Static Public Member Functions

static TypeId GetTypeId (void)
 This method returns the TypeId associated to ns3::Object.

Protected Member Functions

virtual void DoSetOrigin (uint64_t ns)=0
 Establish a correspondence between a simulation time and a wall-clock (real) time.
virtual bool DoRealtime (void)=0
 Return true if this synchronizer is actually synchronizing to a realtime clock. The simulator sometimes needs to know this.
virtual uint64_t DoGetCurrentRealtime (void)=0
 Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units.
virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay)=0
 Wait until the real time is in sync with the specified simulation time.
virtual void DoSignal (void)=0
 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)=0
 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 int64_t DoGetDrift (uint64_t ns)=0
 Declaration of method used to retrieve drift between the real time clock used to synchronize the simulation and the current simulation time.
virtual void DoEventStart (void)=0
virtual uint64_t DoEventEnd (void)=0

Protected Attributes

uint64_t m_realtimeOriginNano
uint64_t m_simOriginNano

Private Member Functions

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 time step in nanosecond units.
uint64_t NanosecondToTimeStep (uint64_t ns)
 Convert a normalized nanosecond count into a simulator time step (which can be steps of time in a user-specified unit).

Detailed Description

Base class used for synchronizing the simulation events to some real time "wall clock.".

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. We use this clock for the simulation time.

The real-time clock is maintained as a 64-bit integer count of nanoseconds.

The synchronization between the simulation clock and the real-time clock is maintained using a combination of sleep-waiting, busy-waiting and a feedback loop.

Definition at line 44 of file synchronizer.h.


Constructor & Destructor Documentation

ns3::Synchronizer::Synchronizer (  ) 

Definition at line 32 of file synchronizer.cc.

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

Definition at line 37 of file synchronizer.cc.


Member Function Documentation

virtual uint64_t ns3::Synchronizer::DoEventEnd ( void   )  [protected, pure virtual]

Implemented in ns3::WallClockSynchronizer.

Referenced by EventEnd().

virtual void ns3::Synchronizer::DoEventStart ( void   )  [protected, pure virtual]

Implemented in ns3::WallClockSynchronizer.

Referenced by EventStart().

virtual uint64_t ns3::Synchronizer::DoGetCurrentRealtime ( void   )  [protected, pure virtual]

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

Implemented in ns3::WallClockSynchronizer.

Referenced by GetCurrentRealtime().

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

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

Implemented in ns3::WallClockSynchronizer.

Referenced by GetDrift().

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

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

Implemented in ns3::WallClockSynchronizer.

Referenced by Realtime().

virtual void ns3::Synchronizer::DoSetCondition ( bool   )  [protected, pure 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

Implemented in ns3::WallClockSynchronizer.

Referenced by SetCondition().

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

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

Implemented in ns3::WallClockSynchronizer.

Referenced by SetOrigin().

virtual void ns3::Synchronizer::DoSignal ( void   )  [protected, pure 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

Implemented in ns3::WallClockSynchronizer.

Referenced by Signal().

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

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

Implemented in ns3::WallClockSynchronizer.

Referenced by Synchronize().

uint64_t ns3::Synchronizer::EventEnd ( void   ) 

Ask the synchronizer to return the time step between the instant remembered during EventStart and now. Used in conjunction with EventStart to determine the real execution time of a simulation event.

See also:
Synchronizer::EventStart
TimeStepPrecision::Get

Definition at line 105 of file synchronizer.cc.

References DoEventEnd(), and NanosecondToTimeStep().

void ns3::Synchronizer::EventStart ( void   ) 

Ask the synchronizer to remember what time it is. Typically used with EventEnd to determine the real execution time of a simulation event.

See also:
Synchronizer::EventEnd
TimeStepPrecision::Get

Definition at line 99 of file synchronizer.cc.

References DoEventStart().

uint64_t ns3::Synchronizer::GetCurrentRealtime ( void   ) 

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

Returns:
The normalized wall clock time (in simulator timestep units).
See also:
TimeStepPrecision::Get
Synchronizer::SetOrigin

Definition at line 48 of file synchronizer.cc.

References DoGetCurrentRealtime(), and NanosecondToTimeStep().

int64_t ns3::Synchronizer::GetDrift ( uint64_t  ts  ) 

Retrieve the difference between the real time clock used to synchronize the simulation and the simulation time (in simulator timestep units).

Parameters:
ts Simulation timestep from the simulator interpreted as current time in the simulator.
Returns:
Simulation timestep (in simulator timestep units) minus origin time (stored internally in nanosecond units).
See also:
TimeStepPrecision::Get
Synchronizer::SetOrigin
Synchronizer::DoGetDrift

Definition at line 67 of file synchronizer.cc.

References DoGetDrift(), NanosecondToTimeStep(), and TimeStepToNanosecond().

uint64_t ns3::Synchronizer::GetOrigin ( void   ) 

Retrieve the value of the origin of the simulation time in simulator timestep units.

Returns:
The simulation time used as the origin (in simulator timestep units).
See also:
TimeStepPrecision::Get
Synchronizer::SetOrigin

Definition at line 61 of file synchronizer.cc.

References m_simOriginNano, and NanosecondToTimeStep().

TypeId ns3::Synchronizer::GetTypeId ( void   )  [static]

This method returns the TypeId associated to ns3::Object.

No Attributes defined for this type.
No TraceSources defined for this type.

Reimplemented from ns3::Object.

Definition at line 24 of file synchronizer.cc.

References ns3::TypeId::SetParent().

uint64_t ns3::Synchronizer::NanosecondToTimeStep ( uint64_t  ns  )  [private]

Convert a normalized nanosecond count into a simulator time step (which can be steps of time in a user-specified unit).

Definition at line 134 of file synchronizer.cc.

References ns3::TimeStepPrecision::FS, ns3::TimeStepPrecision::Get(), ns3::TimeStepPrecision::MS, ns3::TimeStepPrecision::NS, NS_ASSERT_MSG, ns3::TimeStepPrecision::PS, ns3::TimeStepPrecision::S, and ns3::TimeStepPrecision::US.

Referenced by EventEnd(), GetCurrentRealtime(), GetDrift(), and GetOrigin().

bool ns3::Synchronizer::Realtime ( void   ) 

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

Returns:
True if locked with realtime, false if not.

Definition at line 42 of file synchronizer.cc.

References DoRealtime().

void ns3::Synchronizer::SetCondition ( bool  cond  ) 

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::Signal

Definition at line 93 of file synchronizer.cc.

References DoSetCondition().

void ns3::Synchronizer::SetOrigin ( uint64_t  ts  ) 

Establish a correspondence between a simulation time and the synchronizer real time.

This method is expected to be called at the "instant" before simulation begins. At this point, simulation time = 0, and a set = 0 in this method. We then associate this time with the current value of the real time clock that will be used to actually perform the synchronization.

Subclasses are expected to implement the corresponding DoSetOrigin pure virtual method to do the actual real-time-clock-specific work of making the correspondence mentioned above.

Parameters:
ts The simulation time we should use as the origin (in simulator timestep units).
See also:
TimeStepPrecision::Get
TimeStepPrecision::DoSetOrigin

Definition at line 54 of file synchronizer.cc.

References DoSetOrigin(), m_simOriginNano, and TimeStepToNanosecond().

void ns3::Synchronizer::Signal ( void   ) 

Tell a posible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. This will cause the thread to wake and return to the simulator proper where it can get its bearings.

See also:
Synchronizer::Synchronize
Synchronizer::DoSignal

Definition at line 87 of file synchronizer.cc.

References DoSignal().

bool ns3::Synchronizer::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 Sigalled.

This is where the real work of synchronization is done. The Time passed in as a parameter is the simulation time. The job of Synchronize is to translate from simulation time to synchronizer time (in a perfect world this is the same time) and then figure out how long in real-time it needs to wait until that synchronizer / simulation time comes around.

Subclasses are expected to implement the corresponding DoSynchronize pure virtual method to do the actual real-time-clock-specific work of waiting (either busy-waiting or sleeping, or some combination thereof) until the requested simulation time.

Parameters:
tsCurrent The current simulation time (in simulator timestep units).
tsDelay The simulation time we need to wait for (in simulator timestep units).
Returns:
True if the function ran to completion, false if it was interrupted by a Signal.
See also:
TimeStepPrecision::Get
Synchronizer::DoSynchronize
Synchronizer::Signal

Definition at line 80 of file synchronizer.cc.

References DoSynchronize(), and TimeStepToNanosecond().

uint64_t ns3::Synchronizer::TimeStepToNanosecond ( uint64_t  ts  )  [private]

Convert a simulator time step (which can be steps of time in a user-specified unit) to a normalized time step in nanosecond units.

Definition at line 111 of file synchronizer.cc.

References ns3::TimeStepPrecision::FS, ns3::TimeStepPrecision::Get(), ns3::TimeStepPrecision::MS, ns3::TimeStepPrecision::NS, NS_ASSERT_MSG, ns3::TimeStepPrecision::PS, ns3::TimeStepPrecision::S, and ns3::TimeStepPrecision::US.

Referenced by GetDrift(), SetOrigin(), and Synchronize().


Member Data Documentation

uint64_t ns3::Synchronizer::m_simOriginNano [protected]

Definition at line 304 of file synchronizer.h.

Referenced by GetOrigin(), and SetOrigin().


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