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  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 
136  {
137  Time currentAck = Simulator::Now ();
138  m_currentBW = m_ackedSegments * tcb->m_segmentSize / (currentAck - m_lastAck).GetSeconds ();
139  m_lastAck = currentAck;
140  }
142  {
144  m_IsCount = false;
145  }
146 
147  m_ackedSegments = 0;
148  NS_LOG_LOGIC ("Estimated BW: " << m_currentBW);
149 
150  // Filter the BW sample
151 
152  double alpha = 0.9;
153 
154  if (m_fType == TcpWestwood::NONE)
155  {
156  }
157  else if (m_fType == TcpWestwood::TUSTIN)
158  {
159  double sample_bwe = m_currentBW;
160  m_currentBW = (alpha * m_lastBW) + ((1 - alpha) * ((sample_bwe + m_lastSampleBW) / 2));
161  m_lastSampleBW = sample_bwe;
163  }
164 
165  NS_LOG_LOGIC ("Estimated BW after filtering: " << m_currentBW);
166 }
167 
168 uint32_t
170  uint32_t bytesInFlight)
171 {
172  NS_UNUSED (bytesInFlight);
173  NS_LOG_LOGIC ("CurrentBW: " << m_currentBW << " minRtt: " <<
174  tcb->m_minRtt << " ssthresh: " <<
175  m_currentBW * static_cast<double> (tcb->m_minRtt.GetSeconds ()));
176 
177  return std::max (2*tcb->m_segmentSize,
178  uint32_t (m_currentBW * static_cast<double> (tcb->m_minRtt.GetSeconds ())));
179 }
180 
183 {
184  return CreateObject<TcpWestwood> (*this);
185 }
186 
187 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::TcpWestwood::m_IsCount
bool m_IsCount
Start keeping track of m_ackedSegments for Westwood+ if TRUE.
Definition: tcp-westwood.h:134
ns3::TcpWestwood::TUSTIN
@ TUSTIN
Definition: tcp-westwood.h:99
ns3::TcpWestwood::m_lastAck
Time m_lastAck
The last ACK time.
Definition: tcp-westwood.h:136
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#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
rtt-estimator.h
ns3::Simulator::Now
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
ns3::TcpWestwood::m_bwEstimateEvent
EventId m_bwEstimateEvent
The BW estimation event for Westwood+.
Definition: tcp-westwood.h:135
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::TcpWestwood::GetSsThresh
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-westwood.cc:169
ns3::MakeEnumChecker
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:161
ns3::TcpSocketState::m_segmentSize
uint32_t m_segmentSize
Segment size.
Definition: tcp-socket-state.h:177
NS_LOG_WARN
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:265
ns3::TcpWestwood
An implementation of TCP Westwood and Westwood+.
Definition: tcp-westwood.h:68
ns3::Simulator::Schedule
static EventId Schedule(Time const &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition: simulator.h:557
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::EnumValue
Hold variables of type enum.
Definition: enum.h:55
ns3::TcpWestwood::PktsAcked
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t packetsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-westwood.cc:97
ns3::MakeTraceSourceAccessor
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Definition: trace-source-accessor.h:202
ns3::TcpWestwood::m_fType
enum FilterType m_fType
0 for none, 1 for Tustin
Definition: tcp-westwood.h:131
ns3::Ptr< TcpSocketState >
ns3::TcpWestwood::~TcpWestwood
virtual ~TcpWestwood(void)
Definition: tcp-westwood.cc:92
ns3::TcpWestwood::NONE
@ NONE
Definition: tcp-westwood.h:98
ns3::TcpWestwood::Fork
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-westwood.cc:182
max
#define max(a, b)
Definition: 80211b.c:43
sample-rng-plot.alpha
alpha
Definition: sample-rng-plot.py:37
ns3::Time::IsZero
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:301
ns3::TcpWestwood::m_lastSampleBW
double m_lastSampleBW
Last bandwidth sample.
Definition: tcp-westwood.h:128
ns3::TcpWestwood::EstimateBW
void EstimateBW(const Time &rtt, Ptr< TcpSocketState > tcb)
Estimate the network's bandwidth.
Definition: tcp-westwood.cc:127
ns3::EventId::Cancel
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
NS_UNUSED
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
ns3::TcpWestwood::WESTWOODPLUS
@ WESTWOODPLUS
Definition: tcp-westwood.h:90
ns3::Time
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:104
ns3::TcpWestwood::TcpWestwood
TcpWestwood(void)
Definition: tcp-westwood.cc:67
ns3::TcpWestwood::m_pType
enum ProtocolType m_pType
0 for Westwood, 1 for Westwood+
Definition: tcp-westwood.h:130
NS_LOG_LOGIC
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
ns3::TcpWestwood::m_ackedSegments
uint32_t m_ackedSegments
The number of segments ACKed between RTTs.
Definition: tcp-westwood.h:133
ns3::MakeEnumAccessor
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:203
ns3::TcpNewReno
The NewReno implementation.
Definition: tcp-congestion-ops.h:216
ns3::TcpWestwood::WESTWOOD
@ WESTWOOD
Definition: tcp-westwood.h:89
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
tcp-socket-base.h
ns3::TcpWestwood::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-westwood.cc:47
ns3::TcpWestwood::m_lastBW
double m_lastBW
Last bandwidth sample after being filtered.
Definition: tcp-westwood.h:129
tcp-westwood.h
ns3::Time::GetSeconds
double GetSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:380
ns3::TcpWestwood::m_currentBW
TracedValue< double > m_currentBW
Current value of the estimated BW.
Definition: tcp-westwood.h:127