A Discrete-Event Network Simulator
API
tcp-option-ts.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2011 Adrian Sai-wah Tam
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Adrian Sai-wah Tam <adrian.sw.tam@gmail.com>
19 */
20
21#include "tcp-option-ts.h"
22#include "ns3/log.h"
23
24namespace ns3 {
25
26NS_LOG_COMPONENT_DEFINE ("TcpOptionTS");
27
28NS_OBJECT_ENSURE_REGISTERED (TcpOptionTS);
29
31 : TcpOption (),
32 m_timestamp (0),
33 m_echo (0)
34{
35}
36
38{
39}
40
43{
44 static TypeId tid = TypeId ("ns3::TcpOptionTS")
46 .SetGroupName ("Internet")
47 .AddConstructor<TcpOptionTS> ()
48 ;
49 return tid;
50}
51
54{
55 return GetTypeId ();
56}
57
58void
59TcpOptionTS::Print (std::ostream &os) const
60{
61 os << m_timestamp << ";" << m_echo;
62}
63
66{
67 return 10;
68}
69
70void
72{
74 i.WriteU8 (GetKind ()); // Kind
75 i.WriteU8 (10); // Length
76 i.WriteHtonU32 (m_timestamp); // Local timestamp
77 i.WriteHtonU32 (m_echo); // Echo timestamp
78}
79
82{
84
85 uint8_t readKind = i.ReadU8 ();
86 if (readKind != GetKind ())
87 {
88 NS_LOG_WARN ("Malformed Timestamp option");
89 return 0;
90 }
91
92 uint8_t size = i.ReadU8 ();
93 if (size != 10)
94 {
95 NS_LOG_WARN ("Malformed Timestamp option");
96 return 0;
97 }
99 m_echo = i.ReadNtohU32 ();
100 return GetSerializedSize ();
101}
102
103uint8_t
105{
106 return TcpOption::TS;
107}
108
111{
112 return m_timestamp;
113}
114
117{
118 return m_echo;
119}
120
121void
123{
124 m_timestamp = ts;
125}
126
127void
129{
130 m_echo = ts;
131}
132
135{
136 uint64_t now = (uint64_t) Simulator::Now ().GetMilliSeconds ();
137
138 // high: (now & 0xFFFFFFFF00000000ULL) >> 32;
139 // low: now & 0xFFFFFFFF
140 return (now & 0xFFFFFFFF);
141}
142
143Time
145{
146 uint64_t now64 = (uint64_t) Simulator::Now ().GetMilliSeconds ();
147 uint32_t now32 = now64 & 0xFFFFFFFF;
148
149 Time ret = Seconds (0.0);
150 if (now32 > echoTime)
151 {
152 ret = MilliSeconds (now32 - echoTime);
153 }
154
155 return ret;
156}
157
158} // namespace ns3
iterator in a Buffer instance
Definition: buffer.h:99
void WriteU8(uint8_t data)
Definition: buffer.h:869
uint8_t ReadU8(void)
Definition: buffer.h:1021
void WriteHtonU32(uint32_t data)
Definition: buffer.h:924
uint32_t ReadNtohU32(void)
Definition: buffer.h:970
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
Base class for all kinds of TCP options.
Definition: tcp-option.h:37
Defines the TCP option of kind 8 (timestamp option) as in RFC 1323
Definition: tcp-option-ts.h:36
void SetTimestamp(uint32_t ts)
Set the timestamp stored in the Option.
virtual void Print(std::ostream &os) const
Print the Option contents.
virtual TypeId GetInstanceTypeId(void) const
Get the most derived TypeId for this Object.
virtual uint8_t GetKind(void) const
Get the ‘kind’ (as in RFC 793) of this option.
static Time ElapsedTimeFromTsValue(uint32_t echoTime)
Estimate the Time elapsed from a TS echo value.
static TypeId GetTypeId(void)
Get the type ID.
virtual void Serialize(Buffer::Iterator start) const
Serialize the Option to a buffer iterator.
uint32_t GetEcho(void) const
Get the timestamp echo stored in the Option.
uint32_t m_timestamp
local timestamp
virtual uint32_t GetSerializedSize(void) const
Returns number of bytes required for Option serialization.
uint32_t GetTimestamp(void) const
Get the timestamp stored in the Option.
static uint32_t NowToTsValue()
Return an uint32_t value which represent "now".
uint32_t m_echo
echo timestamp
void SetEcho(uint32_t ts)
Set the timestamp echo stored in the Option.
virtual uint32_t Deserialize(Buffer::Iterator start)
Deserialize the Option from a buffer iterator.
virtual ~TcpOptionTS()
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:384
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_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:266
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition: nstime.h:1245
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1253
Every class exported by the ns3 library is enclosed in the ns3 namespace.
def start()
Definition: core.py:1852