A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::Synchronizer Class Referenceabstract

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

#include <synchronizer.h>

+ Inheritance diagram for ns3::Synchronizer:
+ Collaboration diagram for ns3::Synchronizer:

Public Member Functions

 Synchronizer ()
 
virtual ~Synchronizer ()
 
uint64_t EventEnd (void)
 Ask the synchronizer to return the time step between the instant remembered during EventStart and now. More...
 
void EventStart (void)
 Ask the synchronizer to remember what time it is. More...
 
uint64_t GetCurrentRealtime (void)
 Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units. More...
 
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). More...
 
uint64_t GetOrigin (void)
 Retrieve the value of the origin of the simulation time in simulator timestep units. More...
 
bool Realtime (void)
 Return true if this synchronizer is actually synchronizing to a realtime clock. More...
 
void SetCondition (bool)
 Set the condition variable that tells a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. More...
 
void SetOrigin (uint64_t ts)
 Establish a correspondence between a simulation time and the synchronizer real time. More...
 
void Signal (void)
 Tell a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. More...
 
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. More...
 
- Public Member Functions inherited from ns3::Object
 Object ()
 
virtual ~Object ()
 
void AggregateObject (Ptr< Object > other)
 
void Dispose (void)
 Run the DoDispose methods of this object and all the objects aggregated to it. More...
 
AggregateIterator GetAggregateIterator (void) const
 
virtual TypeId GetInstanceTypeId (void) const
 
template<typename T >
Ptr< T > GetObject (void) const
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 
void Initialize (void)
 This method calls the virtual DoInitialize method on all the objects aggregated to this object. More...
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Constructor. More...
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor. More...
 
uint32_t GetReferenceCount (void) const
 Get the reference count of the object. More...
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment. More...
 
void Ref (void) const
 Increment the reference count. More...
 
void Unref (void) const
 Decrement the reference count. More...
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor. More...
 
void GetAttribute (std::string name, AttributeValue &value) const
 
bool GetAttributeFailSafe (std::string name, AttributeValue &attribute) const
 
void SetAttribute (std::string name, const AttributeValue &value)
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 

Static Public Member Functions

static TypeId GetTypeId (void)
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId (void)
 Register this type. More...
 
- Static Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
static void Cleanup (void)
 Noop. More...
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId (void)
 Get the type ID. More...
 

Protected Member Functions

virtual uint64_t DoEventEnd (void)=0
 
virtual void DoEventStart (void)=0
 
virtual uint64_t DoGetCurrentRealtime (void)=0
 Retrieve the value of the origin of the underlying normalized wall clock time in simulator timestep units. More...
 
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. More...
 
virtual bool DoRealtime (void)=0
 Return true if this synchronizer is actually synchronizing to a realtime clock. More...
 
virtual void DoSetCondition (bool)=0
 Declaration of the method used to set the condition variable that tells a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time. More...
 
virtual void DoSetOrigin (uint64_t ns)=0
 Establish a correspondence between a simulation time and a wall-clock (real) time. More...
 
virtual void DoSignal (void)=0
 Declaration of the method used to tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time. More...
 
virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay)=0
 Wait until the real time is in sync with the specified simulation time. More...
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 
virtual void DoDispose (void)
 This method is called by Object::Dispose or by the object's destructor, whichever comes first. More...
 
virtual void DoInitialize (void)
 This method is called only once by Object::Initialize. More...
 
virtual void NotifyNewAggregate (void)
 This method is invoked whenever two sets of objects are aggregated together. More...
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 
virtual void NotifyConstructionCompleted (void)
 This method is invoked once all member attributes have been initialized. More...
 

Protected Attributes

uint64_t m_realtimeOriginNano
 
uint64_t m_simOriginNano
 

Private Member Functions

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). More...
 
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. More...
 

Detailed Description

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

Doxygen introspection did not find any typical Config paths.

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.


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

Definition at line 44 of file synchronizer.h.

Constructor & Destructor Documentation

ns3::Synchronizer::Synchronizer ( )

Definition at line 37 of file synchronizer.cc.

References NS_LOG_FUNCTION.

ns3::Synchronizer::~Synchronizer ( )
virtual

Definition at line 43 of file synchronizer.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

virtual uint64_t ns3::Synchronizer::DoEventEnd ( void  )
protectedpure virtual

Implemented in ns3::WallClockSynchronizer.

Referenced by EventEnd().

+ Here is the caller graph for this function:

virtual void ns3::Synchronizer::DoEventStart ( void  )
protectedpure virtual

Implemented in ns3::WallClockSynchronizer.

Referenced by EventStart().

+ Here is the caller graph for this function:

virtual uint64_t ns3::Synchronizer::DoGetCurrentRealtime ( void  )
protectedpure virtual

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

Internal:

Subclasses are expected to implement this method to do the actual real-time-clock-specific work of getting the current time.

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

Implemented in ns3::WallClockSynchronizer.

Referenced by GetCurrentRealtime().

+ Here is the caller graph for this function:

