44 static TypeId tid =
TypeId (
"ns3::WallClockSynchronizer")
82 clock_getres (CLOCK_REALTIME, &ts);
153 return (int64_t)(nsNow - ns);
161 return -(int64_t)(ns - nsNow);
204 uint64_t numberJiffies = ns /
m_jiffy;
205 NS_LOG_INFO (
"Synchronize numberJiffies = " << numberJiffies);
227 if (numberJiffies > 3)
261 int64_t nsDrift =
DoGetDrift (nsCurrent + nsDelay);
269 NS_LOG_INFO (
"Back from SleepWait: IML8 " << nsDrift);
279 NS_LOG_INFO (
"SpinWait until " << nsCurrent + nsDelay);
280 return SpinWait (nsCurrent + nsDelay);
361 uint64_t correction = (uint64_t)drift;
362 if (correction <= nsDelay)
364 return nsDelay - correction;
376 struct timeval tvNow;
377 gettimeofday (&tvNow, NULL);
410 struct timeval *result)
413 result->tv_sec = tv1->tv_sec + tv2->tv_sec;
414 result->tv_usec = tv1->tv_usec + tv2->tv_usec;
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint64_t m_jiffy
Size of the system clock tick, as reported by clock_getres, in ns.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
System-independent thread conditional wait.
uint64_t TimevalToNs(struct timeval *tv)
Convert a timeval to absolute time, in ns.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
static const uint64_t NS_PER_SEC
Conversion constant between ns and s.
uint64_t m_nsEventStart
Time recorded by DoEventStart.
void Signal(void)
Release one thread if waiting for the condition to be true.
bool SleepWait(uint64_t ns)
Put our process to sleep for some number of nanoseconds.
static const uint64_t US_PER_NS
Conversion constant between μs and ns.
WallClockSynchronizer()
Constructor.
uint64_t GetRealtime(void)
Get the current absolute real time (in ns since the epoch).
virtual int64_t DoGetDrift(uint64_t ns)
Get the drift between the real time clock used to synchronize the simulation and the current simulati...
virtual bool DoRealtime(void)
Return true if this synchronizer is actually synchronizing to a realtime clock.
ns3::WallClockSynchronizer declaration.
void SetCondition(bool condition)
Set the value of the underlying condition.
virtual uint64_t DoGetCurrentRealtime(void)
Retrieve the value of the origin of the underlying normalized wall clock time in Time resolution unit...
virtual bool DoSynchronize(uint64_t nsCurrent, uint64_t nsDelay)
Wait until the real time is in sync with the specified simulation time.
bool GetCondition(void)
Get the value of the underlying condition.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual ~WallClockSynchronizer()
Destructor.
Base class used for synchronizing the simulation events to some real time "wall clock.".
bool TimedWait(uint64_t ns)
Wait a maximum of ns nanoseconds for the condition to be true.
virtual void DoSetOrigin(uint64_t ns)
Establish a correspondence between a simulation time and a wall-clock (real) time.
static const uint64_t US_PER_SEC
Conversion constant between μs and seconds.
uint64_t m_realtimeOriginNano
The real time, in ns, when SetOrigin was called.
virtual void DoEventStart(void)
Record the normalized real time at which the current event is starting execution. ...
virtual void DoSetCondition(bool cond)
Set the condition variable to tell a possible simulator thread waiting in the Synchronize method that...
void NsToTimeval(int64_t ns, struct timeval *tv)
Convert an absolute time in ns to a timeval.
static TypeId GetTypeId(void)
Get the registered TypeId for this class.
void TimevalAdd(struct timeval *tv1, struct timeval *tv2, struct timeval *result)
Add two timeval.
SystemCondition m_condition
Thread synchronizer.
a unique identifier for an interface.
uint64_t GetNormalizedRealtime(void)
Get the current normalized real time, in ns.
TypeId SetParent(TypeId tid)
bool SpinWait(uint64_t ns)
Do a busy-wait until the normalized realtime equals the argument or the condition variable becomes tr...
virtual void DoSignal(void)
Tell a possible simulator thread waiting in the DoSynchronize method that an event has happened which...
virtual uint64_t DoEventEnd(void)
Return the amount of real time elapsed since the last call to EventStart.
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...