A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Author: Tommaso Pecorella <tommaso.pecorella@unifi.it>
8 */
9
10#include "seq-ts-echo-header.h"
11
12#include "ns3/assert.h"
13#include "ns3/header.h"
14#include "ns3/log.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("SeqTsEchoHeader");
21
22NS_OBJECT_ENSURE_REGISTERED(SeqTsEchoHeader);
23
25 : m_seq(0),
26 m_tsValue(Simulator::Now()),
27 m_tsEchoReply(Seconds(0))
28{
29 NS_LOG_FUNCTION(this);
30}
31
32void
34{
35 NS_LOG_FUNCTION(this << seq);
36 m_seq = seq;
37}
38
41{
42 NS_LOG_FUNCTION(this);
43 return m_seq;
44}
45
46void
48{
49 NS_LOG_FUNCTION(this << ts);
50 m_tsValue = ts;
51}
52
53Time
55{
56 NS_LOG_FUNCTION(this);
57 return m_tsValue;
58}
59
60void
66
67Time
73
76{
77 static TypeId tid = TypeId("ns3::SeqTsEchoHeader")
79 .SetGroupName("Applications")
80 .AddConstructor<SeqTsEchoHeader>();
81 return tid;
82}
83
86{
87 return GetTypeId();
88}
89
90void
91SeqTsEchoHeader::Print(std::ostream& os) const
92{
93 NS_LOG_FUNCTION(this << &os);
94 os << "(seq=" << m_seq << " Tx time=" << m_tsValue.As(Time::S)
95 << " Rx time=" << m_tsEchoReply.As(Time::S) << ")";
96}
97
100{
101 NS_LOG_FUNCTION(this);
102 return 4 + 8 + 8;
103}
104
105void
114
117{
118 NS_LOG_FUNCTION(this << &start);
119 Buffer::Iterator i = start;
120 m_seq = i.ReadNtohU32();
121 m_tsValue = TimeStep(i.ReadNtohU64());
122 m_tsEchoReply = TimeStep(i.ReadNtohU64());
123 return GetSerializedSize();
124}
125
126} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteHtonU64(uint64_t data)
Definition buffer.cc:923
uint64_t ReadNtohU64()
Definition buffer.cc:1030
uint32_t ReadNtohU32()
Definition buffer.h:967
void WriteHtonU32(uint32_t data)
Definition buffer.h:922
Protocol header serialization and deserialization.
Definition header.h:33
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 m_seq
Sequence number.
void SetSeq(uint32_t seq)
void Serialize(Buffer::Iterator start) const override
static TypeId GetTypeId()
Get the type ID.
uint32_t Deserialize(Buffer::Iterator start) override
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:57
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
Definition time.cc:404
@ S
second
Definition nstime.h:105
int64_t GetTimeStep() const
Get the raw time value, in the current resolution unit.
Definition nstime.h:434
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Time Now()
create an ns3::Time instance which contains the current simulation time.
Definition simulator.cc:294
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Every class exported by the ns3 library is enclosed in the ns3 namespace.