author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 24 Apr 2008 16:03:13 -0700 | |
changeset 3040 | e11e106c7c19 |
parent 3038 | 5962e2962fa9 |
child 3041 | a624276a897b |
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" |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
3 |
#include "ns3/mtag.h" |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
#include "ns3/simulator.h" |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
5 |
#include "ns3/string.h" |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
namespace { |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
|
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
9 |
class TimestampTag : public ns3::Tag |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
public: |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
TimestampTag (); |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
13 |
static ns3::TypeId GetTypeId (void); |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
14 |
virtual ns3::TypeId GetInstanceTypeId (void) const; |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
15 |
|
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
16 |
virtual uint32_t GetSerializedSize (void) const; |
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
17 |
virtual void Serialize (ns3::TagBuffer i) const; |
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
18 |
virtual void Deserialize (ns3::TagBuffer i); |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
19 |
|
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
ns3::Time GetTxTime (void) const; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
private: |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
uint64_t m_creationTime; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
}; |
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 |
TimestampTag::TimestampTag () |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
: m_creationTime (ns3::Simulator::Now ().GetTimeStep ()) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
{} |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
29 |
|
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
30 |
ns3::TypeId |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
31 |
TimestampTag::GetTypeId (void) |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
{ |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
33 |
static ns3::TypeId tid = ns3::TypeId ("anon::TimestampTag") |
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
34 |
.SetParent<Tag> () |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
35 |
.AddConstructor<TimestampTag> () |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
36 |
.AddAttribute ("CreationTime", |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
37 |
"The time at which the timestamp was created", |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
38 |
ns3::StringValue ("0.0s"), |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
39 |
ns3::MakeTimeAccessor (&TimestampTag::GetTxTime), |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
40 |
ns3::MakeTimeChecker ()) |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
41 |
; |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
42 |
return tid; |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
43 |
} |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
44 |
ns3::TypeId |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
45 |
TimestampTag::GetInstanceTypeId (void) const |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
46 |
{ |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
47 |
return GetTypeId (); |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
48 |
} |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
49 |
|
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
50 |
uint32_t |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
51 |
TimestampTag::GetSerializedSize (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
52 |
{ |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
53 |
return 8; |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
54 |
} |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
55 |
void |
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
56 |
TimestampTag::Serialize (ns3::TagBuffer i) const |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
57 |
{ |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
58 |
i.WriteU64 (m_creationTime); |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
59 |
} |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
60 |
void |
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
61 |
TimestampTag::Deserialize (ns3::TagBuffer i) |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
62 |
{ |
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
63 |
m_creationTime = i.ReadU64 (); |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
65 |
ns3::Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
66 |
TimestampTag::GetTxTime (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
67 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
68 |
return ns3::TimeStep (m_creationTime); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
69 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
|
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 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
73 |
namespace ns3 { |
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 |
DelayJitterEstimation::DelayJitterEstimation () |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
: m_previousRx (Simulator::Now ()), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
m_previousRxTx (Simulator::Now ()), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
78 |
m_jitter (Seconds (0.0)), |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
m_delay (Seconds (0.0)) |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
{} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
81 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet) |
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 |
TimestampTag tag; |
3040
e11e106c7c19
Mtag -> Tag
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
3038
diff
changeset
|
85 |
packet->AddTag (tag); |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
86 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
87 |
void |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
88 |
DelayJitterEstimation::RecordRx (Ptr<const Packet> packet) |
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 |
TimestampTag tag; |
2281
1e9dd91f666f
fix optimized build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2265
diff
changeset
|
91 |
bool found; |
3038
5962e2962fa9
convert to new tag API.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
2287
diff
changeset
|
92 |
found = packet->FindFirstMatchingTag (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
|
93 |
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
|
94 |
{ |
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
|
95 |
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
|
96 |
} |
2265
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
97 |
tag.GetTxTime (); |
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 |
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
|
100 |
m_jitter += (Abs (delta) - m_jitter ) / Scalar (16.0); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
101 |
m_previousRx = Simulator::Now (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
102 |
m_previousRxTx = tag.GetTxTime (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
103 |
m_delay = Simulator::Now () - tag.GetTxTime (); |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
104 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
105 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
106 |
Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
107 |
DelayJitterEstimation::GetLastDelay (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
108 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
109 |
return m_delay; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
110 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
111 |
Time |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
112 |
DelayJitterEstimation::GetLastJitter (void) const |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
113 |
{ |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
114 |
return m_jitter; |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
115 |
} |
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
116 |
|
190a2d913472
estimation delay and jitter
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
117 |
} // namespace ns3 |