A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
20
#include "
delay-jitter-estimation.h
"
21
22
#include "ns3/simulator.h"
23
#include "ns3/string.h"
24
#include "ns3/tag.h"
25
26
namespace
ns3
27
{
28
34
class
DelayJitterEstimationTimestampTag
:
public
Tag
35
{
36
public
:
37
DelayJitterEstimationTimestampTag
();
38
43
static
TypeId
GetTypeId
();
44
TypeId
GetInstanceTypeId
()
const override
;
45
46
uint32_t
GetSerializedSize
()
const override
;
47
void
Serialize
(
TagBuffer
i)
const override
;
48
void
Deserialize
(
TagBuffer
i)
override
;
49
void
Print
(std::ostream& os)
const override
;
50
55
Time
GetTxTime
()
const
;
56
57
private
:
58
Time
m_creationTime
;
59
};
60
61
DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag
()
62
: m_creationTime(
Simulator
::
Now
())
63
{
64
}
65
66
TypeId
67
DelayJitterEstimationTimestampTag::GetTypeId
()
68
{
69
static
TypeId
tid =
70
TypeId
(
"anon::DelayJitterEstimationTimestampTag"
)
71
.
SetParent
<
Tag
>()
72
.SetGroupName(
"Network"
)
73
.AddConstructor<
DelayJitterEstimationTimestampTag
>()
74
.AddAttribute(
"CreationTime"
,
75
"The time at which the timestamp was created"
,
76
TimeValue
(
Time
(0)),
77
MakeTimeAccessor
(&
DelayJitterEstimationTimestampTag::m_creationTime
),
78
MakeTimeChecker
());
79
return
tid;
80
}
81
82
TypeId
83
DelayJitterEstimationTimestampTag::GetInstanceTypeId
()
const
84
{
85
return
GetTypeId
();
86
}
87
88
uint32_t
89
DelayJitterEstimationTimestampTag::GetSerializedSize
()
const
90
{
91
return
8;
92
}
93
94
void
95
DelayJitterEstimationTimestampTag::Serialize
(
TagBuffer
i)
const
96
{
97
i.
WriteU64
(
m_creationTime
.
GetTimeStep
());
98
}
99
100
void
101
DelayJitterEstimationTimestampTag::Deserialize
(
TagBuffer
i)
102
{
103
m_creationTime
= TimeStep(i.
ReadU64
());
104
}
105
106
void
107
DelayJitterEstimationTimestampTag::Print
(std::ostream& os)
const
108
{
109
os <<
"CreationTime="
<<
m_creationTime
;
110
}
111
112
Time
113
DelayJitterEstimationTimestampTag::GetTxTime
()
const
114
{
115
return
m_creationTime
;
116
}
117
118
DelayJitterEstimation::DelayJitterEstimation
()
119
: m_jitter(
Time
(0)),
120
m_transit(
Time
(0))
121
{
122
}
123
124
void
125
DelayJitterEstimation::PrepareTx
(
Ptr<const Packet>
packet)
126
{
127
DelayJitterEstimationTimestampTag
tag;
128
packet->
AddByteTag
(tag);
129
}
130
131
void
132
DelayJitterEstimation::RecordRx
(
Ptr<const Packet>
packet)
133
{
134
DelayJitterEstimationTimestampTag
tag;
135
bool
found;
136
found = packet->
FindFirstMatchingByteTag
(tag);
137
if
(!found)
138
{
139
return
;
140
}
141
142
// Variable names from
143
// RFC 1889 Appendix A.8 ,p. 71,
144
// RFC 3550 Appendix A.8, p. 94
145
146
Time
r_ts = tag.
GetTxTime
();
147
Time
arrival =
Simulator::Now
();
148
Time
transit = arrival - r_ts;
149
Time
delta = transit -
m_transit
;
150
m_transit
= transit;
151
152
// floating jitter version
153
// m_jitter += (Abs (delta) - m_jitter) / 16;
154
155
// int variant
156
m_jitter
+=
Abs
(delta) - ((
m_jitter
+ TimeStep(8)) / 16);
157
}
158
159
Time
160
DelayJitterEstimation::GetLastDelay
()
const
161
{
162
return
m_transit
;
163
}
164
165
uint64_t
166
DelayJitterEstimation::GetLastJitter
()
const
167
{
168
// floating jitter version
169
// return m_jitter.GetTimeStep ();
170
171
// int variant
172
return
(
m_jitter
/ 16).GetTimeStep();
173
}
174
175
}
// namespace ns3
ns3::DelayJitterEstimation::GetLastDelay
Time GetLastDelay() const
Definition:
delay-jitter-estimation.cc:160
ns3::DelayJitterEstimation::RecordRx
void RecordRx(Ptr< const Packet > packet)
Definition:
delay-jitter-estimation.cc:132
ns3::DelayJitterEstimation::DelayJitterEstimation
DelayJitterEstimation()
Definition:
delay-jitter-estimation.cc:118
ns3::DelayJitterEstimation::GetLastJitter
uint64_t GetLastJitter() const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
Definition:
delay-jitter-estimation.cc:166
ns3::DelayJitterEstimation::PrepareTx
static void PrepareTx(Ptr< const Packet > packet)
Definition:
delay-jitter-estimation.cc:125
ns3::DelayJitterEstimation::m_transit
Time m_transit
Relative transit time for the previous packet.
Definition:
delay-jitter-estimation.h:78
ns3::DelayJitterEstimation::m_jitter
Time m_jitter
Jitter estimation.
Definition:
delay-jitter-estimation.h:77
ns3::DelayJitterEstimationTimestampTag
Tag to perform Delay and Jitter estimations.
Definition:
delay-jitter-estimation.cc:35
ns3::DelayJitterEstimationTimestampTag::Print
void Print(std::ostream &os) const override
Definition:
delay-jitter-estimation.cc:107
ns3::DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag
DelayJitterEstimationTimestampTag()
Definition:
delay-jitter-estimation.cc:61
ns3::DelayJitterEstimationTimestampTag::GetTxTime
Time GetTxTime() const
Get the Transmission time stored in the tag.
Definition:
delay-jitter-estimation.cc:113
ns3::DelayJitterEstimationTimestampTag::GetSerializedSize
uint32_t GetSerializedSize() const override
Definition:
delay-jitter-estimation.cc:89
ns3::DelayJitterEstimationTimestampTag::m_creationTime
Time m_creationTime
The time stored in the tag.
Definition:
delay-jitter-estimation.cc:58
ns3::DelayJitterEstimationTimestampTag::Serialize
void Serialize(TagBuffer i) const override
Definition:
delay-jitter-estimation.cc:95
ns3::DelayJitterEstimationTimestampTag::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition:
delay-jitter-estimation.cc:67
ns3::DelayJitterEstimationTimestampTag::Deserialize
void Deserialize(TagBuffer i) override
Definition:
delay-jitter-estimation.cc:101
ns3::DelayJitterEstimationTimestampTag::GetInstanceTypeId
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
Definition:
delay-jitter-estimation.cc:83
ns3::Packet::FindFirstMatchingByteTag
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition:
packet.cc:962
ns3::Packet::AddByteTag
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition:
packet.cc:934
ns3::Ptr< const Packet >
ns3::Simulator
Control the scheduling of simulation events.
Definition:
simulator.h:68
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition:
simulator.cc:199
ns3::TagBuffer
read and write tag data
Definition:
tag-buffer.h:52
ns3::TagBuffer::WriteU64
void WriteU64(uint64_t v)
Definition:
tag-buffer.cc:104
ns3::TagBuffer::ReadU64
uint64_t ReadU64()
Definition:
tag-buffer.cc:139
ns3::Tag
tag a set of bytes in a packet
Definition:
tag.h:39
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:105
ns3::Time::GetTimeStep
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition:
nstime.h:444
ns3::TimeValue
AttributeValue implementation for Time.
Definition:
nstime.h:1425
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:60
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:935
uint32_t
delay-jitter-estimation.h
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition:
nstime.h:1426
ns3::Abs
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition:
int64x64.h:215
ns3::Now
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition:
simulator.cc:296
ns3::TracedValueCallback::Time
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition:
nstime.h:850
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition:
time.cc:535
src
network
helper
delay-jitter-estimation.cc
Generated on Tue Nov 1 2022 23:00:24 for ns-3 by
1.9.3