2 #include "delay-jitter-estimation.h" |
2 #include "delay-jitter-estimation.h" |
3 #include "ns3/tag.h" |
3 #include "ns3/tag.h" |
4 #include "ns3/simulator.h" |
4 #include "ns3/simulator.h" |
5 #include "ns3/string.h" |
5 #include "ns3/string.h" |
6 |
6 |
7 namespace { |
7 namespace ns3 { |
8 |
8 |
9 class TimestampTag : public ns3::Tag |
9 class DelayJitterEstimationTimestampTag : public Tag |
10 { |
10 { |
11 public: |
11 public: |
12 TimestampTag (); |
12 DelayJitterEstimationTimestampTag (); |
13 static ns3::TypeId GetTypeId (void); |
13 static TypeId GetTypeId (void); |
14 virtual ns3::TypeId GetInstanceTypeId (void) const; |
14 virtual TypeId GetInstanceTypeId (void) const; |
15 |
15 |
16 virtual uint32_t GetSerializedSize (void) const; |
16 virtual uint32_t GetSerializedSize (void) const; |
17 virtual void Serialize (ns3::TagBuffer i) const; |
17 virtual void Serialize (TagBuffer i) const; |
18 virtual void Deserialize (ns3::TagBuffer i); |
18 virtual void Deserialize (TagBuffer i); |
19 |
19 |
20 |
20 |
21 ns3::Time GetTxTime (void) const; |
21 Time GetTxTime (void) const; |
22 private: |
22 private: |
23 uint64_t m_creationTime; |
23 uint64_t m_creationTime; |
24 }; |
24 }; |
25 |
25 |
26 TimestampTag::TimestampTag () |
26 DelayJitterEstimationTimestampTag::DelayJitterEstimationTimestampTag () |
27 : m_creationTime (ns3::Simulator::Now ().GetTimeStep ()) |
27 : m_creationTime (Simulator::Now ().GetTimeStep ()) |
28 {} |
28 {} |
29 |
29 |
30 ns3::TypeId |
30 TypeId |
31 TimestampTag::GetTypeId (void) |
31 DelayJitterEstimationTimestampTag::GetTypeId (void) |
32 { |
32 { |
33 static ns3::TypeId tid = ns3::TypeId ("anon::TimestampTag") |
33 static TypeId tid = TypeId ("anon::DelayJitterEstimationTimestampTag") |
34 .SetParent<Tag> () |
34 .SetParent<Tag> () |
35 .AddConstructor<TimestampTag> () |
35 .AddConstructor<DelayJitterEstimationTimestampTag> () |
36 .AddAttribute ("CreationTime", |
36 .AddAttribute ("CreationTime", |
37 "The time at which the timestamp was created", |
37 "The time at which the timestamp was created", |
38 ns3::StringValue ("0.0s"), |
38 StringValue ("0.0s"), |
39 ns3::MakeTimeAccessor (&TimestampTag::GetTxTime), |
39 MakeTimeAccessor (&DelayJitterEstimationTimestampTag::GetTxTime), |
40 ns3::MakeTimeChecker ()) |
40 MakeTimeChecker ()) |
41 ; |
41 ; |
42 return tid; |
42 return tid; |
43 } |
43 } |
44 ns3::TypeId |
44 TypeId |
45 TimestampTag::GetInstanceTypeId (void) const |
45 DelayJitterEstimationTimestampTag::GetInstanceTypeId (void) const |
46 { |
46 { |
47 return GetTypeId (); |
47 return GetTypeId (); |
48 } |
48 } |
49 |
49 |
50 uint32_t |
50 uint32_t |
51 TimestampTag::GetSerializedSize (void) const |
51 DelayJitterEstimationTimestampTag::GetSerializedSize (void) const |
52 { |
52 { |
53 return 8; |
53 return 8; |
54 } |
54 } |
55 void |
55 void |
56 TimestampTag::Serialize (ns3::TagBuffer i) const |
56 DelayJitterEstimationTimestampTag::Serialize (TagBuffer i) const |
57 { |
57 { |
58 i.WriteU64 (m_creationTime); |
58 i.WriteU64 (m_creationTime); |
59 } |
59 } |
60 void |
60 void |
61 TimestampTag::Deserialize (ns3::TagBuffer i) |
61 DelayJitterEstimationTimestampTag::Deserialize (TagBuffer i) |
62 { |
62 { |
63 m_creationTime = i.ReadU64 (); |
63 m_creationTime = i.ReadU64 (); |
64 } |
64 } |
65 ns3::Time |
65 Time |
66 TimestampTag::GetTxTime (void) const |
66 DelayJitterEstimationTimestampTag::GetTxTime (void) const |
67 { |
67 { |
68 return ns3::TimeStep (m_creationTime); |
68 return TimeStep (m_creationTime); |
69 } |
69 } |
70 |
|
71 } |
|
72 |
|
73 namespace ns3 { |
|
74 |
70 |
75 DelayJitterEstimation::DelayJitterEstimation () |
71 DelayJitterEstimation::DelayJitterEstimation () |
76 : m_previousRx (Simulator::Now ()), |
72 : m_previousRx (Simulator::Now ()), |
77 m_previousRxTx (Simulator::Now ()), |
73 m_previousRxTx (Simulator::Now ()), |
78 m_jitter (Seconds (0.0)), |
74 m_jitter (Seconds (0.0)), |
79 m_delay (Seconds (0.0)) |
75 m_delay (Seconds (0.0)) |
80 {} |
76 {} |
81 void |
77 void |
82 DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet) |
78 DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet) |
83 { |
79 { |
84 TimestampTag tag; |
80 DelayJitterEstimationTimestampTag tag; |
85 packet->AddTag (tag); |
81 packet->AddTag (tag); |
86 } |
82 } |
87 void |
83 void |
88 DelayJitterEstimation::RecordRx (Ptr<const Packet> packet) |
84 DelayJitterEstimation::RecordRx (Ptr<const Packet> packet) |
89 { |
85 { |
90 TimestampTag tag; |
86 DelayJitterEstimationTimestampTag tag; |
91 bool found; |
87 bool found; |
92 found = packet->FindFirstMatchingTag (tag); |
88 found = packet->FindFirstMatchingTag (tag); |
93 if (!found) |
89 if (!found) |
94 { |
90 { |
95 return; |
91 return; |