A Discrete-Event Network Simulator
API
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
26namespace ns3 {
27
34{
35public:
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;
55private:
57};
58
60 : m_creationTime (Simulator::Now ())
61{
62}
63
66{
67 static TypeId tid = TypeId ("anon::DelayJitterEstimationTimestampTag")
68 .SetParent<Tag> ()
69 .SetGroupName("Network")
70 .AddConstructor<DelayJitterEstimationTimestampTag> ()
71 .AddAttribute ("CreationTime",
72 "The time at which the timestamp was created",
73 TimeValue (Time (0)),
76 ;
77 return tid;
78}
81{
82 return GetTypeId ();
83}
84
87{
88 return 8;
89}
90void
92{
94}
95void
97{
98 m_creationTime = TimeStep (i.ReadU64 ());
99}
100void
102{
103 os << "CreationTime=" << m_creationTime;
104}
105Time
107{
108 return m_creationTime;
109}
110
112 : m_jitter (Time (0)),
113 m_transit (Time (0))
114{
115}
116void
118{
120 packet->AddByteTag (tag);
121}
122void
124{
126 bool found;
127 found = packet->FindFirstMatchingByteTag (tag);
128 if (!found)
129 {
130 return;
131 }
132
133 // Variable names from
134 // RFC 1889 Appendix A.8 ,p. 71,
135 // RFC 3550 Appendix A.8, p. 94
136
137 Time r_ts = tag.GetTxTime ();
138 Time arrival = Simulator::Now ();
139 Time transit = arrival - r_ts;
140 Time delta = transit - m_transit;
141 m_transit = transit;
142
143 // floating jitter version
144 // m_jitter += (Abs (delta) - m_jitter) / 16;
145
146 // int variant
147 m_jitter += Abs (delta) - ( (m_jitter + TimeStep (8)) / 16 );
148}
149
150Time
152{
153 return m_transit;
154}
155uint64_t
157{
158 // floating jitter version
159 // return m_jitter.GetTimeStep ();
160
161 // int variant
162 return (m_jitter / 16).GetTimeStep ();
163}
164
165} // namespace ns3
void RecordRx(Ptr< const Packet > packet)
static void PrepareTx(Ptr< const Packet > packet)
uint64_t GetLastJitter(void) const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
Time m_transit
Relative transit time for the previous packet.
Time m_jitter
Jitter estimation.
Tag to perform Delay and Jitter estimations.
Time GetTxTime(void) const
Get the Transmission time stored in the tag.
virtual uint32_t GetSerializedSize(void) const
virtual void Print(std::ostream &os) const
static TypeId GetTypeId(void)
Get the type ID.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Time m_creationTime
The time stored in the tag.
virtual void Serialize(TagBuffer i) const
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:939
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:912
Control the scheduling of simulation events.
Definition: simulator.h:69
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
read and write tag data
Definition: tag-buffer.h:52
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:102
uint64_t ReadU64(void)
Definition: tag-buffer.cc:134
tag a set of bytes in a packet
Definition: tag.h:37
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:415
AttributeValue implementation for Time.
Definition: nstime.h:1308
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1309
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:205
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition: time.cc:536