A Discrete-Event Network Simulator
API
seq-ts-echo-header.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 INRIA
4  * Copyright (c) 2016 Universita' di Firenze (added echo fields)
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
20  */
21 
22 #include "ns3/assert.h"
23 #include "ns3/log.h"
24 #include "ns3/header.h"
25 #include "ns3/simulator.h"
26 #include "seq-ts-echo-header.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("SeqTsEchoHeader");
31 
32 NS_OBJECT_ENSURE_REGISTERED (SeqTsEchoHeader);
33 
35  : m_seq (0),
36  m_tsValue (Simulator::Now ()),
37  m_tsEchoReply (Seconds (0))
38 {
39  NS_LOG_FUNCTION (this);
40 }
41 
42 void
44 {
45  NS_LOG_FUNCTION (this << seq);
46  m_seq = seq;
47 }
48 
49 uint32_t
51 {
52  NS_LOG_FUNCTION (this);
53  return m_seq;
54 }
55 
56 void
58 {
59  NS_LOG_FUNCTION (this << ts);
60  m_tsValue = ts;
61 }
62 
63 Time
65 {
66  NS_LOG_FUNCTION (this);
67  return m_tsValue;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this << ts);
74  m_tsEchoReply = ts;
75 }
76 
77 Time
79 {
80  NS_LOG_FUNCTION (this);
81  return m_tsEchoReply;
82 }
83 
84 TypeId
86 {
87  static TypeId tid = TypeId ("ns3::SeqTsEchoHeader")
88  .SetParent<Header> ()
89  .SetGroupName ("Applications")
90  .AddConstructor<SeqTsEchoHeader> ()
91  ;
92  return tid;
93 }
94 
95 TypeId
97 {
98  return GetTypeId ();
99 }
100 
101 void
102 SeqTsEchoHeader::Print (std::ostream &os) const
103 {
104  NS_LOG_FUNCTION (this << &os);
105  os << "(seq=" << m_seq << " Tx time=" << m_tsValue.As (Time::S) << " Rx time=" << m_tsEchoReply.As (Time::S) << ")";
106 }
107 
108 uint32_t
110 {
111  NS_LOG_FUNCTION (this);
112  return 4+8+8;
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << &start);
120  i.WriteHtonU32 (m_seq);
123 }
124 
125 uint32_t
127 {
128  NS_LOG_FUNCTION (this << &start);
130  m_seq = i.ReadNtohU32 ();
131  m_tsValue = TimeStep (i.ReadNtohU64 ());
132  m_tsEchoReply = TimeStep (i.ReadNtohU64 ());
133  return GetSerializedSize ();
134 }
135 
136 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
TimeWithUnit As(const enum Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition: time.cc:429
void WriteHtonU64(uint64_t data)
Definition: buffer.cc:940
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Control the scheduling of simulation events.
Definition: simulator.h:68
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t m_seq
Sequence number.
def start()
Definition: core.py:1855
uint64_t ReadNtohU64(void)
Definition: buffer.cc:1043
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual void Print(std::ostream &os) const override
virtual TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
void SetSeq(uint32_t seq)
Time m_tsEchoReply
Receiver&#39;s timestamp.
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
Time GetTsEchoReply(void) const
iterator in a Buffer instance
Definition: buffer.h:98
void SetTsEchoReply(Time ts)
Upon SeqTsEchoHeader reception, the host answers via echoing back the received timestamp.
static TypeId GetTypeId(void)
Get the type ID.
void SetTsValue(Time ts)
Set the sender&#39;s time value.
Packet header to carry sequence number and two timestamps.
Time m_tsValue
Sender&#39;s timestamp.
Time GetTsValue(void) const
virtual uint32_t GetSerializedSize(void) const override
uint32_t GetSeq(void) const
SeqTsEchoHeader()
constructor
Every class exported by the ns3 library is enclosed in the ns3 namespace.
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
virtual void Serialize(Buffer::Iterator start) const override
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1289
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
second
Definition: nstime.h:115
a unique identifier for an interface.
Definition: type-id.h:58
virtual uint32_t Deserialize(Buffer::Iterator start) override
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:416