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
41void
42TcpOptionTS::Print(std::ostream& os) const
43{
44 os << m_timestamp << ";" << m_echo;
45}
46
49{
50 return 10;
51}
52
53void
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
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 }
82 m_echo = i.ReadNtohU32();
83 return GetSerializedSize();
84}
85
86uint8_t
88{
89 return TcpOption::TS;
90}
91
94{
95 return m_timestamp;
96}
97
100{
101 return m_echo;
102}
103
104void
109
110void
112{
113 m_echo = ts;
114}
115
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
126Time
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
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.
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:49
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 MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1357
Every class exported by the ns3 library is enclosed in the ns3 namespace.