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/tag.h"
25
26namespace ns3
27{
28
35{
36 public:
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:
59};
60
62 : m_creationTime(Simulator::Now())
63{
64}
65
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)),
79 return tid;
80}
81
84{
85 return GetTypeId();
86}
87
90{
91 return 8;
92}
93
94void
96{
98}
99
100void
102{
103 m_creationTime = TimeStep(i.ReadU64());
104}
105
106void
108{
109 os << "CreationTime=" << m_creationTime;
110}
111
112Time
114{
115 return m_creationTime;
116}
117
119 : m_jitter(Time(0)),
120 m_transit(Time(0))
121{
122}
123
124void
126{
128 packet->AddByteTag(tag);
129}
130
131void
133{
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
159Time
161{
162 return m_transit;
163}
164
165uint64_t
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
void RecordRx(Ptr< const Packet > packet)
uint64_t GetLastJitter() const
The jitter is calculated using the RFC 1889 (RTP) jitter definition.
static void PrepareTx(Ptr< const Packet > packet)
Time m_transit
Relative transit time for the previous packet.
Time m_jitter
Jitter estimation.
Tag to perform Delay and Jitter estimations.
void Print(std::ostream &os) const override
Time GetTxTime() const
Get the Transmission time stored in the tag.
Time m_creationTime
The time stored in the tag.
void Serialize(TagBuffer i) const override
static TypeId GetTypeId()
Get the type ID.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
bool FindFirstMatchingByteTag(Tag &tag) const
Finds the first tag matching the parameter Tag type.
Definition: packet.cc:962
void AddByteTag(const Tag &tag) const
Tag each byte included in this packet with a new byte tag.
Definition: packet.cc:934
Control the scheduling of simulation events.
Definition: simulator.h:68
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
read and write tag data
Definition: tag-buffer.h:52
void WriteU64(uint64_t v)
Definition: tag-buffer.cc:104
uint64_t ReadU64()
Definition: tag-buffer.cc:139
tag a set of bytes in a packet
Definition: tag.h:39
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:444
AttributeValue implementation for Time.
Definition: nstime.h:1425
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Ptr< const AttributeAccessor > MakeTimeAccessor(T1 a1)
Definition: nstime.h:1426
int64x64_t Abs(const int64x64_t &value)
Absolute value.
Definition: int64x64.h:215
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:296
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:850
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:535