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
28namespace ns3 {
29
30NS_LOG_COMPONENT_DEFINE ("SeqTsEchoHeader");
31
32NS_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
42void
44{
45 NS_LOG_FUNCTION (this << seq);
46 m_seq = seq;
47}
48
51{
52 NS_LOG_FUNCTION (this);
53 return m_seq;
54}
55
56void
58{
59 NS_LOG_FUNCTION (this << ts);
60 m_tsValue = ts;
61}
62
63Time
65{
66 NS_LOG_FUNCTION (this);
67 return m_tsValue;
68}
69
70void
72{
73 NS_LOG_FUNCTION (this << ts);
74 m_tsEchoReply = ts;
75}
76
77Time
79{
80 NS_LOG_FUNCTION (this);
81 return m_tsEchoReply;
82}
83
86{
87 static TypeId tid = TypeId ("ns3::SeqTsEchoHeader")
88 .SetParent<Header> ()
89 .SetGroupName ("Applications")
90 .AddConstructor<SeqTsEchoHeader> ()
91 ;
92 return tid;
93}
94
97{
98 return GetTypeId ();
99}
100
101void
102SeqTsEchoHeader::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
110{
111 NS_LOG_FUNCTION (this);
112 return 4+8+8;
113}
114
115void
117{
118 NS_LOG_FUNCTION (this << &start);
123}
124
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
iterator in a Buffer instance
Definition: buffer.h:99
void WriteHtonU64(uint64_t data)
Definition: buffer.cc:941
uint64_t ReadNtohU64(void)
Definition: buffer.cc:1044
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
Protocol header serialization and deserialization.
Definition: header.h:43
Packet header to carry sequence number and two timestamps.
Time GetTsValue(void) const
virtual TypeId GetInstanceTypeId(void) const override
Get the most derived TypeId for this Object.
Time m_tsEchoReply
Receiver's timestamp.
Time m_tsValue
Sender's timestamp.
void SetTsValue(Time ts)
Set the sender's time value.
uint32_t m_seq
Sequence number.
virtual uint32_t GetSerializedSize(void) const override
void SetSeq(uint32_t seq)
virtual void Serialize(Buffer::Iterator start) const override
Time GetTsEchoReply(void) const
uint32_t GetSeq(void) const
virtual uint32_t Deserialize(Buffer::Iterator start) override
static TypeId GetTypeId(void)
Get the type ID.
void SetTsEchoReply(Time ts)
Upon SeqTsEchoHeader reception, the host answers via echoing back the received timestamp.
virtual void Print(std::ostream &os) const override
Control the scheduling of simulation events.
Definition: simulator.h:69
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
int64_t GetTimeStep(void) const
Get the raw time value, in the current resolution unit.
Definition: nstime.h:416
@ S
second
Definition: nstime.h:115
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:418
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:206
#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:45
Time Now(void)
create an ns3::Time instance which contains the current simulation time.
Definition: simulator.cc:287
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852