virtual int64_t ns3::Synchronizer::DoGetDrift ( uint64_t  ns)
protectedpure virtual

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

Internal:
Parameters
nsSimulation timestep from the simulator normalized to nanosecond steps.
Returns
Drift in nanosecond units.
See also
TimeStepPrecision::Get
Synchronizer::SetOrigin
Synchronizer::GetDrift

Implemented in ns3::WallClockSynchronizer.

Referenced by GetDrift().

+ Here is the caller graph for this function:

virtual bool ns3::Synchronizer::DoRealtime ( void  )
protectedpure virtual

Return true if this synchronizer is actually synchronizing to a realtime clock.

The simulator sometimes needs to know this.

Internal:

Subclasses are expected to implement this method to tell the outside world whether or not they are synchronizing to a realtime clock.

Returns
True if locked with realtime, false if not.

Implemented in ns3::WallClockSynchronizer.

Referenced by Realtime().

+ Here is the caller graph for this function:

virtual void ns3::Synchronizer::DoSetCondition ( bool  )
protectedpure virtual

Declaration of the method used to set the condition variable that tells a possible 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().

+ Here is the caller graph for this function:

virtual void ns3::Synchronizer::DoSetOrigin ( uint64_t  ns)
protectedpure virtual

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

Internal:

There are three timelines involved here: the simulation time, the (absolute) wall-clock time and the (relative) synchronizer real time. Calling this method makes a correspondence between the origin of the synchronizer time and the current wall-clock time.

This method is expected to be called at the "instant" before simulation begins. At this point, simulation time = 0, and synchronizer time is 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 this method to do the actual real-time-clock-specific work of making the correspondence mentioned above. for example, this is where the differences between Time parameters and parameters to clock_nanosleep would be dealt with.

Parameters
nsThe simulation time we need to use as the origin (normalized to nanosecond units).
See also
Synchronizer::SetOrigin
TimeStepPrecision::Get

Implemented in ns3::WallClockSynchronizer.

Referenced by SetOrigin().

+ Here is the caller graph for this function:

virtual void ns3::Synchronizer::DoSignal ( void  )
protectedpure virtual

Declaration of the method used to tell a possible 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().

+ Here is the caller graph for this function:

virtual bool ns3::Synchronizer::DoSynchronize ( uint64_t  nsCurrent,
uint64_t  nsDelay 
)
protectedpure virtual

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

Internal:

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 this method to do the actual real-time-clock-specific work of waiting (either busy-waiting or sleeping, or some combination) until the requested simulation time.

Parameters
nsCurrentThe current simulation time (normalized to nanosecond units).
nsDelayThe simulation time we need to wait for (normalized to nanosecond units).
Returns
True if the function ran to completion, false if it was interrupted by a Signal.
See also
Synchronizer::Synchronize
TimeStepPrecision::Get
Synchronizer::Signal

Implemented in ns3::WallClockSynchronizer.

Referenced by Synchronize().

+ Here is the caller graph for this function:

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 121 of file synchronizer.cc.

References DoEventEnd(), NanosecondToTimeStep(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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 114 of file synchronizer.cc.

References DoEventStart(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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 56 of file synchronizer.cc.

References DoGetCurrentRealtime(), NanosecondToTimeStep(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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
tsSimulation 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 78 of file synchronizer.cc.

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

+ Here is the call graph for this function:

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 71 of file synchronizer.cc.

References m_simOriginNano, NanosecondToTimeStep(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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

Definition at line 29 of file synchronizer.cc.

References ns3::TypeId::SetParent().

+ Here is the call graph for this function:

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).

Internal:
Parameters
nsThe nanosecond count step to be converted
Returns
The simulation time step to be interpreted in appropriate units.
See also
TimeStepPrecision::Get

Definition at line 135 of file synchronizer.cc.

References NS_LOG_FUNCTION.

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

+ Here is the caller graph for this function:

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 49 of file synchronizer.cc.

References DoRealtime(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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

Set the condition variable that tells a possible 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 107 of file synchronizer.cc.

References DoSetCondition(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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
tsThe simulation time we should use as the origin (in simulator timestep units).
See also
TimeStepPrecision::Get
TimeStepPrecision::DoSetOrigin

Definition at line 63 of file synchronizer.cc.

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

+ Here is the call graph for this function:

void ns3::Synchronizer::Signal ( void  )

Tell a possible 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 100 of file synchronizer.cc.

References DoSignal(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

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
tsCurrentThe current simulation time (in simulator timestep units).
tsDelayThe 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 92 of file synchronizer.cc.

References DoSynchronize(), NS_LOG_FUNCTION, and TimeStepToNanosecond().

+ Here is the call graph for this function:

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.

Internal:
Parameters
tsThe simulation time step to be normalized.
Returns
The simulation time step normalized to nanosecond units.
See also
TimeStepPrecision::Get

Definition at line 128 of file synchronizer.cc.

References ns3::Time::GetNanoSeconds(), NS_LOG_FUNCTION, and ns3::TimeStep().

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

uint64_t ns3::Synchronizer::m_realtimeOriginNano
protected
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: