A Discrete-Event Network Simulator
API
tcp-westwood.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 ResiliNets, ITTC, University of Kansas
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  * Authors: Siddharth Gangadhar <siddharth@ittc.ku.edu>,
19  * Truc Anh N. Nguyen <annguyen@ittc.ku.edu>,
20  * Greeshma Umapathi
21  *
22  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
23  * ResiliNets Research Group http://wiki.ittc.ku.edu/resilinets
24  * Information and Telecommunication Technology Center (ITTC)
25  * and Department of Electrical Engineering and Computer Science
26  * The University of Kansas Lawrence, KS USA.
27  *
28  * Work supported in part by NSF FIND (Future Internet Design) Program
29  * under grant CNS-0626918 (Postmodern Internet Architecture),
30  * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
31  * US Department of Defense (DoD), and ITTC at The University of Kansas.
32  */
33 
34 #include "tcp-westwood.h"
35 #include "ns3/log.h"
36 #include "ns3/simulator.h"
37 #include "rtt-estimator.h"
38 #include "tcp-socket-base.h"
39 
40 NS_LOG_COMPONENT_DEFINE ("TcpWestwood");
41 
42 namespace ns3 {
43 
44 NS_OBJECT_ENSURE_REGISTERED (TcpWestwood);
45 
46 TypeId
48 {
49  static TypeId tid = TypeId("ns3::TcpWestwood")
51  .SetGroupName ("Internet")
52  .AddConstructor<TcpWestwood>()
53  .AddAttribute("FilterType", "Use this to choose no filter or Tustin's approximation filter",
56  .AddAttribute("ProtocolType", "Use this to let the code run as Westwood or WestwoodPlus",
60  .AddTraceSource("EstimatedBW", "The estimated bandwidth",
62  "ns3::TracedValueCallback::DataRate")
63  ;
64  return tid;
65 }
66 
68  TcpNewReno (),
69  m_currentBW (0),
70  m_lastSampleBW (0),
71  m_lastBW (0),
72  m_ackedSegments (0),
73  m_IsCount (false),
74  m_lastAck (0)
75 {
76  NS_LOG_FUNCTION (this);
77 }
78 
80  TcpNewReno (sock),
81  m_currentBW (sock.m_currentBW),
82  m_lastSampleBW (sock.m_lastSampleBW),
83  m_lastBW (sock.m_lastBW),
84  m_pType (sock.m_pType),
85  m_fType (sock.m_fType),
86  m_IsCount (sock.m_IsCount)
87 {
88  NS_LOG_FUNCTION (this);
89  NS_LOG_LOGIC ("Invoked the copy constructor");
90 }
91 
93 {
94 }
95 
96 void
97 TcpWestwood::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t packetsAcked,
98  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 
111  {
112  EstimateBW (rtt, tcb);
113  }
115  {
116  if (!(rtt.IsZero () || m_IsCount))
117  {
118  m_IsCount = true;
121  this, rtt, tcb);
122  }
123  }
124 }
125 
126 void
128 {
129  NS_LOG_FUNCTION (this);
130 
131  NS_ASSERT (!rtt.IsZero ());
132 
134  {
135  Time currentAck = Simulator::Now ();
136 
137  NS_ABORT_MSG_IF (currentAck == m_lastAck,
138  "This violates a model assumption and would lead to divide-by-zero; please report to ns-3 maintainers if this occurs.");
139 
140  m_currentBW = DataRate (m_ackedSegments * tcb->m_segmentSize * 8.0 / (currentAck - m_lastAck).GetSeconds ());
141  m_lastAck = currentAck;
142  }
144  {
145  m_currentBW = DataRate (m_ackedSegments * tcb->m_segmentSize * 8.0 / rtt.GetSeconds ());
146  m_IsCount = false;
147  }
148 
149  m_ackedSegments = 0;
150 
151  NS_LOG_LOGIC ("Estimated BW: " << m_currentBW);
152 
153  // Filter the BW sample
154 
155  constexpr double alpha = 0.9;
156 
158  {
159  DataRate sample_bwe = m_currentBW;
160  m_currentBW = (m_lastBW * alpha) + (((sample_bwe + m_lastSampleBW) * 0.5) * (1 - alpha));
161  m_lastSampleBW = sample_bwe;
163  }
164 
165  NS_LOG_LOGIC ("Estimated BW after filtering: " << m_currentBW);
166 }
167 
168 uint32_t
170  [[maybe_unused]] uint32_t bytesInFlight)
171 {
172  uint32_t ssThresh = static_cast<uint32_t> ((m_currentBW * tcb->m_minRtt) / 8.0);
173 
174  NS_LOG_LOGIC ("CurrentBW: " << m_currentBW <<
175  " minRtt: " << tcb->m_minRtt <<
176  " ssThresh: " << ssThresh);
177 
178  return std::max (2 * tcb->m_segmentSize, ssThresh);
179 }
180 
183 {
184  return CreateObject<TcpWestwood> (*this);
185 }
186 
187 } // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
Class for representing data rates.
Definition: data-rate.h:89
Hold variables of type enum.
Definition: enum.h:55
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:556
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
The NewReno implementation.
uint32_t m_segmentSize
Segment size.
An implementation of TCP Westwood and Westwood+.
Definition: tcp-westwood.h:67
TracedValue< DataRate > m_currentBW
Current value of the estimated BW.
Definition: tcp-westwood.h:126
enum ProtocolType m_pType
0 for Westwood, 1 for Westwood+
Definition: tcp-westwood.h:129
enum FilterType m_fType
0 for none, 1 for Tustin
Definition: tcp-westwood.h:130
bool m_IsCount
Start keeping track of m_ackedSegments for Westwood+ if TRUE.
Definition: tcp-westwood.h:133
DataRate m_lastSampleBW
Last bandwidth sample.
Definition: tcp-westwood.h:127
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network's bandwidth.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t packetsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-westwood.cc:97
DataRate m_lastBW
Last bandwidth sample after being filtered.
Definition: tcp-westwood.h:128
virtual ~TcpWestwood(void)
Definition: tcp-westwood.cc:92
Time m_lastAck
The last ACK time.
Definition: tcp-westwood.h:135
uint32_t m_ackedSegments
The number of segments ACKed between RTTs.
Definition: tcp-westwood.h:132
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
Definition: tcp-westwood.h:134
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-westwood.cc:47
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:379
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
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_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
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_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:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:265
void(* DataRate)(DataRate oldValue, DataRate newValue)
TracedValue callback signature for DataRate.
Definition: data-rate.h:329
#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:162
float alpha
Plot alpha value (transparency)