author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 19 Dec 2007 13:24:30 +0100 | |
changeset 2287 | 363c7065ce0e |
parent 2281 | 1e9dd91f666f |
child 3038 | 5962e2962fa9 |
permissions | -rw-r--r-- |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
1 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
#include "delay-jitter-estimation.h" |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
#include "ns3/tag.h" |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
#include "ns3/simulator.h" |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
namespace { |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
class TimestampTag : public ns3::Tag |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
public: |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
TimestampTag (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
static uint32_t GetUid (void); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
void Print (std::ostream &os) const; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
void Serialize (ns3::Buffer::Iterator start) const; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
uint32_t Deserialize (ns3::Buffer::Iterator start); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
uint32_t GetSerializedSize (void) const; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
ns3::Time GetTxTime (void) const; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
private: |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
uint64_t m_creationTime; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
}; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
TimestampTag::TimestampTag () |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
: m_creationTime (ns3::Simulator::Now ().GetTimeStep ()) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
{} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
uint32_t |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
TimestampTag::GetUid (void) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
static uint32_t uid = ns3::Tag::AllocateUid<TimestampTag> ("mathieu.paper.TimestampTag"); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
30 |
return uid; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
TimestampTag::Print (std::ostream &os) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
os << ns3::TimeStep (m_creationTime); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
38 |
TimestampTag::Serialize (ns3::Buffer::Iterator start) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
39 |
{} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
40 |
uint32_t |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
41 |
TimestampTag::Deserialize (ns3::Buffer::Iterator start) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
42 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
return 0; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
44 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
45 |
uint32_t |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
TimestampTag::GetSerializedSize (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
47 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
return 0; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
49 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
50 |
ns3::Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
TimestampTag::GetTxTime (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
53 |
return ns3::TimeStep (m_creationTime); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
54 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
55 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
56 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
57 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
58 |
namespace ns3 { |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
59 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
60 |
DelayJitterEstimation::DelayJitterEstimation () |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
61 |
: m_previousRx (Simulator::Now ()), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
62 |
m_previousRxTx (Simulator::Now ()), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
63 |
m_jitter (Seconds (0.0)), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
m_delay (Seconds (0.0)) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
{} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
TimestampTag tag; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
packet->AddTag (tag); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
71 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
72 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
DelayJitterEstimation::RecordRx (Ptr<const Packet> packet) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
74 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
75 |
TimestampTag tag; |
2281
1e9dd91f666f
fix optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2265
diff
changeset
|
76 |
bool found; |
1e9dd91f666f
fix optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2265
diff
changeset
|
77 |
found = packet->PeekTag (tag); |
2287
363c7065ce0e
it is possible to receive packets which are not tagged. ignore them rather than crash.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2281
diff
changeset
|
78 |
if (!found) |
363c7065ce0e
it is possible to receive packets which are not tagged. ignore them rather than crash.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2281
diff
changeset
|
79 |
{ |
363c7065ce0e
it is possible to receive packets which are not tagged. ignore them rather than crash.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2281
diff
changeset
|
80 |
return; |
363c7065ce0e
it is possible to receive packets which are not tagged. ignore them rather than crash.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2281
diff
changeset
|
81 |
} |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
tag.GetTxTime (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
83 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
84 |
Time delta = (Simulator::Now () - m_previousRx) - (tag.GetTxTime () - m_previousRxTx); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
85 |
m_jitter += (Abs (delta) - m_jitter ) / Scalar (16.0); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
86 |
m_previousRx = Simulator::Now (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
m_previousRxTx = tag.GetTxTime (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
m_delay = Simulator::Now () - tag.GetTxTime (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
89 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
90 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
91 |
Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
DelayJitterEstimation::GetLastDelay (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
93 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
94 |
return m_delay; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
95 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
96 |
Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
97 |
DelayJitterEstimation::GetLastJitter (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
98 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
99 |
return m_jitter; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
100 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
101 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
102 |
} // namespace ns3 |