A Discrete-Event Network Simulator
API
delay-jitter-estimation.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2007 INRIA
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18  */
19 
21 
22 #include "ns3/simulator.h"
23 #include "ns3/string.h"
24 #include "ns3/timestamp-tag.h"
25 
26 namespace ns3
27 {
28 
30 {
31 }
32 
33 void
35 {
37  packet->AddByteTag(tag);
38 }
39 
40 void
42 {
43  TimestampTag tag;
44 
45  if (!packet->FindFirstMatchingByteTag(tag))
46  {
47  return;
48  }
49 
50  // Variable names from
51  // RFC 1889 Appendix A.8 ,p. 71,
52  // RFC 3550 Appendix A.8, p. 94
53  Time r_ts = tag.GetTimestamp();
54  Time arrival = Simulator::Now();
55  Time transit = arrival - r_ts;
56  Time delta = transit - m_transit;
57  m_transit = transit;
58 
59  // floating jitter version
60  // m_jitter += (Abs (delta) - m_jitter) / 16;
61 
62  // int variant
63  m_jitter += Abs(delta) - ((m_jitter + TimeStep(8)) / 16);
64 }
65 
66 Time
68 {
69  return m_transit;
70 }
71 
72 uint64_t
74 {
75  // floating jitter version
76  // return m_jitter.GetTimeStep();
77 
78  // int variant
79  return (m_jitter / 16).GetTimeStep();
80 }
81 
82 } // namespace ns3
Time GetLastDelay() const
Get the Last Delay object.
void RecordRx(Ptr< const Packet > packet)
Invoke this method to update the delay and jitter calculations After a call to this method,...
uint64_t GetLastJitter() const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
static void PrepareTx(Ptr< const Packet > packet)
This method should be invoked once on each packet to record within the packet the tx time which is us...
Time m_transit
Relative transit time for the previous packet.
Time m_jitter
Jitter estimation.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:943
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:915
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Timestamp tag for associating a timestamp with a packet.
Definition: timestamp-tag.h:39
Time GetTimestamp() const
Get the Timestamp object.
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:215
Every class exported by the ns3 library is enclosed in the ns3 namespace.