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_ackedSegments (0),
73  m_IsCount (false)
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_pType (sock.m_pType),
84  m_fType (sock.m_fType),
85  m_IsCount (sock.m_IsCount)
86 {
87  NS_LOG_FUNCTION (this);
88  NS_LOG_LOGIC ("Invoked the copy constructor");
89 }
90 
92 {
93 }
94 
95 void
96 TcpWestwood::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t packetsAcked,
97  const Time& rtt)
98 {
99  NS_LOG_FUNCTION (this << tcb << packetsAcked << rtt);
100 
101  if (rtt.IsZero ())
102  {
103  NS_LOG_WARN ("RTT measured is zero!");
104  return;
105  }
106 
107  m_ackedSegments += packetsAcked;
108 
110  {
111  EstimateBW (rtt, tcb);
112  }
114  {
115  if (!(rtt.IsZero () || m_IsCount))
116  {
117  m_IsCount = true;
120  this, rtt, tcb);
121  }
122  }
123 }
124 
125 void
127 {
128  NS_LOG_FUNCTION (this);
129 
130  NS_ASSERT (!rtt.IsZero ());
131 
133 
135  {
136  m_IsCount = false;
137  }
138 
139  m_ackedSegments = 0;
140  NS_LOG_LOGIC ("Estimated BW: " << m_currentBW);
141 
142  // Filter the BW sample
143 
144  double alpha = 0.9;
145 
146  if (m_fType == TcpWestwood::NONE)
147  {
148  }
149  else if (m_fType == TcpWestwood::TUSTIN)
150  {
151  double sample_bwe = m_currentBW;
152  m_currentBW = (alpha * m_lastBW) + ((1 - alpha) * ((sample_bwe + m_lastSampleBW) / 2));
153  m_lastSampleBW = sample_bwe;
155  }
156 
157  NS_LOG_LOGIC ("Estimated BW after filtering: " << m_currentBW);
158 }
159 
160 uint32_t
162  uint32_t bytesInFlight)
163 {
164  NS_UNUSED (bytesInFlight);
165  NS_LOG_LOGIC ("CurrentBW: " << m_currentBW << " minRtt: " <<
166  tcb->m_minRtt << " ssthresh: " <<
167  m_currentBW * static_cast<double> (tcb->m_minRtt.GetSeconds ()));
168 
169  return std::max (2*tcb->m_segmentSize,
170  uint32_t (m_currentBW * static_cast<double> (tcb->m_minRtt.GetSeconds ())));
171 }
172 
175 {
176  return CreateObject<TcpWestwood> (*this);
177 }
178 
179 } // namespace ns3
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
Definition: tcp-westwood.h:135
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#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:45
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:129
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:355
#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:202
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uint32_t m_segmentSize
Segment size.
The NewReno implementation.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t packetsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-westwood.cc:96
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
enum FilterType m_fType
0 for none, 1 for Tustin
Definition: tcp-westwood.h:131
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:1381
#define max(a, b)
Definition: 80211b.c:43
bool IsZero(void) const
Definition: nstime.h:288
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.
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
virtual ~TcpWestwood(void)
Definition: tcp-westwood.cc:91
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
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
double m_lastSampleBW
Last bandwidth sample.
Definition: tcp-westwood.h:128
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network&#39;s bandwidth.
TracedValue< double > m_currentBW
Current value of the estimated BW.
Definition: tcp-westwood.h:127
bool m_IsCount
Start keeping track of m_ackedSegments for Westwood+ if TRUE.
Definition: tcp-westwood.h:134
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
uint32_t m_ackedSegments
The number of segments ACKed between RTTs.
Definition: tcp-westwood.h:133
An implementation of TCP Westwood and Westwood+.
Definition: tcp-westwood.h:67
enum ProtocolType m_pType
0 for Westwood, 1 for Westwood+
Definition: tcp-westwood.h:130