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::Double")
63  ;
64  return tid;
65 }
66 
68  TcpNewReno (),
69  m_currentBW (0),
70  m_lastSampleBW (0),
71  m_lastBW (0),
72  m_minRtt (Time (0)),
73  m_ackedSegments (0),
74  m_IsCount (false)
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_minRtt (Time (0)),
85  m_pType (sock.m_pType),
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 TcpWestwood::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t packetsAcked,
99  const Time& rtt)
100 {
101  NS_LOG_FUNCTION (this << tcb << packetsAcked << rtt);
102 
103  if (rtt.IsZero ())
104  {
105  NS_LOG_WARN ("RTT measured is zero!");
106  return;
107  }
108 
109  m_ackedSegments += packetsAcked;
110 
111  // Update minRtt
112  if (m_minRtt.IsZero ())
113  {
114  m_minRtt = rtt;
115  }
116  else
117  {
118  if (rtt < m_minRtt)
119  {
120  m_minRtt = rtt;
121  }
122  }
123 
124  NS_LOG_LOGIC ("MinRtt: " << m_minRtt.GetMilliSeconds () << "ms");
125 
127  {
128  EstimateBW (rtt, tcb);
129  }
131  {
132  if (!(rtt.IsZero () || m_IsCount))
133  {
134  m_IsCount = true;
137  this, rtt, tcb);
138  }
139  }
140 }
141 
142 void
144 {
145  NS_LOG_FUNCTION (this);
146 
147  NS_ASSERT (!rtt.IsZero ());
148 
149  m_currentBW = m_ackedSegments * tcb->m_segmentSize / rtt.GetSeconds ();
150 
152  {
153  m_IsCount = false;
154  }
155 
156  m_ackedSegments = 0;
157  NS_LOG_LOGIC ("Estimated BW: " << m_currentBW);
158 
159  // Filter the BW sample
160 
161  double alpha = 0.9;
162 
163  if (m_fType == TcpWestwood::NONE)
164  {
165  }
166  else if (m_fType == TcpWestwood::TUSTIN)
167  {
168  double sample_bwe = m_currentBW;
169  m_currentBW = (alpha * m_lastBW) + ((1 - alpha) * ((sample_bwe + m_lastSampleBW) / 2));
170  m_lastSampleBW = sample_bwe;
172  }
173 
174  NS_LOG_LOGIC ("Estimated BW after filtering: " << m_currentBW);
175 }
176 
177 uint32_t
179  uint32_t bytesInFlight)
180 {
181  (void) bytesInFlight;
182  NS_LOG_LOGIC ("CurrentBW: " << m_currentBW << " minRtt: " <<
183  m_minRtt << " ssthresh: " <<
184  m_currentBW * static_cast<double> (m_minRtt.GetSeconds ()));
185 
186  return std::max (2*tcb->m_segmentSize,
187  uint32_t (m_currentBW * static_cast<double> (m_minRtt.GetSeconds ())));
188 }
189 
192 {
193  return CreateObject<TcpWestwood> (*this);
194 }
195 
196 } // namespace ns3
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
Definition: tcp-westwood.h:134
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
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:209
double m_lastBW
Last bandwidth sample after being filtered.
Definition: tcp-westwood.h:127
bool IsZero(void) const
Definition: nstime.h:274
#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
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
The NewReno implementation.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t packetsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-westwood.cc:98
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:341
enum FilterType m_fType
0 for none, 1 for Tustin
Definition: tcp-westwood.h:130
Hold variables of type enum.
Definition: enum.h:54
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
#define max(a, b)
Definition: 80211b.c:45
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-westwood.cc:47
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
virtual ~TcpWestwood(void)
Definition: tcp-westwood.cc:93
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
int m_ackedSegments
The number of segments ACKed between RTTs.
Definition: tcp-westwood.h:132
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:228
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
double m_lastSampleBW
Last bandwidth sample.
Definition: tcp-westwood.h:126
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network's bandwidth.
TracedValue< double > m_currentBW
Current value of the estimated BW.
Definition: tcp-westwood.h:125
bool m_IsCount
Start keeping track of m_ackedSegments for Westwood+ if TRUE.
Definition: tcp-westwood.h:133
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
Time m_minRtt
Minimum RTT.
Definition: tcp-westwood.h:128
a unique identifier for an interface.
Definition: type-id.h:58
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:345
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
An implementation of TCP Westwood and Westwood+.
Definition: tcp-westwood.h:65
enum ProtocolType m_pType
0 for Westwood, 1 for Westwood+
Definition: tcp-westwood.h:129