A Discrete-Event Network Simulator
API
tcp-westwood-plus.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-plus.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 
41 NS_LOG_COMPONENT_DEFINE("TcpWestwoodPlus");
42 
43 namespace ns3
44 {
45 
46 NS_OBJECT_ENSURE_REGISTERED(TcpWestwoodPlus);
47 
48 TypeId
50 {
51  static TypeId tid =
52  TypeId("ns3::TcpWestwoodPlus")
54  .SetGroupName("Internet")
55  .AddConstructor<TcpWestwoodPlus>()
56  .AddAttribute(
57  "FilterType",
58  "Use this to choose no filter or Tustin's approximation filter",
62  .AddTraceSource("EstimatedBW",
63  "The estimated bandwidth",
65  "ns3::TracedValueCallback::DataRate");
66  return tid;
67 }
68 
70  : TcpNewReno(),
71  m_currentBW(0),
72  m_lastSampleBW(0),
73  m_lastBW(0),
74  m_ackedSegments(0),
75  m_IsCount(false),
76  m_lastAck(0)
77 {
78  NS_LOG_FUNCTION(this);
79 }
80 
82  : TcpNewReno(sock),
83  m_currentBW(sock.m_currentBW),
84  m_lastSampleBW(sock.m_lastSampleBW),
85  m_lastBW(sock.m_lastBW),
86  m_fType(sock.m_fType),
87  m_IsCount(sock.m_IsCount)
88 {
89  NS_LOG_FUNCTION(this);
90  NS_LOG_LOGIC("Invoked the copy constructor");
91 }
92 
94 {
95 }
96 
97 void
98 TcpWestwoodPlus::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t packetsAcked, const Time& rtt)
99 {
100  NS_LOG_FUNCTION(this << tcb << packetsAcked << rtt);
101 
102  if (rtt.IsZero())
103  {
104  NS_LOG_WARN("RTT measured is zero!");
105  return;
106  }
107 
108  m_ackedSegments += packetsAcked;
109 
110  if (!(rtt.IsZero() || m_IsCount))
111  {
112  m_IsCount = true;
115  }
116 }
117 
118 void
120 {
121  NS_LOG_FUNCTION(this);
122 
123  NS_ASSERT(!rtt.IsZero());
124 
126  m_IsCount = false;
127 
128  m_ackedSegments = 0;
129 
130  NS_LOG_LOGIC("Estimated BW: " << m_currentBW);
131 
132  // Filter the BW sample
133 
134  constexpr double ALPHA = 0.9;
135 
137  {
138  DataRate sample_bwe = m_currentBW;
139  m_currentBW = (m_lastBW * ALPHA) + (((sample_bwe + m_lastSampleBW) * 0.5) * (1 - ALPHA));
140  m_lastSampleBW = sample_bwe;
142  }
143 
144  NS_LOG_LOGIC("Estimated BW after filtering: " << m_currentBW);
145 }
146 
147 uint32_t
148 TcpWestwoodPlus::GetSsThresh(Ptr<const TcpSocketState> tcb, uint32_t bytesInFlight [[maybe_unused]])
149 {
150  uint32_t ssThresh = static_cast<uint32_t>((m_currentBW * tcb->m_minRtt) / 8.0);
151 
152  NS_LOG_LOGIC("CurrentBW: " << m_currentBW << " minRtt: " << tcb->m_minRtt
153  << " ssThresh: " << ssThresh);
154 
155  return std::max(2 * tcb->m_segmentSize, ssThresh);
156 }
157 
160 {
161  return CreateObject<TcpWestwoodPlus>(*this);
162 }
163 
164 } // 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
The NewReno implementation.
uint32_t m_segmentSize
Segment size.
An implementation of TCP Westwood+.
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network's bandwidth.
TracedValue< DataRate > m_currentBW
Current value of the estimated BW.
DataRate m_lastBW
Last bandwidth sample after being filtered.
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
DataRate m_lastSampleBW
Last bandwidth sample.
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
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.
FilterType m_fType
0 for none, 1 for Tustin
uint32_t m_ackedSegments
The number of segments ACKed between RTTs.
static TypeId GetTypeId()
Get the type ID.
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
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)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: enum.h:205
#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:46
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