A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 ()
 Constructor.
 
 ~Synchronizer () override
 Destructor.
 
uint64_t EventEnd ()
 Ask the synchronizer to return the time step between the instant remembered during EventStart and now.
 
void EventStart ()
 Ask the synchronizer to remember what time it is.
 
uint64_t GetCurrentRealtime ()
 Retrieve the value of the origin of the underlying normalized wall clock 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 Time resolution units).
 
uint64_t GetOrigin ()
 Retrieve the value of the origin of the simulation time in Time.resolution units.
 
bool Realtime ()
 Return true if this synchronizer is actually synchronizing to a realtime clock.
 
void 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.
 
void SetOrigin (uint64_t ts)
 Establish a correspondence between a simulation time and the synchronizer real time.
 
void Signal ()
 Tell a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait 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 Signalled.
 
- Public Member Functions inherited from ns3::Object
 Object ()
 Constructor.
 
 ~Object () override
 Destructor.
 
void AggregateObject (Ptr< Object > other)
 Aggregate two Objects together.
 
void Dispose ()
 Dispose of this Object.
 
AggregateIterator GetAggregateIterator () const
 Get an iterator to the Objects aggregated to this one.
 
TypeId GetInstanceTypeId () const override
 Get the most derived TypeId for this Object.
 
template<typename T >
Ptr< T > GetObject () const
 Get a pointer to the requested aggregated Object.
 
template<>
Ptr< ObjectGetObject () const
 Specialization of () for objects of type ns3::Object.
 
template<typename T >
Ptr< T > GetObject (TypeId tid) const
 Get a pointer to the requested aggregated Object by TypeId.
 
template<>
Ptr< ObjectGetObject (TypeId tid) const
 Specialization of (TypeId tid) for objects of type ns3::Object.
 
void Initialize ()
 Invoke DoInitialize on all Objects aggregated to this one.
 
bool IsInitialized () const
 Check if the object has been initialized.
 
void UnidirectionalAggregateObject (Ptr< Object > other)
 Aggregate an Object to another Object.
 
- Public Member Functions inherited from ns3::SimpleRefCount< Object, ObjectBase, ObjectDeleter >
 SimpleRefCount ()
 Default constructor.
 
 SimpleRefCount (const SimpleRefCount &o)
 Copy constructor.
 
uint32_t GetReferenceCount () const
 Get the reference count of the object.
 
SimpleRefCountoperator= (const SimpleRefCount &o)
 Assignment operator.
 
void Ref () const
 Increment the reference count.
 
void Unref () const
 Decrement the reference count.
 
- Public Member Functions inherited from ns3::ObjectBase
virtual ~ObjectBase ()
 Virtual destructor.
 
void GetAttribute (std::string name, AttributeValue &value, bool permissive=false) const
 Get the value of an attribute, raising fatal errors if unsuccessful.
 
bool GetAttributeFailSafe (std::string name, AttributeValue &value) const
 Get the value of an attribute without raising errors.
 
void SetAttribute (std::string name, const AttributeValue &value)
 Set a single attribute, raising fatal errors if unsuccessful.
 
bool SetAttributeFailSafe (std::string name, const AttributeValue &value)
 Set a single attribute without raising errors.
 
bool TraceConnect (std::string name, std::string context, const CallbackBase &cb)
 Connect a TraceSource to a Callback with a context.
 
bool TraceConnectWithoutContext (std::string name, const CallbackBase &cb)
 Connect a TraceSource to a Callback without a context.
 
