diff --git a/examples/stats/wifi-example-apps.cc b/examples/stats/wifi-example-apps.cc index 9d07a8b34..4f78f14f0 100644 --- a/examples/stats/wifi-example-apps.cc +++ b/examples/stats/wifi-example-apps.cc @@ -278,65 +278,3 @@ Receiver::Receive(Ptr socket) // end Receiver::Receive } - -//---------------------------------------------------------------------- -//-- TimestampTag -//------------------------------------------------------ -TypeId -TimestampTag::GetTypeId() -{ - static TypeId tid = TypeId("TimestampTag") - .SetParent() - .AddConstructor() - .AddAttribute("Timestamp", - "Some momentous point in time!", - EmptyAttributeValue(), - MakeTimeAccessor(&TimestampTag::GetTimestamp), - MakeTimeChecker()); - return tid; -} - -TypeId -TimestampTag::GetInstanceTypeId() const -{ - return GetTypeId(); -} - -uint32_t -TimestampTag::GetSerializedSize() const -{ - return 8; -} - -void -TimestampTag::Serialize(TagBuffer i) const -{ - int64_t t = m_timestamp.GetNanoSeconds(); - i.Write((const uint8_t*)&t, 8); -} - -void -TimestampTag::Deserialize(TagBuffer i) -{ - int64_t t; - i.Read((uint8_t*)&t, 8); - m_timestamp = NanoSeconds(t); -} - -void -TimestampTag::SetTimestamp(Time time) -{ - m_timestamp = time; -} - -Time -TimestampTag::GetTimestamp() const -{ - return m_timestamp; -} - -void -TimestampTag::Print(std::ostream& os) const -{ - os << "t=" << m_timestamp; -} diff --git a/examples/stats/wifi-example-apps.h b/examples/stats/wifi-example-apps.h index 2e8e1488e..5dc301880 100644 --- a/examples/stats/wifi-example-apps.h +++ b/examples/stats/wifi-example-apps.h @@ -121,43 +121,3 @@ class Receiver : public Application // end class Receiver }; - -/** - * Timestamp tag - it carries when the packet has been sent. - * - * It would have been more realistic to include this info in - * a header. Here we show how to avoid the extra overhead in - * a simulation. - */ -class TimestampTag : public Tag -{ - public: - /** - * \brief Get the type ID. - * \return The object TypeId. - */ - static TypeId GetTypeId(); - TypeId GetInstanceTypeId() const override; - - uint32_t GetSerializedSize() const override; - void Serialize(TagBuffer i) const override; - void Deserialize(TagBuffer i) override; - - /** - * Set the timestamp. - * \param time The timestamp. - */ - void SetTimestamp(Time time); - /** - * Get the timestamp. - * \return the timestamp. - */ - Time GetTimestamp() const; - - void Print(std::ostream& os) const override; - - private: - Time m_timestamp; //!< Timestamp. - - // end class TimestampTag -}; diff --git a/src/network/helper/delay-jitter-estimation.cc b/src/network/helper/delay-jitter-estimation.cc index 04d034a76..9a31b99e5 100644 --- a/src/network/helper/delay-jitter-estimation.cc +++ b/src/network/helper/delay-jitter-estimation.cc @@ -21,120 +21,28 @@ #include "ns3/simulator.h" #include "ns3/string.h" -#include "ns3/tag.h" +#include "ns3/timestamp-tag.h" namespace ns3 { -/** - * Tag to perform Delay and Jitter estimations - * - * The tag holds the packet's creation timestamp - */ -class DelayJitterEstimationTimestampTag : public Tag -{ - public: - DelayJitterEstimationTimestampTag(); - - /** - * \brief Get the type ID. - * \return the object TypeId - */ - static TypeId GetTypeId(); - TypeId GetInstanceTypeId() const override; - - uint32_t GetSerializedSize() const override; - void Serialize(TagBuffer i) const override; - void Deserialize(TagBuffer i) override; - void Print(std::ostream& os) const override; - - /** - * \brief Get the Transmission time stored in the tag - * \return the transmission time - */ - Time GetTxTime() const; - - private: - Time m_creationTime; //!< The time stored in the tag -}; - -DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag() - : m_creationTime(Simulator::Now()) -{ -} - -TypeId -DelayJitterEstimationTimestampTag::GetTypeId() -{ - static TypeId tid = - TypeId("anon::DelayJitterEstimationTimestampTag") - .SetParent() - .SetGroupName("Network") - .AddConstructor() - .AddAttribute("CreationTime", - "The time at which the timestamp was created", - TimeValue(Time(0)), - MakeTimeAccessor(&DelayJitterEstimationTimestampTag::m_creationTime), - MakeTimeChecker()); - return tid; -} - -TypeId -DelayJitterEstimationTimestampTag::GetInstanceTypeId() const -{ - return GetTypeId(); -} - -uint32_t -DelayJitterEstimationTimestampTag::GetSerializedSize() const -{ - return 8; -} - -void -DelayJitterEstimationTimestampTag::Serialize(TagBuffer i) const -{ - i.WriteU64(m_creationTime.GetTimeStep()); -} - -void -DelayJitterEstimationTimestampTag::Deserialize(TagBuffer i) -{ - m_creationTime = TimeStep(i.ReadU64()); -} - -void -DelayJitterEstimationTimestampTag::Print(std::ostream& os) const -{ - os << "CreationTime=" << m_creationTime; -} - -Time -DelayJitterEstimationTimestampTag::GetTxTime() const -{ - return m_creationTime; -} - DelayJitterEstimation::DelayJitterEstimation() - : m_jitter(Time(0)), - m_transit(Time(0)) { } void DelayJitterEstimation::PrepareTx(Ptr packet) { - DelayJitterEstimationTimestampTag tag; + TimestampTag tag(Simulator::Now()); packet->AddByteTag(tag); } void DelayJitterEstimation::RecordRx(Ptr packet) { - DelayJitterEstimationTimestampTag tag; - bool found; - found = packet->FindFirstMatchingByteTag(tag); - if (!found) + TimestampTag tag; + + if (!packet->FindFirstMatchingByteTag(tag)) { return; } @@ -142,15 +50,14 @@ DelayJitterEstimation::RecordRx(Ptr packet) // Variable names from // RFC 1889 Appendix A.8 ,p. 71, // RFC 3550 Appendix A.8, p. 94 - - Time r_ts = tag.GetTxTime(); + Time r_ts = tag.GetTimestamp(); Time arrival = Simulator::Now(); Time transit = arrival - r_ts; Time delta = transit - m_transit; m_transit = transit; // floating jitter version - // m_jitter += (Abs (delta) - m_jitter) / 16; + // m_jitter += (Abs (delta) - m_jitter) / 16; // int variant m_jitter += Abs(delta) - ((m_jitter + TimeStep(8)) / 16); @@ -166,7 +73,7 @@ uint64_t DelayJitterEstimation::GetLastJitter() const { // floating jitter version - // return m_jitter.GetTimeStep (); + // return m_jitter.GetTimeStep(); // int variant return (m_jitter / 16).GetTimeStep(); diff --git a/src/network/helper/delay-jitter-estimation.h b/src/network/helper/delay-jitter-estimation.h index 8c1096f71..2587e278c 100644 --- a/src/network/helper/delay-jitter-estimation.h +++ b/src/network/helper/delay-jitter-estimation.h @@ -74,8 +74,8 @@ class DelayJitterEstimation uint64_t GetLastJitter() const; private: - Time m_jitter; //!< Jitter estimation - Time m_transit; //!< Relative transit time for the previous packet + Time m_jitter{0}; //!< Jitter estimation + Time m_transit{0}; //!< Relative transit time for the previous packet }; } // namespace ns3