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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Siddharth Gangadhar <siddharth@ittc.ku.edu>,
7 * Truc Anh N. Nguyen <annguyen@ittc.ku.edu>,
8 * Greeshma Umapathi
9 *
10 * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
11 * ResiliNets Research Group https://resilinets.org/
12 * Information and Telecommunication Technology Center (ITTC)
13 * and Department of Electrical Engineering and Computer Science
14 * The University of Kansas Lawrence, KS USA.
15 *
16 * Work supported in part by NSF FIND (Future Internet Design) Program
17 * under grant CNS-0626918 (Postmodern Internet Architecture),
18 * NSF grant CNS-1050226 (Multilayer Network Resilience Analysis and Experimentation on GENI),
19 * US Department of Defense (DoD), and ITTC at The University of Kansas.
20 */
21
22#include "tcp-westwood-plus.h"
23
24#include "ns3/log.h"
25#include "ns3/simulator.h"
26
27NS_LOG_COMPONENT_DEFINE("TcpWestwoodPlus");
28
29namespace ns3
30{
31
32NS_OBJECT_ENSURE_REGISTERED(TcpWestwoodPlus);
33
34TypeId
36{
37 static TypeId tid =
38 TypeId("ns3::TcpWestwoodPlus")
40 .SetGroupName("Internet")
41 .AddConstructor<TcpWestwoodPlus>()
42 .AddAttribute(
43 "FilterType",
44 "Use this to choose no filter or Tustin's approximation filter",
48 .AddTraceSource("EstimatedBW",
49 "The estimated bandwidth",
51 "ns3::TracedValueCallback::DataRate");
52 return tid;
53}
54
56 : TcpNewReno(),
57 m_currentBW(0),
58 m_lastSampleBW(0),
59 m_lastBW(0),
60 m_ackedSegments(0),
61 m_IsCount(false),
62 m_lastAck(0)
63{
64 NS_LOG_FUNCTION(this);
65}
66
68 : TcpNewReno(sock),
69 m_currentBW(sock.m_currentBW),
70 m_lastSampleBW(sock.m_lastSampleBW),
71 m_lastBW(sock.m_lastBW),
72 m_fType(sock.m_fType),
73 m_IsCount(sock.m_IsCount)
74{
75 NS_LOG_FUNCTION(this);
76 NS_LOG_LOGIC("Invoked the copy constructor");
77}
78
82
83void
85{
86 NS_LOG_FUNCTION(this << tcb << packetsAcked << rtt);
87
88 if (rtt.IsZero())
89 {
90 NS_LOG_WARN("RTT measured is zero!");
91 return;
92 }
93
94 m_ackedSegments += packetsAcked;
95
96 if (!(rtt.IsZero() || m_IsCount))
97 {
98 m_IsCount = true;
101 }
102}
103
104void
106{
107 NS_LOG_FUNCTION(this);
108
109 NS_ASSERT(!rtt.IsZero());
110
111 m_currentBW = DataRate(m_ackedSegments * tcb->m_segmentSize * 8.0 / rtt.GetSeconds());
112 m_IsCount = false;
113
114 m_ackedSegments = 0;
115
116 NS_LOG_LOGIC("Estimated BW: " << m_currentBW);
117
118 // Filter the BW sample
119
120 constexpr double ALPHA = 0.9;
121
123 {
124 DataRate sample_bwe = m_currentBW;
125 m_currentBW = (m_lastBW * ALPHA) + (((sample_bwe + m_lastSampleBW) * 0.5) * (1 - ALPHA));
126 m_lastSampleBW = sample_bwe;
128 }
129
130 NS_LOG_LOGIC("Estimated BW after filtering: " << m_currentBW);
131}
132
135{
136 uint32_t ssThresh = static_cast<uint32_t>((m_currentBW * tcb->m_minRtt) / 8.0);
137
138 NS_LOG_LOGIC("CurrentBW: " << m_currentBW << " minRtt: " << tcb->m_minRtt
139 << " ssThresh: " << ssThresh);
140
141 return std::max(2 * tcb->m_segmentSize, ssThresh);
142}
143
149
150} // namespace ns3
Class for representing data rates.
Definition data-rate.h:78
Hold variables of type enum.
Definition enum.h:52
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition event-id.cc:44
Smart pointer class similar to boost::intrusive_ptr.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
Definition simulator.h:560
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:94
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:392
bool IsZero() const
Exactly equivalent to t == 0.
Definition nstime.h:304
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:250
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
Definition object.h:619
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
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:179
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition enum.h:221