A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
delay-jitter-estimation.cc
Go to the documentation of this file.
1 
3 #include "ns3/tag.h"
4 #include "ns3/simulator.h"
5 #include "ns3/string.h"
6 
7 namespace ns3 {
8 
10 {
11 public:
13  static TypeId GetTypeId (void);
14  virtual TypeId GetInstanceTypeId (void) const;
15 
16  virtual uint32_t GetSerializedSize (void) const;
17  virtual void Serialize (TagBuffer i) const;
18  virtual void Deserialize (TagBuffer i);
19  virtual void Print (std::ostream &os) const;
20 
21  Time GetTxTime (void) const;
22 private:
23  uint64_t m_creationTime;
24 };
25 
27  : m_creationTime (Simulator::Now ().GetTimeStep ())
28 {
29 }
30 
31 TypeId
33 {
34  static TypeId tid = TypeId ("anon::DelayJitterEstimationTimestampTag")
35  .SetParent<Tag> ()
36  .AddConstructor<DelayJitterEstimationTimestampTag> ()
37  .AddAttribute ("CreationTime",
38  "The time at which the timestamp was created",
39  StringValue ("0.0s"),
41  MakeTimeChecker ())
42  ;
43  return tid;
44 }
45 TypeId
47 {
48  return GetTypeId ();
49 }
50 
51 uint32_t
53 {
54  return 8;
55 }
56 void
58 {
60 }
61 void
63 {
64  m_creationTime = i.ReadU64 ();
65 }
66 void
68 {
69  os << "CreationTime=" << m_creationTime;
70 }
71 Time
73 {
74  return TimeStep (m_creationTime);
75 }
76 
78  : m_previousRx (Simulator::Now ()),
79  m_previousRxTx (Simulator::Now ()),
80  m_jitter (0),
81  m_delay (Seconds (0.0))
82 {
83 }
84 void
86 {
88  packet->AddByteTag (tag);
89 }
90 void
92 {
94  bool found;
95  found = packet->FindFirstMatchingByteTag (tag);
96  if (!found)
97  {
98  return;
99  }
100  tag.GetTxTime ();
101 
102  Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx);
103  m_jitter += (Abs (delta) - m_jitter) / 16;
105  m_previousRxTx = tag.GetTxTime ();
106  m_delay = Simulator::Now () - tag.GetTxTime ();
107 }
108 
109 Time
111 {
112  return m_delay;
113 }
114 uint64_t
116 {
117  return m_jitter.GetHigh ();
118 }
119 
120 } // namespace ns3