A Discrete-Event Network Simulator
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
13namespace ns3
14{
15
16NS_LOG_COMPONENT_DEFINE("TcpOptionTS");
17
19
21 : TcpOption(),
22 m_timestamp(0),
23 m_echo(0)
24{
25}
26
30
33{
34 static TypeId tid = TypeId("ns3::TcpOptionTS")
36 .SetGroupName("Internet")
37 .AddConstructor<TcpOptionTS>();
38 return tid;
39}
40
43{
44 return GetTypeId();
45}
46
47void
48TcpOptionTS::Print(std::ostream& os) const
49{
50 os << m_timestamp << ";" << m_echo;
51}
52
55{
56 return 10;
57}
58
59void
61{
62 Buffer::Iterator i = start;
63 i.WriteU8(GetKind()); // Kind
64 i.WriteU8(10); // Length
65 i.WriteHtonU32(m_timestamp); // Local timestamp
66 i.WriteHtonU32(m_echo); // Echo timestamp
67}
68
71{
72 Buffer::Iterator i = start;
73
74 uint8_t readKind = i.ReadU8();
75 if (readKind != GetKind())
76 {
77 NS_LOG_WARN("Malformed Timestamp option");
78 return 0;
79 }
80
81 uint8_t size = i.ReadU8();
82 if (size != 10)
83 {
84 NS_LOG_WARN("Malformed Timestamp option");
85 return 0;
86 }
88 m_echo = i.ReadNtohU32();
89 return GetSerializedSize();
90}
91
92uint8_t
94{
95 return TcpOption::TS;
96}
97
100{
101 return m_timestamp;
102}
103
106{
107 return m_echo;
108}
109
110void
115
116void
118{
119 m_echo = ts;
120}
121
124{
125 uint64_t now = (uint64_t)Simulator::Now().GetMilliSeconds();
126
127 // high: (now & 0xFFFFFFFF00000000ULL) >> 32;
128 // low: now & 0xFFFFFFFF
129 return (now & 0xFFFFFFFF);
130}
131
132Time
134{
135 uint64_t now64 = (uint64_t)Simulator::Now().GetMilliSeconds();
136 uint32_t now32 = now64 & 0xFFFFFFFF;
137
138 Time ret = Seconds(0.0);
139 if (now32 > echoTime)
140 {
141 ret = MilliSeconds(now32 - echoTime);
142 }
143
144 return ret;
145}
146
147} // namespace ns3
iterator in a Buffer instance
Definition buffer.h:89
void WriteU8(uint8_t data)
Definition buffer.h:870
uint32_t ReadNtohU32()
Definition buffer.h:967
void WriteHtonU32(uint32_t data)
Definition buffer.h:922
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
Base class for all kinds of TCP options.
Definition tcp-option.h:27
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323
uint8_t GetKind() const override
Get the ‘kind’ (as in RFC 793 ) of this option.
void SetTimestamp(uint32_t ts)
Set the timestamp stored in the Option.
TypeId GetInstanceTypeId() const override
Get the most derived TypeId for this Object.
static Time ElapsedTimeFromTsValue(uint32_t echoTime)
Estimate the Time elapsed from a TS echo value.
uint32_t GetSerializedSize() const override
Returns number of bytes required for Option serialization.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetTimestamp() const
Get the timestamp stored in the Option.
uint32_t Deserialize(Buffer::Iterator start) override
Deserialize the Option from a buffer iterator.
uint32_t m_timestamp
local timestamp
~TcpOptionTS() override
uint32_t GetEcho() const
Get the timestamp echo stored in the Option.
static uint32_t NowToTsValue()
Return an uint32_t value which represent "now".
void Serialize(Buffer::Iterator start) const override
Serialize the Option to a buffer iterator.
uint32_t m_echo
echo timestamp
void SetEcho(uint32_t ts)
Set the timestamp echo stored in the Option.
void Print(std::ostream &os) const override
Print the Option contents.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
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_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1308
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.