A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
Loading...
Searching...
No Matches
tcp-option-ts.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2011 Adrian Sai-wah Tam
3
*
4
* SPDX-License-Identifier: GPL-2.0-only
5
*
6
* Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
7
*/
8
9
#include "
tcp-option-ts.h
"
10
11
#include "ns3/log.h"
12
13
namespace
ns3
14
{
15
16
NS_LOG_COMPONENT_DEFINE
(
"TcpOptionTS"
);
17
18
NS_OBJECT_ENSURE_REGISTERED
(
TcpOptionTS
);
19
20
TcpOptionTS::TcpOptionTS
()
21
:
TcpOption
(),
22
m_timestamp
(0),
23
m_echo
(0)
24
{
25
}
26
27
TcpOptionTS::~TcpOptionTS
()
28
{
29
}
30
31
TypeId
32
TcpOptionTS::GetTypeId
()
33
{
34
static
TypeId
tid =
TypeId
(
"ns3::TcpOptionTS"
)
35
.
SetParent
<
TcpOption
>()
36
.SetGroupName(
"Internet"
)
37
.AddConstructor<
TcpOptionTS
>();
38
return
tid;
39
}
40
41
void
42
TcpOptionTS::Print
(std::ostream& os)
const
43
{
44
os <<
m_timestamp
<<
";"
<<
m_echo
;
45
}
46
47
uint32_t
48
TcpOptionTS::GetSerializedSize
()
const
49
{
50
return
10;
51
}
52
53
void
54
TcpOptionTS::Serialize
(
Buffer::Iterator
start)
const
55
{
56
Buffer::Iterator
i = start;
57
i.
WriteU8
(
GetKind
());
// Kind
58
i.
WriteU8
(10);
// Length
59
i.
WriteHtonU32
(
m_timestamp
);
// Local timestamp
60
i.
WriteHtonU32
(
m_echo
);
// Echo timestamp
61
}
62
63
uint32_t
64
TcpOptionTS::Deserialize
(
Buffer::Iterator
start)
65
{
66
Buffer::Iterator
i = start;
67
68
uint8_t readKind = i.
ReadU8
();
69
if
(readKind !=
GetKind
())
70
{
71
NS_LOG_WARN
(
"Malformed Timestamp option"
);
72
return
0;
73
}
74
75
uint8_t size = i.
ReadU8
();
76
if
(size != 10)
77
{
78
NS_LOG_WARN
(
"Malformed Timestamp option"
);
79
return
0;
80
}
81
m_timestamp
= i.
ReadNtohU32
();
82
m_echo
= i.
ReadNtohU32
();
83
return
GetSerializedSize
();
84
}
85
86
uint8_t
87
TcpOptionTS::GetKind
()
const
88
{
89
return
TcpOption::TS
;
90
}
91
92
uint32_t
93
TcpOptionTS::GetTimestamp
()
const
94
{
95
return
m_timestamp
;
96
}
97
98
uint32_t
99
TcpOptionTS::GetEcho
()
const
100
{
101
return
m_echo
;
102
}
103
104
void
105
TcpOptionTS::SetTimestamp
(
uint32_t
ts)
106
{
107
m_timestamp
= ts;
108
}
109
110
void
111
TcpOptionTS::SetEcho
(
uint32_t
ts)
112
{
113
m_echo
= ts;
114
}
115
116
uint32_t
117
TcpOptionTS::NowToTsValue
()
118
{
119
uint64_t now = (uint64_t)
Simulator::Now
().GetMilliSeconds();
120
121
// high: (now & 0xFFFFFFFF00000000ULL) >> 32;
122
// low: now & 0xFFFFFFFF
123
return
(now & 0xFFFFFFFF);
124
}
125
126
Time
127
TcpOptionTS::ElapsedTimeFromTsValue
(
uint32_t
echoTime)
128
{
129
uint64_t now64 = (uint64_t)
Simulator::Now
().GetMilliSeconds();
130
uint32_t
now32 = now64 & 0xFFFFFFFF;
131
132
Time
ret;
133
if
(now32 > echoTime)
134
{
135
ret =
MilliSeconds
(now32 - echoTime);
136
}
137
138
return
ret;
139
}
140
141
}
// namespace ns3
ns3::Buffer::Iterator
iterator in a Buffer instance
Definition
buffer.h:89
ns3::Buffer::Iterator::ReadU8
uint8_t ReadU8()
Definition
buffer.h:1016
ns3::Buffer::Iterator::WriteU8
void WriteU8(uint8_t data)
Definition
buffer.h:870
ns3::Buffer::Iterator::ReadNtohU32
uint32_t ReadNtohU32()
Definition
buffer.h:967
ns3::Buffer::Iterator::WriteHtonU32
void WriteHtonU32(uint32_t data)
Definition
buffer.h:922
ns3::Simulator::Now
static Time Now()
Return the current simulation virtual time.
Definition
simulator.cc:197
ns3::TcpOption::TS
@ TS
TS.
Definition
tcp-option.h:51
ns3::TcpOption::TcpOption
TcpOption()
Definition
tcp-option.cc:29
ns3::TcpOptionTS
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323.
Definition
tcp-option-ts.h:26
ns3::TcpOptionTS::GetKind
uint8_t GetKind() const override
Definition
tcp-option-ts.cc:87
ns3::TcpOptionTS::SetTimestamp
void SetTimestamp(uint32_t ts)
Set the timestamp stored in the Option.
Definition
tcp-option-ts.cc:105
ns3::TcpOptionTS::TcpOptionTS
TcpOptionTS()
Definition
tcp-option-ts.cc:20
ns3::TcpOptionTS::ElapsedTimeFromTsValue
static Time ElapsedTimeFromTsValue(uint32_t echoTime)
Estimate the Time elapsed from a TS echo value.
Definition
tcp-option-ts.cc:127
ns3::TcpOptionTS::GetSerializedSize
uint32_t GetSerializedSize() const override
Get the `kind' (as in \RFC{793}) of this option.
Definition
tcp-option-ts.cc:48
ns3::TcpOptionTS::GetTypeId
static TypeId GetTypeId()
Get the type ID.
Definition
tcp-option-ts.cc:32
ns3::TcpOptionTS::GetTimestamp
uint32_t GetTimestamp() const
Get the timestamp stored in the Option.
Definition
tcp-option-ts.cc:93
ns3::TcpOptionTS::Deserialize
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
Definition
tcp-option-ts.cc:64
ns3::TcpOptionTS::m_timestamp
uint32_t m_timestamp
local timestamp
Definition
tcp-option-ts.h:93
ns3::TcpOptionTS::~TcpOptionTS
~TcpOptionTS() override
Definition
tcp-option-ts.cc:27
ns3::TcpOptionTS::GetEcho
uint32_t GetEcho() const
Get the timestamp echo stored in the Option.
Definition
tcp-option-ts.cc:99
ns3::TcpOptionTS::NowToTsValue
static uint32_t NowToTsValue()
Return an uint32_t value which represent "now".
Definition
tcp-option-ts.cc:117
ns3::TcpOptionTS::Serialize
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
Definition
tcp-option-ts.cc:54
ns3::TcpOptionTS::m_echo
uint32_t m_echo
echo timestamp
Definition
tcp-option-ts.h:94
ns3::TcpOptionTS::SetEcho
void SetEcho(uint32_t ts)
Set the timestamp echo stored in the Option.
Definition
tcp-option-ts.cc:111
ns3::TcpOptionTS::Print
void Print(std::ostream &os) const override
Print the Option contents.
Definition
tcp-option-ts.cc:42
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition
nstime.h:96
ns3::TypeId
a unique identifier for an interface.
Definition
type-id.h:49
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition
type-id.cc:1001
uint32_t
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition
log.h:250
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition
object-base.h:35
ns3::MilliSeconds
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition
nstime.h:1381
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
tcp-option-ts.h
src
internet
model
tcp-option-ts.cc
Generated on
for ns-3 by
1.15.0