A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
tcp-lp.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 NITK Surathkal
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Charitha Sangaraju <charitha29193@gmail.com>
18 * Nandita G <gm.nandita@gmail.com>
19 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
20 *
21 */
22
23#include "tcp-lp.h"
24
25#include "ns3/log.h"
26#include "ns3/simulator.h"
27
28namespace ns3
29{
30
33
34TypeId
36{
37 static TypeId tid = TypeId("ns3::TcpLp")
39 .AddConstructor<TcpLp>()
40 .SetGroupName("Internet");
41 return tid;
42}
43
45 : TcpNewReno(),
46 m_flag(0),
47 m_sOwd(0),
48 m_owdMin(0xffffffff),
49 m_owdMax(0),
50 m_owdMaxRsv(0),
51 m_lastDrop(Time(0)),
52 m_inference(Time(0))
53{
54 NS_LOG_FUNCTION(this);
55}
56
57TcpLp::TcpLp(const TcpLp& sock)
58 : TcpNewReno(sock),
59 m_flag(sock.m_flag),
60 m_sOwd(sock.m_sOwd),
61 m_owdMin(sock.m_owdMin),
62 m_owdMax(sock.m_owdMax),
63 m_owdMaxRsv(sock.m_owdMaxRsv),
64 m_lastDrop(sock.m_lastDrop),
65 m_inference(sock.m_inference)
66{
67 NS_LOG_FUNCTION(this);
68}
69
71{
72 NS_LOG_FUNCTION(this);
73}
74
77{
78 return CopyObject<TcpLp>(this);
79}
80
81void
83{
84 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
85
86 if (!(m_flag & LP_WITHIN_INF))
87 {
88 TcpNewReno::CongestionAvoidance(tcb, segmentsAcked);
89 }
90}
91
94{
95 NS_LOG_FUNCTION(this << tcb);
96
97 int64_t owd = 0;
98
99 owd = tcb->m_rcvTimestampValue - tcb->m_rcvTimestampEchoReply;
100
101 if (owd < 0)
102 {
103 owd = -owd;
104 }
105 if (owd > 0)
106 {
108 }
109 else
110 {
111 m_flag &= ~LP_VALID_OWD;
112 }
113 return owd;
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << tcb);
120
121 uint32_t mowd = OwdCalculator(tcb);
122
123 if (!(m_flag & LP_VALID_OWD))
124 {
125 return;
126 }
127
128 /* record the next minimum owd */
129 if (mowd < m_owdMin)
130 {
131 m_owdMin = mowd;
132 }
133
134 if (mowd > m_owdMax)
135 {
136 if (mowd > m_owdMaxRsv)
137 {
138 if (m_owdMaxRsv == 0)
139 {
140 m_owdMax = mowd;
141 }
142 else
143 {
145 }
146 m_owdMaxRsv = mowd;
147 }
148 else
149 {
150 m_owdMax = mowd;
151 }
152 }
153
154 /* Calculation for Smoothed Owd */
155 if (m_sOwd != 0)
156 {
157 mowd -= m_sOwd >> 3;
158 m_sOwd += mowd; /* owd = 7/8 owd + 1/8 new owd */
159 }
160 else
161 {
162 m_sOwd = mowd << 3; /* owd = 1/8 new owd */
163 }
164}
165
166void
167TcpLp::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt)
168{
169 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
170
171 if (!rtt.IsZero())
172 {
173 RttSample(tcb);
174 }
175
176 Time timestamp = Simulator::Now();
177 /* Calculation of inference time */
178 if (timestamp.GetMilliSeconds() > tcb->m_rcvTimestampEchoReply)
179 {
180 m_inference = 3 * (timestamp - MilliSeconds(tcb->m_rcvTimestampEchoReply));
181 }
182
183 /* Test if within inference */
184 if (!m_lastDrop.IsZero() && (timestamp - m_lastDrop < m_inference))
185 {
187 }
188 else
189 {
190 m_flag &= ~LP_WITHIN_INF;
191 }
192
193 /* Test if within threshold */
194 if (m_sOwd >> 3 <= m_owdMin + 15 * (m_owdMax - m_owdMin) / 100)
195 {
197 }
198 else
199 {
200 m_flag &= ~LP_WITHIN_THR;
201 }
202
203 if (m_flag & LP_WITHIN_THR)
204 {
205 return;
206 }
207
208 m_owdMin = m_sOwd >> 3;
209 m_owdMax = m_sOwd >> 2;
210 m_owdMaxRsv = m_sOwd >> 2;
211
212 /* happened within inference
213 * drop congestion window to 1 */
214 if (m_flag & LP_WITHIN_INF)
215 {
216 tcb->m_cWnd = 1U * tcb->m_segmentSize;
217 }
218
219 /* happened after inference
220 * cut congestion window to half */
221 else
222 {
223 tcb->m_cWnd = std::max(tcb->m_cWnd.Get() >> 1U, 1U * tcb->m_segmentSize);
224 }
225
226 /* record this time of reduction of cwnd */
227 m_lastDrop = timestamp;
228}
229
230std::string
232{
233 return "TcpLp";
234}
235} // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
static Time Now()
Return the current simulation virtual time.
Definition: simulator.cc:208
TCP-LP (Low Priority) congestion control algorithm.
Definition: tcp-lp.h:41
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-lp.cc:231
Time m_inference
Current inference period.
Definition: tcp-lp.h:108
uint32_t m_flag
TcpLp state flag.
Definition: tcp-lp.h:102
~TcpLp() override
Definition: tcp-lp.cc:70
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-lp.cc:167
uint32_t m_owdMax
Maximum One-Way Delay.
Definition: tcp-lp.h:105
void RttSample(Ptr< TcpSocketState > tcb)
Estimates minimum and maximum One-Way Delays and calculates the smoothed One-Way Delay.
Definition: tcp-lp.cc:117
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition: tcp-lp.cc:76
uint32_t m_owdMaxRsv
Reserved Maximum One-Way Delay.
Definition: tcp-lp.h:106
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-lp.cc:35
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Invokes Congestion Avoidance of TcpNewReno if TcpLp is not within inference.
Definition: tcp-lp.cc:82
uint32_t m_owdMin
Minimum One-Way Delay.
Definition: tcp-lp.h:104
TcpLp()
Creates an unbound tcp socket.
Definition: tcp-lp.cc:44
@ LP_WITHIN_INF
TcpLp is within Inference.
Definition: tcp-lp.h:99
@ LP_VALID_OWD
Calculated One-Way Delay is valid.
Definition: tcp-lp.h:97
@ LP_WITHIN_THR
TcpLp is within Threshold.
Definition: tcp-lp.h:98
uint32_t OwdCalculator(Ptr< TcpSocketState > tcb)
Calculates One-Way Delay using Sender and Receiver timestamps.
Definition: tcp-lp.cc:93
Time m_lastDrop
Last time when cwnd was reduced.
Definition: tcp-lp.h:107
uint32_t m_sOwd
Smoothed One-Way Delay.
Definition: tcp-lp.h:103
The NewReno implementation.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:408
bool IsZero() const
Exactly equivalent to t == 0.
Definition: nstime.h:315
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:46
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1331
Every class exported by the ns3 library is enclosed in the ns3 namespace.