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 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
22 #include "ns3/tag.h"
23 #include "ns3/simulator.h"
24 #include "ns3/string.h"
25 
26 namespace ns3 {
27 
34 {
35 public:
37 
42  static TypeId GetTypeId (void);
43  virtual TypeId GetInstanceTypeId (void) const;
44 
45  virtual uint32_t GetSerializedSize (void) const;
46  virtual void Serialize (TagBuffer i) const;
47  virtual void Deserialize (TagBuffer i);
48  virtual void Print (std::ostream &os) const;
49 
54  Time GetTxTime (void) const;
55 private:
56  uint64_t m_creationTime;
57 };
58 
60  : m_creationTime (Simulator::Now ().GetTimeStep ())
61 {
62 }
63 
64 TypeId
66 {
67  static TypeId tid = TypeId ("anon::DelayJitterEstimationTimestampTag")
68  .SetParent<Tag> ()
69  .AddConstructor<DelayJitterEstimationTimestampTag> ()
70  .AddAttribute ("CreationTime",
71  "The time at which the timestamp was created",
72  StringValue ("0.0s"),
74  MakeTimeChecker ())
75  ;
76  return tid;
77 }
78 TypeId
80 {
81  return GetTypeId ();
82 }
83 
84 uint32_t
86 {
87  return 8;
88 }
89 void
91 {
93 }
94 void
96 {
97  m_creationTime = i.ReadU64 ();
98 }
99 void
101 {
102  os << "CreationTime=" << m_creationTime;
103 }
104 Time
106 {
107  return TimeStep (m_creationTime);
108 }
109 
111  : m_previousRx (Simulator::Now ()),
112  m_previousRxTx (Simulator::Now ()),
113  m_jitter (0),
114  m_delay (Seconds (0.0))
115 {
116 }
117 void
119 {
121  packet->AddByteTag (tag);
122 }
123 void
125 {
127  bool found;
128  found = packet->FindFirstMatchingByteTag (tag);
129  if (!found)
130  {
131  return;
132  }
133  tag.GetTxTime ();
134 
135  Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx);
136  m_jitter += (Abs (delta) - m_jitter) / 16;
138  m_previousRxTx = tag.GetTxTime ();
139  m_delay = Simulator::Now () - tag.GetTxTime ();
140 }
141 
142 Time
144 {
145  return m_delay;
146 }
147 uint64_t
149 {
150  return m_jitter.GetHigh ();
151 }
152 
153 } // namespace ns3
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:824
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:95
Control the scheduling of simulation events.
Definition: simulator.h:63
hold variables of type string
Definition: string.h:18
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
void RecordRx(Ptr< const Packet > packet)
virtual void Print(std::ostream &os) const
static TypeId GetTypeId(void)
Get the type ID.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:444
uint64_t GetLastJitter(void) const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
static void PrepareTx(Ptr< const Packet > packet)
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:183
virtual void Serialize(TagBuffer i) const
tag a set of bytes in a packet
Definition: tag.h:36
uint64_t ReadU64(void)
Definition: tag-buffer.cc:134
Time m_previousRxTx
Previous Rx or Tx time.
Tag to perform Delay and Jitter estimations.
Time TimeStep(uint64_t ts)
Definition: nstime.h:902
static Time Now(void)
Return the "current simulation time".
Definition: simulator.cc:180
Time m_delay
Delay estimation.
Time m_previousRx
Previous Rx time.
read and write tag data
Definition: tag-buffer.h:51
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:845
Time GetTxTime(void) const
Get the Transmission time stored in the tag.
int64_t GetHigh(void) const
Get the integer portion.
Definition: int64x64-128.h:191
uint64_t m_creationTime
The time stored in the tag.
int64x64_t m_jitter
Jitter estimation.
virtual uint32_t GetSerializedSize(void) const
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:610
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:808