From b604bf2d7abcbc5e490623956173ff9bb2c267f1 Mon Sep 17 00:00:00 2001 From: Mathieu Lacage Date: Tue, 11 Dec 2007 17:48:09 +0100 Subject: [PATCH] estimation delay and jitter --- src/contrib/delay-jitter-estimation.cc | 98 ++++++++++++++++++++++++++ src/contrib/delay-jitter-estimation.h | 28 ++++++++ 2 files changed, 126 insertions(+) create mode 100644 src/contrib/delay-jitter-estimation.cc create mode 100644 src/contrib/delay-jitter-estimation.h diff --git a/src/contrib/delay-jitter-estimation.cc b/src/contrib/delay-jitter-estimation.cc new file mode 100644 index 000000000..007359758 --- /dev/null +++ b/src/contrib/delay-jitter-estimation.cc @@ -0,0 +1,98 @@ + +#include "delay-jitter-estimation.h" +#include "ns3/tag.h" +#include "ns3/simulator.h" + +namespace { + +class TimestampTag : public ns3::Tag +{ +public: + TimestampTag (); + static uint32_t GetUid (void); + void Print (std::ostream &os) const; + void Serialize (ns3::Buffer::Iterator start) const; + uint32_t Deserialize (ns3::Buffer::Iterator start); + uint32_t GetSerializedSize (void) const; + + ns3::Time GetTxTime (void) const; +private: + uint64_t m_creationTime; +}; + +TimestampTag::TimestampTag () + : m_creationTime (ns3::Simulator::Now ().GetTimeStep ()) +{} +uint32_t +TimestampTag::GetUid (void) +{ + static uint32_t uid = ns3::Tag::AllocateUid ("mathieu.paper.TimestampTag"); + return uid; +} +void +TimestampTag::Print (std::ostream &os) const +{ + os << ns3::TimeStep (m_creationTime); +} +void +TimestampTag::Serialize (ns3::Buffer::Iterator start) const +{} +uint32_t +TimestampTag::Deserialize (ns3::Buffer::Iterator start) +{ + return 0; +} +uint32_t +TimestampTag::GetSerializedSize (void) const +{ + return 0; +} +ns3::Time +TimestampTag::GetTxTime (void) const +{ + return ns3::TimeStep (m_creationTime); +} + +} + +namespace ns3 { + +DelayJitterEstimation::DelayJitterEstimation () + : m_previousRx (Simulator::Now ()), + m_previousRxTx (Simulator::Now ()), + m_jitter (Seconds (0.0)), + m_delay (Seconds (0.0)) +{} +void +DelayJitterEstimation::PrepareTx (Ptr packet) +{ + TimestampTag tag; + packet->AddTag (tag); +} +void +DelayJitterEstimation::RecordRx (Ptr packet) +{ + TimestampTag tag; + bool found = packet->PeekTag (tag); + NS_ASSERT (found); + tag.GetTxTime (); + + Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx); + m_jitter += (Abs (delta) - m_jitter ) / Scalar (16.0); + m_previousRx = Simulator::Now (); + m_previousRxTx = tag.GetTxTime (); + m_delay = Simulator::Now () - tag.GetTxTime (); +} + +Time +DelayJitterEstimation::GetLastDelay (void) const +{ + return m_delay; +} +Time +DelayJitterEstimation::GetLastJitter (void) const +{ + return m_jitter; +} + +} // namespace ns3 diff --git a/src/contrib/delay-jitter-estimation.h b/src/contrib/delay-jitter-estimation.h new file mode 100644 index 000000000..d4dc0e5bf --- /dev/null +++ b/src/contrib/delay-jitter-estimation.h @@ -0,0 +1,28 @@ +#ifndef DELAY_JITTER_ESTIMATION_H +#define DELAY_JITTER_ESTIMATION_H + +#include "ns3/nstime.h" +#include "ns3/packet.h" + +namespace ns3 { + +class DelayJitterEstimation +{ +public: + DelayJitterEstimation (); + static void PrepareTx (Ptr packet); + void RecordRx (Ptr packet); + + Time GetLastDelay (void) const; + Time GetLastJitter (void) const; + +private: + Time m_previousRx; + Time m_previousRxTx; + Time m_jitter; + Time m_delay; +}; + +} // namespace ns3 + +#endif /* DELAY_JITTER_ESTIMATION_H */