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