A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 "ns3/log.h"
36#include "ns3/simulator.h"
37
38NS_LOG_COMPONENT_DEFINE("TcpWestwoodPlus");
39
40namespace ns3
41{
42
43NS_OBJECT_ENSURE_REGISTERED(TcpWestwoodPlus);
44
45TypeId
47{
48 static TypeId tid =
49 TypeId("ns3::TcpWestwoodPlus")
51 .SetGroupName("Internet")
52 .AddConstructor<TcpWestwoodPlus>()
53 .AddAttribute(
54 "FilterType",
55 "Use this to choose no filter or Tustin's approximation filter",
57 MakeEnumAccessor<FilterType>(&TcpWestwoodPlus::m_fType),
59 .AddTraceSource("EstimatedBW",
60 "The estimated bandwidth",
62 "ns3::TracedValueCallback::DataRate");
63 return tid;
64}
65
67 : TcpNewReno(),
68 m_currentBW(0),
69 m_lastSampleBW(0),
70 m_lastBW(0),
71 m_ackedSegments(0),
72 m_IsCount(false),
73 m_lastAck(0)
74{
75 NS_LOG_FUNCTION(this);
76}
77
79 : TcpNewReno(sock),
80 m_currentBW(sock.m_currentBW),
81 m_lastSampleBW(sock.m_lastSampleBW),
82 m_lastBW(sock.m_lastBW),
83 m_fType(sock.m_fType),
84 m_IsCount(sock.m_IsCount)
85{
86 NS_LOG_FUNCTION(this);
87 NS_LOG_LOGIC("Invoked the copy constructor");
88}
89
91{
92}
93
94void
96{
97 NS_LOG_FUNCTION(this << tcb << packetsAcked << rtt);
98
99 if (rtt.IsZero())
100 {
101 NS_LOG_WARN("RTT measured is zero!");
102 return;
103 }
104
105 m_ackedSegments += packetsAcked;
106
107 if (!(rtt.IsZero() || m_IsCount))
108 {
109 m_IsCount = true;
112 }
113}
114
115void
117{
118 NS_LOG_FUNCTION(this);
119
120 NS_ASSERT(!rtt.IsZero());
121
122 m_currentBW = DataRate(m_ackedSegments * tcb->m_segmentSize * 8.0 / rtt.GetSeconds());
123 m_IsCount = false;
124
125 m_ackedSegments = 0;
126
127 NS_LOG_LOGIC("Estimated BW: " << m_currentBW);
128
129 // Filter the BW sample
130
131 constexpr double ALPHA = 0.9;
132
134 {
135 DataRate sample_bwe = m_currentBW;
136 m_currentBW = (m_lastBW * ALPHA) + (((sample_bwe + m_lastSampleBW) * 0.5) * (1 - ALPHA));
137 m_lastSampleBW = sample_bwe;
139 }
140
141 NS_LOG_LOGIC("Estimated BW after filtering: " << m_currentBW);
142}
143
146{
147 uint32_t ssThresh = static_cast<uint32_t>((m_currentBW * tcb->m_minRtt) / 8.0);
148
149 NS_LOG_LOGIC("CurrentBW: " << m_currentBW << " minRtt: " << tcb->m_minRtt
150 << " ssThresh: " << ssThresh);
151
152 return std::max(2 * tcb->m_segmentSize, ssThresh);
153}
154
157{
158 return CreateObject<TcpWestwoodPlus>(*this);
159}
160
161} // namespace ns3
Class for representing data rates.
Definition: data-rate.h:89
Hold variables of type enum.
Definition: enum.h:62
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:571
The NewReno implementation.
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:403
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:315
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#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
#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
#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(T v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:189