A Discrete-Event Network Simulator
API
tcp-westwood.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Siddharth Gangadhar <siddharth@ittc.ku.edu>,
18 * Truc Anh N. Nguyen <annguyen@ittc.ku.edu>,
19 * Greeshma Umapathi
20 *
21 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
22 * ResiliNets Research Group https://resilinets.org/
23 * Information and Telecommunication Technology Center (ITTC)
24 * and Department of Electrical Engineering and Computer Science
25 * The University of Kansas Lawrence, KS USA.
26 *
27 * Work supported in part by NSF FIND (Future Internet Design) Program
28 * under grant CNS-0626918 (Postmodern Internet Architecture),
29 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
30 * US Department of Defense (DoD), and ITTC at The University of Kansas.
31 */
32
33#include "tcp-westwood.h"
34
35#include "rtt-estimator.h"
36#include "tcp-socket-base.h"
37
38#include "ns3/log.h"
39#include "ns3/simulator.h"
40
41NS_LOG_COMPONENT_DEFINE("TcpWestwood");
42
43namespace ns3
44{
45
47
48TypeId
50{
51 static TypeId tid =
52 TypeId("ns3::TcpWestwood")
54 .SetGroupName("Internet")
55 .AddConstructor<TcpWestwood>()
56 .AddAttribute("FilterType",
57 "Use this to choose no filter or Tustin's approximation filter",
61 .AddAttribute("ProtocolType",
62 "Use this to let the code run as Westwood or WestwoodPlus",
66 "Westwood",
68 "WestwoodPlus"))
69 .AddTraceSource("EstimatedBW",
70 "The estimated bandwidth",
72 "ns3::TracedValueCallback::DataRate");
73 return tid;
74}
75
77 : TcpNewReno(),
78 m_currentBW(0),
79 m_lastSampleBW(0),
80 m_lastBW(0),
81 m_ackedSegments(0),
82 m_IsCount(false),
83 m_lastAck(0)
84{
85 NS_LOG_FUNCTION(this);
86}
87
89 : TcpNewReno(sock),
90 m_currentBW(sock.m_currentBW),
91 m_lastSampleBW(sock.m_lastSampleBW),
92 m_lastBW(sock.m_lastBW),
93 m_pType(sock.m_pType),
94 m_fType(sock.m_fType),
95 m_IsCount(sock.m_IsCount)
96{
97 NS_LOG_FUNCTION(this);
98 NS_LOG_LOGIC("Invoked the copy constructor");
99}
100
102{
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << tcb << packetsAcked << rtt);
109
110 if (rtt.IsZero())
111 {
112 NS_LOG_WARN("RTT measured is zero!");
113 return;
114 }
115
116 m_ackedSegments += packetsAcked;
117
119 {
120 EstimateBW(rtt, tcb);
121 }
123 {
124 if (!(rtt.IsZero() || m_IsCount))
125 {
126 m_IsCount = true;
129 }
130 }
131}
132
133void
135{
136 NS_LOG_FUNCTION(this);
137
138 NS_ASSERT(!rtt.IsZero());
139
141 {
142 Time currentAck = Simulator::Now();
143
144 NS_ABORT_MSG_IF(currentAck == m_lastAck,
145 "This violates a model assumption and would lead to divide-by-zero; please "
146 "report to ns-3 maintainers if this occurs.");
147
149 (currentAck - m_lastAck).GetSeconds());
150 m_lastAck = currentAck;
151 }
153 {
155 m_IsCount = false;
156 }
157
158 m_ackedSegments = 0;
159
160 NS_LOG_LOGIC("Estimated BW: " << m_currentBW);
161
162 // Filter the BW sample
163
164 constexpr double alpha = 0.9;
165
167 {
168 DataRate sample_bwe = m_currentBW;
169 m_currentBW = (m_lastBW * alpha) + (((sample_bwe + m_lastSampleBW) * 0.5) * (1 - alpha));
170 m_lastSampleBW = sample_bwe;
172 }
173
174 NS_LOG_LOGIC("Estimated BW after filtering: " << m_currentBW);
175}
176
179{
180 uint32_t ssThresh = static_cast<uint32_t>((m_currentBW * tcb->m_minRtt) / 8.0);
181
182 NS_LOG_LOGIC("CurrentBW: " << m_currentBW << " minRtt: " << tcb->m_minRtt
183 << " ssThresh: " << ssThresh);
184
185 return std::max(2 * tcb->m_segmentSize, ssThresh);
186}
187
190{
191 return CreateObject<TcpWestwood>(*this);
192}
193
194} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
Class for representing data rates.
Definition: data-rate.h:90
Hold variables of type enum.
Definition: enum.h:56
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:568
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:199
The NewReno implementation.
uint32_t m_segmentSize
Segment size.
An implementation of TCP Westwood and Westwood+.
Definition: tcp-westwood.h:68
TracedValue< DataRate > m_currentBW
Current value of the estimated BW.
Definition: tcp-westwood.h:125
enum ProtocolType m_pType
0 for Westwood, 1 for Westwood+
Definition: tcp-westwood.h:128
~TcpWestwood() override
enum FilterType m_fType
0 for none, 1 for Tustin
Definition: tcp-westwood.h:129
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t packetsAcked, const Time &rtt) override
Timing information on received ACK.
bool m_IsCount
Start keeping track of m_ackedSegments for Westwood+ if TRUE.
Definition: tcp-westwood.h:132
DataRate m_lastSampleBW
Last bandwidth sample.
Definition: tcp-westwood.h:126
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network's bandwidth.
DataRate m_lastBW
Last bandwidth sample after being filtered.
Definition: tcp-westwood.h:127
Time m_lastAck
The last ACK time.
Definition: tcp-westwood.h:134
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-westwood.cc:49
uint32_t m_ackedSegments
The number of segments ACKed between RTTs.
Definition: tcp-westwood.h:131
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
Definition: tcp-westwood.h:133
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:402
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:314
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:205
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:328
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:163