src/contrib/delay-jitter-estimation.cc
changeset 3038 5962e2962fa9
parent 2287 363c7065ce0e
child 3040 e11e106c7c19
equal deleted inserted replaced
3037:b0f12f3a75b3 3038:5962e2962fa9
     1 
     1 
     2 #include "delay-jitter-estimation.h"
     2 #include "delay-jitter-estimation.h"
     3 #include "ns3/tag.h"
     3 #include "ns3/mtag.h"
     4 #include "ns3/simulator.h"
     4 #include "ns3/simulator.h"
       
     5 #include "ns3/string.h"
     5 
     6 
     6 namespace {
     7 namespace {
     7 
     8 
     8 class TimestampTag : public ns3::Tag
     9 class TimestampTag : public ns3::Mtag
     9 {
    10 {
    10 public:
    11 public:
    11   TimestampTag ();
    12   TimestampTag ();
    12   static uint32_t GetUid (void);
    13   static ns3::TypeId GetTypeId (void);
    13   void Print (std::ostream &os) const;
    14   virtual ns3::TypeId GetInstanceTypeId (void) const;
    14   void Serialize (ns3::Buffer::Iterator start) const;
    15 
    15   uint32_t Deserialize (ns3::Buffer::Iterator start);
    16   virtual uint32_t GetSerializedSize (void) const;
    16   uint32_t GetSerializedSize (void) const;
    17   virtual void Serialize (ns3::MtagBuffer i) const;
       
    18   virtual void Deserialize (ns3::MtagBuffer i);
       
    19 
    17 
    20 
    18   ns3::Time GetTxTime (void) const;
    21   ns3::Time GetTxTime (void) const;
    19 private:
    22 private:
    20   uint64_t m_creationTime;
    23   uint64_t m_creationTime;
    21 };
    24 };
    22 
    25 
    23 TimestampTag::TimestampTag ()
    26 TimestampTag::TimestampTag ()
    24   : m_creationTime (ns3::Simulator::Now ().GetTimeStep ())
    27   : m_creationTime (ns3::Simulator::Now ().GetTimeStep ())
    25 {}
    28 {}
    26 uint32_t 
    29 
    27 TimestampTag::GetUid (void)
    30 ns3::TypeId 
       
    31 TimestampTag::GetTypeId (void)
    28 {
    32 {
    29   static uint32_t uid = ns3::Tag::AllocateUid<TimestampTag> ("mathieu.paper.TimestampTag");
    33   static ns3::TypeId tid = ns3::TypeId ("anon::TimestampTag")
    30   return uid;
    34     .SetParent<Mtag> ()
       
    35     .AddConstructor<TimestampTag> ()
       
    36     .AddAttribute ("CreationTime",
       
    37 		   "The time at which the timestamp was created",
       
    38 		   ns3::StringValue ("0.0s"),
       
    39 		   ns3::MakeTimeAccessor (&TimestampTag::GetTxTime),
       
    40 		   ns3::MakeTimeChecker ())
       
    41     ;
       
    42   return tid;
    31 }
    43 }
    32 void 
    44 ns3::TypeId 
    33 TimestampTag::Print (std::ostream &os) const
    45 TimestampTag::GetInstanceTypeId (void) const
    34 {
    46 {
    35   os << ns3::TimeStep (m_creationTime);
    47   return GetTypeId ();
    36 }
    48 }
    37 void 
    49 
    38 TimestampTag::Serialize (ns3::Buffer::Iterator start) const
       
    39 {}
       
    40 uint32_t 
       
    41 TimestampTag::Deserialize (ns3::Buffer::Iterator start)
       
    42 {
       
    43   return 0;
       
    44 }
       
    45 uint32_t 
    50 uint32_t 
    46 TimestampTag::GetSerializedSize (void) const
    51 TimestampTag::GetSerializedSize (void) const
    47 {
    52 {
    48   return 0;
    53   return 8;
       
    54 }
       
    55 void 
       
    56 TimestampTag::Serialize (ns3::MtagBuffer i) const
       
    57 {
       
    58   i.WriteU64 (m_creationTime);
       
    59 }
       
    60 void 
       
    61 TimestampTag::Deserialize (ns3::MtagBuffer i)
       
    62 {
       
    63   m_creationTime = i.ReadU64 ();
    49 }
    64 }
    50 ns3::Time 
    65 ns3::Time 
    51 TimestampTag::GetTxTime (void) const
    66 TimestampTag::GetTxTime (void) const
    52 {
    67 {
    53   return ns3::TimeStep (m_creationTime);
    68   return ns3::TimeStep (m_creationTime);
    65 {}
    80 {}
    66 void 
    81 void 
    67 DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet)
    82 DelayJitterEstimation::PrepareTx (Ptr<const Packet> packet)
    68 {
    83 {
    69   TimestampTag tag;
    84   TimestampTag tag;
    70   packet->AddTag (tag);
    85   packet->AddMtag (tag);
    71 }
    86 }
    72 void 
    87 void 
    73 DelayJitterEstimation::RecordRx (Ptr<const Packet> packet)
    88 DelayJitterEstimation::RecordRx (Ptr<const Packet> packet)
    74 {
    89 {
    75   TimestampTag tag;
    90   TimestampTag tag;
    76   bool found;
    91   bool found;
    77   found = packet->PeekTag (tag);
    92   found = packet->FindFirstMatchingTag (tag);
    78   if (!found)
    93   if (!found)
    79     {
    94     {
    80       return;
    95       return;
    81     }
    96     }
    82   tag.GetTxTime ();
    97   tag.GetTxTime ();