bool TraceDisconnect (std::string name, std::string context, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected with a context.
 
bool TraceDisconnectWithoutContext (std::string name, const CallbackBase &cb)
 Disconnect from a TraceSource a Callback previously connected without a context.
 

Static Public Member Functions

static TypeId GetTypeId ()
 Get the registered TypeId for this class.
 
- Static Public Member Functions inherited from ns3::Object
static TypeId GetTypeId ()
 Register this type.
 
- Static Public Member Functions inherited from ns3::ObjectBase
static TypeId GetTypeId ()
 Get the type ID.
 

Protected Member Functions

virtual uint64_t DoEventEnd ()=0
 Return the amount of real time elapsed since the last call to EventStart.
 
virtual void DoEventStart ()=0
 Record the normalized real time at which the current event is starting execution.
 
virtual uint64_t DoGetCurrentRealtime ()=0
 Retrieve the value of the origin of the underlying normalized wall clock time in Time resolution units.
 
virtual int64_t DoGetDrift (uint64_t ns)=0
 Get the drift between the real time clock used to synchronize the simulation and the current simulation time.
 
virtual bool DoRealtime ()=0
 Return true if this synchronizer is actually synchronizing to a realtime clock.
 
virtual void DoSetCondition (bool cond)=0
 Set the condition variable to tell a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time.
 
virtual void DoSetOrigin (uint64_t ns)=0
 Establish a correspondence between a simulation time and a wall-clock (real) time.
 
virtual void DoSignal ()=0
 Tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which demands a reevaluation of the wait time.
 
virtual bool DoSynchronize (uint64_t nsCurrent, uint64_t nsDelay)=0
 Wait until the real time is in sync with the specified simulation time.
 
- Protected Member Functions inherited from ns3::Object
 Object (const Object &o)
 Copy an Object.
 
virtual void DoDispose ()
 Destructor implementation.
 
virtual void DoInitialize ()
 Initialize() implementation.
 
virtual void NotifyNewAggregate ()
 Notify all Objects aggregated to this one of a new Object being aggregated.
 
- Protected Member Functions inherited from ns3::ObjectBase
void ConstructSelf (const AttributeConstructionList &attributes)
 Complete construction of ObjectBase; invoked by derived classes.
 
virtual void NotifyConstructionCompleted ()
 Notifier called once the ObjectBase is fully constructed.
 

Protected Attributes

uint64_t m_realtimeOriginNano
 The real time, in ns, when SetOrigin was called.
 
uint64_t m_simOriginNano
 The simulation time, in ns, when SetOrigin was called.
 

Private Member Functions

uint64_t NanosecondToTimeStep (uint64_t ns)
 Convert a normalized nanosecond time step into a simulator time step (in Time resolution units).
 
uint64_t TimeStepToNanosecond (uint64_t ts)
 Convert a simulator time step (in Time resolution units) to a normalized time step in nanosecond units.
 

Additional Inherited Members

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 Time::SetResolution 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 41 of file synchronizer.h.

Constructor & Destructor Documentation

◆ Synchronizer()

ns3::Synchronizer::Synchronizer ( )

Constructor.

Definition at line 31 of file synchronizer.cc.

References NS_LOG_FUNCTION.

◆ ~Synchronizer()

ns3::Synchronizer::~Synchronizer ( )
override

Destructor.

Definition at line 38 of file synchronizer.cc.

References NS_LOG_FUNCTION.

Member Function Documentation

◆ DoEventEnd()

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

Return the amount of real time elapsed since the last call to EventStart.

Returns
The elapsed real time, in ns.

Implemented in ns3::WallClockSynchronizer.

Referenced by EventEnd().

+ Here is the caller graph for this function:

◆ DoEventStart()

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

Record the normalized real time at which the current event is starting execution.

Implemented in ns3::WallClockSynchronizer.

Referenced by EventStart().

+ Here is the caller graph for this function:

◆ DoGetCurrentRealtime()

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

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

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
SetOrigin

Implemented in ns3::WallClockSynchronizer.

Referenced by GetCurrentRealtime().

+ Here is the caller graph for this function:

◆ DoGetDrift()

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

Get the drift between the real time clock used to synchronize the simulation and the current simulation time.

Parameters
[in]nsSimulation time in ns.
Returns
Drift in ns units.
See also
SetOrigin
GetDrift

Implemented in ns3::WallClockSynchronizer.

Referenced by GetDrift().

+ Here is the caller graph for this function:

◆ DoRealtime()

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

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

The simulator sometimes needs to know this.

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:

◆ DoSetCondition()

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

Set the condition variable to tell a possible simulator thread waiting in the Synchronize method that an event has happened which demands a reevaluation of the wait time.

Parameters
[in]condThe new value for the condition variable.
See also
SetCondition

Implemented in ns3::WallClockSynchronizer.

Referenced by SetCondition().

+ Here is the caller graph for this function:

◆ DoSetOrigin()

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

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

There are three timelines involved here: the simulation (virtual) 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
[in]nsThe simulation time we need to use as the origin (normalized to nanosecond units).
See also
SetOrigin

Implemented in ns3::WallClockSynchronizer.

Referenced by SetOrigin().

+ Here is the caller graph for this function:

◆ DoSignal()

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

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
Signal

Implemented in ns3::WallClockSynchronizer.

Referenced by Signal().

+ Here is the caller graph for this function:

◆ DoSynchronize()

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.

This is where the real work of synchronization is done. The nsCurrent argument is the simulation time (in ns). The job of DoSynchronize is to translate from simulation time to synchronizer time (in a perfect world these are 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
[in]nsCurrentThe current simulation time (in nanosecond units).
[in]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
Synchronize
Signal

Implemented in ns3::WallClockSynchronizer.

Referenced by Synchronize().

+ Here is the caller graph for this function:

◆ EventEnd()

uint64_t ns3::Synchronizer::EventEnd ( )

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.

Returns
The elapsed real time, in ns.
See also
EventStart

Definition at line 117 of file synchronizer.cc.

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

+ Here is the call graph for this function:

◆ EventStart()

void ns3::Synchronizer::EventStart ( )

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
EventEnd

Definition at line 110 of file synchronizer.cc.

References DoEventStart(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetCurrentRealtime()

uint64_t ns3::Synchronizer::GetCurrentRealtime ( )

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

Returns
The normalized wall clock time (in Time resolution units).
See also
SetOrigin

Definition at line 51 of file synchronizer.cc.

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

+ Here is the call graph for this function:

◆ GetDrift()

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 Time resolution units).

Parameters
[in]tsSimulation time in Time resolution units.
Returns
Simulation Time (in Time resolution units) minus the origin time (stored internally in nanosecond units).
See also
SetOrigin
DoGetDrift

Definition at line 73 of file synchronizer.cc.

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

+ Here is the call graph for this function:

◆ GetOrigin()

uint64_t ns3::Synchronizer::GetOrigin ( )

Retrieve the value of the origin of the simulation time in Time.resolution units.

Returns
The simulation time used as the origin (in Time resolution units).
See also
SetOrigin

Definition at line 66 of file synchronizer.cc.

References m_simOriginNano, NanosecondToTimeStep(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ GetTypeId()

TypeId ns3::Synchronizer::GetTypeId ( )
static

Get the registered TypeId for this class.

Returns
The TypeId.

Definition at line 25 of file synchronizer.cc.

References ns3::TypeId::SetParent().

+ Here is the call graph for this function:

◆ NanosecondToTimeStep()

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

Convert a normalized nanosecond time step into a simulator time step (in Time resolution units).

Parameters
[in]nsThe nanosecond count step to be converted
Returns
The simulation time step to be interpreted in appropriate units.

Definition at line 131 of file synchronizer.cc.

References ns3::Time::GetTimeStep(), ns3::NanoSeconds(), and NS_LOG_FUNCTION.

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Realtime()

bool ns3::Synchronizer::Realtime ( )

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

References DoRealtime(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ SetCondition()

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.

Parameters
[in]condThe new value for the condition variable.
See also
Signal

Definition at line 103 of file synchronizer.cc.

References DoSetCondition(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ SetOrigin()

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
[in]tsThe simulation time we should use as the origin (in Time resolution units).
See also
DoSetOrigin

Definition at line 58 of file synchronizer.cc.

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

+ Here is the call graph for this function:

◆ Signal()

void ns3::Synchronizer::Signal ( )

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
Synchronize
DoSignal

Definition at line 96 of file synchronizer.cc.

References DoSignal(), and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

◆ Synchronize()

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

This is where the real work of synchronization is done. The tsCurrent argument 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
[in]tsCurrentThe current simulation time (in Time resolution units).
[in]tsDelayThe simulation time we need to wait for (in Time resolution units).
Returns
true if the function ran to completion, false if it was interrupted by a Signal.
See also
DoSynchronize
Signal

Definition at line 89 of file synchronizer.cc.

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

+ Here is the call graph for this function:

◆ TimeStepToNanosecond()

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

Convert a simulator time step (in Time resolution units) to a normalized time step in nanosecond units.

Parameters
[in]tsThe simulation time step to be normalized.
Returns
The simulation time step normalized to nanosecond units.

Definition at line 124 of file synchronizer.cc.

References NS_LOG_FUNCTION.

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

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_realtimeOriginNano

uint64_t ns3::Synchronizer::m_realtimeOriginNano
protected

The real time, in ns, when SetOrigin was called.

Definition at line 307 of file synchronizer.h.

Referenced by ns3::WallClockSynchronizer::DoSetOrigin(), and ns3::WallClockSynchronizer::GetNormalizedRealtime().

◆ m_simOriginNano

uint64_t ns3::Synchronizer::m_simOriginNano
protected

The simulation time, in ns, when SetOrigin was called.

Definition at line 309 of file synchronizer.h.

Referenced by GetOrigin(), and SetOrigin().


The documentation for this class was generated from the following files: