A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
network
helper
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
21
#include "
delay-jitter-estimation.h
"
22
#include "ns3/tag.h"
23
#include "ns3/simulator.h"
24
#include "ns3/string.h"
25
26
namespace
ns3
{
27
33
class
DelayJitterEstimationTimestampTag
:
public
Tag
34
{
35
public
:
36
DelayJitterEstimationTimestampTag
();
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
59
DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag
()
60
: m_creationTime (
Simulator
::
Now
().GetTimeStep ())
61
{
62
}
63
64
TypeId
65
DelayJitterEstimationTimestampTag::GetTypeId
(
void
)
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
StringValue
(
"0.0s"
),
74
MakeTimeAccessor
(&
DelayJitterEstimationTimestampTag::GetTxTime
),
75
MakeTimeChecker
())
76
;
77
return
tid;
78
}
79
TypeId
80
DelayJitterEstimationTimestampTag::GetInstanceTypeId
(
void
)
const
81
{
82
return
GetTypeId
();
83
}
84
85
uint32_t
86
DelayJitterEstimationTimestampTag::GetSerializedSize
(
void
)
const
87
{
88
return
8;
89
}
90
void
91
DelayJitterEstimationTimestampTag::Serialize
(
TagBuffer
i)
const
92
{
93
i.
WriteU64
(
m_creationTime
);
94
}
95
void
96
DelayJitterEstimationTimestampTag::Deserialize
(
TagBuffer
i)
97
{
98
m_creationTime
= i.
ReadU64
();
99
}
100
void
101
DelayJitterEstimationTimestampTag::Print
(std::ostream &os)
const
102
{
103
os <<
"CreationTime="
<<
m_creationTime
;
104
}
105
Time
106
DelayJitterEstimationTimestampTag::GetTxTime
(
void
)
const
107
{
108
return
TimeStep
(
m_creationTime
);
109
}
110
111
DelayJitterEstimation::DelayJitterEstimation
()
112
: m_previousRx (
Simulator
::
Now
()),
113
m_previousRxTx (
Simulator
::
Now
()),
114
m_jitter (0),
115
m_delay (
Seconds
(0.0))
116
{
117
}
118
void
119
DelayJitterEstimation::PrepareTx
(
Ptr<const Packet>
packet)
120
{
121
DelayJitterEstimationTimestampTag
tag;
122
packet->
AddByteTag
(tag);
123
}
124
void
125
DelayJitterEstimation::RecordRx
(
Ptr<const Packet>
packet)
126
{
127
DelayJitterEstimationTimestampTag
tag;
128
bool
found;
129
found = packet->
FindFirstMatchingByteTag
(tag);
130
if
(!found)
131
{
132
return
;
133
}
134
tag.
GetTxTime
();
135
136
Time
delta = (
Simulator::Now
() -
m_previousRx
) - (tag.
GetTxTime
() -
m_previousRxTx
);
137
m_jitter
+= (
Abs
(delta) -
m_jitter
) / 16;
138
m_previousRx
=
Simulator::Now
();
139
m_previousRxTx
= tag.
GetTxTime
();
140
m_delay
=
Simulator::Now
() - tag.
GetTxTime
();
141
}
142
143
Time
144
DelayJitterEstimation::GetLastDelay
(
void
)
const
145
{
146
return
m_delay
;
147
}
148
uint64_t
149
DelayJitterEstimation::GetLastJitter
(
void
)
const
150
{
151
return
m_jitter
.
GetHigh
();
152
}
153
154
}
// namespace ns3
ns3::Packet::FindFirstMatchingByteTag
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition:
packet.cc:835
ns3::DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag
DelayJitterEstimationTimestampTag()
Definition:
delay-jitter-estimation.cc:59
ns3::DelayJitterEstimationTimestampTag::Serialize
virtual void Serialize(TagBuffer i) const
Definition:
delay-jitter-estimation.cc:91
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition:
nstime.h:102
ns3::Ptr< const Packet >
ns3::Simulator
Control the scheduling of simulation events.
Definition:
simulator.h:68
ns3::StringValue
Hold variables of type string.
Definition:
string.h:41
ns3::TagBuffer::WriteU64
void WriteU64(uint64_t v)
Definition:
tag-buffer.cc:102
ns3::DelayJitterEstimation::RecordRx
void RecordRx(Ptr< const Packet > packet)
Definition:
delay-jitter-estimation.cc:125
ns3::DelayJitterEstimationTimestampTag::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition:
delay-jitter-estimation.cc:65
ns3::MakeTimeChecker
Ptr< const AttributeChecker > MakeTimeChecker(const Time min, const Time max)
Helper to make a Time checker with bounded range.
Definition:
time.cc:446
ns3::DelayJitterEstimation::DelayJitterEstimation
DelayJitterEstimation()
Definition:
delay-jitter-estimation.cc:111
ns3::DelayJitterEstimationTimestampTag::Print
virtual void Print(std::ostream &os) const
Definition:
delay-jitter-estimation.cc:101
ns3::DelayJitterEstimation::PrepareTx
static void PrepareTx(Ptr< const Packet > packet)
Definition:
delay-jitter-estimation.cc:119
ns3::Abs
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition:
int64x64.h:184
delay-jitter-estimation.h
ns3::Tag
tag a set of bytes in a packet
Definition:
tag.h:36
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TagBuffer::ReadU64
uint64_t ReadU64(void)
Definition:
tag-buffer.cc:134
ns3::DelayJitterEstimation::GetLastDelay
Time GetLastDelay(void) const
Definition:
delay-jitter-estimation.cc:144
ns3::DelayJitterEstimation::m_previousRxTx
Time m_previousRxTx
Previous Rx or Tx time.
Definition:
delay-jitter-estimation.h:73
ns3::DelayJitterEstimationTimestampTag
Tag to perform Delay and Jitter estimations.
Definition:
delay-jitter-estimation.cc:33
ns3::TimeStep
Time TimeStep(uint64_t ts)
Definition:
nstime.h:1071
ns3::MakeTimeAccessor
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition:
nstime.h:1077
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition:
simulator.cc:249
ns3::DelayJitterEstimationTimestampTag::Deserialize
virtual void Deserialize(TagBuffer i)
Definition:
delay-jitter-estimation.cc:96
ns3::DelayJitterEstimation::m_delay
Time m_delay
Delay estimation.
Definition:
delay-jitter-estimation.h:75
ns3::DelayJitterEstimation::m_previousRx
Time m_previousRx
Previous Rx time.
Definition:
delay-jitter-estimation.h:72
ns3::TagBuffer
read and write tag data
Definition:
tag-buffer.h:51
ns3::Seconds
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition:
nstime.h:1014
ns3::DelayJitterEstimationTimestampTag::m_creationTime
uint64_t m_creationTime
The time stored in the tag.
Definition:
delay-jitter-estimation.cc:56
ns3::Now
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition:
simulator.cc:365
ns3::DelayJitterEstimationTimestampTag::GetInstanceTypeId
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
Definition:
delay-jitter-estimation.cc:80
ns3::DelayJitterEstimation::GetLastJitter
uint64_t GetLastJitter(void) const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
Definition:
delay-jitter-estimation.cc:149
ns3::DelayJitterEstimation::m_jitter
int64x64_t m_jitter
Jitter estimation.
Definition:
delay-jitter-estimation.h:74
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:58
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition:
type-id.cc:915
ns3::Packet::AddByteTag
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition:
packet.cc:819
ns3::DelayJitterEstimationTimestampTag::GetSerializedSize
virtual uint32_t GetSerializedSize(void) const
Definition:
delay-jitter-estimation.cc:86
ns3::DelayJitterEstimationTimestampTag::GetTxTime
Time GetTxTime(void) const
Get the Transmission time stored in the tag.
Definition:
delay-jitter-estimation.cc:106
ns3::int64x64_t::GetHigh
int64_t GetHigh(void) const
Get the integer portion.
Definition:
int64x64-128.h:219
Generated on Wed Nov 7 2018 10:02:06 for ns-3 by
1.8.14