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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Charitha Sangaraju <charitha29193@gmail.com>
7 * Nandita G <gm.nandita@gmail.com>
8 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
9 *
10 */
11
12#include "tcp-lp.h"
13
14#include "ns3/log.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19
22
23TypeId
25{
26 static TypeId tid = TypeId("ns3::TcpLp")
28 .AddConstructor<TcpLp>()
29 .SetGroupName("Internet");
30 return tid;
31}
32
34 : TcpNewReno(),
35 m_flag(0),
36 m_sOwd(0),
37 m_owdMin(0xffffffff),
38 m_owdMax(0),
39 m_owdMaxRsv(0),
40 m_lastDrop(Time(0)),
41 m_inference(Time(0))
42{
43 NS_LOG_FUNCTION(this);
44}
45
46TcpLp::TcpLp(const TcpLp& sock)
47 : TcpNewReno(sock),
48 m_flag(sock.m_flag),
49 m_sOwd(sock.m_sOwd),
50 m_owdMin(sock.m_owdMin),
51 m_owdMax(sock.m_owdMax),
52 m_owdMaxRsv(sock.m_owdMaxRsv),
53 m_lastDrop(sock.m_lastDrop),
54 m_inference(sock.m_inference)
55{
56 NS_LOG_FUNCTION(this);
57}
58
60{
61 NS_LOG_FUNCTION(this);
62}
63
66{
67 return CopyObject<TcpLp>(this);
68}
69
70void
72{
73 NS_LOG_FUNCTION(this << tcb << segmentsAcked);
74
75 if (!(m_flag & LP_WITHIN_INF))
76 {
77 TcpNewReno::CongestionAvoidance(tcb, segmentsAcked);
78 }
79}
80
83{
84 NS_LOG_FUNCTION(this << tcb);
85
86 int64_t owd = 0;
87
88 owd = tcb->m_rcvTimestampValue - tcb->m_rcvTimestampEchoReply;
89
90 if (owd < 0)
91 {
92 owd = -owd;
93 }
94 if (owd > 0)
95 {
97 }
98 else
99 {
100 m_flag &= ~LP_VALID_OWD;
101 }
102 return owd;
103}
104
105void
107{
108 NS_LOG_FUNCTION(this << tcb);
109
110 uint32_t mowd = OwdCalculator(tcb);
111
112 if (!(m_flag & LP_VALID_OWD))
113 {
114 return;
115 }
116
117 /* record the next minimum owd */
118 if (mowd < m_owdMin)
119 {
120 m_owdMin = mowd;
121 }
122
123 if (mowd > m_owdMax)
124 {
125 if (mowd > m_owdMaxRsv)
126 {
127 if (m_owdMaxRsv == 0)
128 {
129 m_owdMax = mowd;
130 }
131 else
132 {
134 }
135 m_owdMaxRsv = mowd;
136 }
137 else
138 {
139 m_owdMax = mowd;
140 }
141 }
142
143 /* Calculation for Smoothed Owd */
144 if (m_sOwd != 0)
145 {
146 mowd -= m_sOwd >> 3;
147 m_sOwd += mowd; /* owd = 7/8 owd + 1/8 new owd */
148 }
149 else
150 {
151 m_sOwd = mowd << 3; /* owd = 1/8 new owd */
152 }
153}
154
155void
156TcpLp::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt)
157{
158 NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
159
160 if (!rtt.IsZero())
161 {
162 RttSample(tcb);
163 }
164
165 Time timestamp = Simulator::Now();
166 /* Calculation of inference time */
167 if (timestamp.GetMilliSeconds() > tcb->m_rcvTimestampEchoReply)
168 {
169 m_inference = 3 * (timestamp - MilliSeconds(tcb->m_rcvTimestampEchoReply));
170 }
171
172 /* Test if within inference */
173 if (!m_lastDrop.IsZero() && (timestamp - m_lastDrop < m_inference))
174 {
176 }
177 else
178 {
179 m_flag &= ~LP_WITHIN_INF;
180 }
181
182 /* Test if within threshold */
183 if (m_sOwd >> 3 <= m_owdMin + 15 * (m_owdMax - m_owdMin) / 100)
184 {
186 }
187 else
188 {
189 m_flag &= ~LP_WITHIN_THR;
190 }
191
192 if (m_flag & LP_WITHIN_THR)
193 {
194 return;
195 }
196
197 m_owdMin = m_sOwd >> 3;
198 m_owdMax = m_sOwd >> 2;
199 m_owdMaxRsv = m_sOwd >> 2;
200
201 /* happened within inference
202 * drop congestion window to 1 */
203 if (m_flag & LP_WITHIN_INF)
204 {
205 tcb->m_cWnd = 1U * tcb->m_segmentSize;
206 }
207
208 /* happened after inference
209 * cut congestion window to half */
210 else
211 {
212 tcb->m_cWnd = std::max(tcb->m_cWnd.Get() >> 1U, 1U * tcb->m_segmentSize);
213 }
214
215 /* record this time of reduction of cwnd */
216 m_lastDrop = timestamp;
217}
218
219std::string
221{
222 return "TcpLp";
223}
224} // namespace ns3
friend Ptr< T > CopyObject(Ptr< T > object)
Copy an Object.
Definition object.h:581
Smart pointer class similar to boost::intrusive_ptr.
static Time Now()
Return the current simulation virtual time.
Definition simulator.cc:197
TCP-LP (Low Priority) congestion control algorithm.
Definition tcp-lp.h:30
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition tcp-lp.cc:220
Time m_inference
Current inference period.
Definition tcp-lp.h:97
uint32_t m_flag
TcpLp state flag.
Definition tcp-lp.h:91
~TcpLp() override
Definition tcp-lp.cc:59
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition tcp-lp.cc:156
uint32_t m_owdMax
Maximum One-Way Delay.
Definition tcp-lp.h:94
void RttSample(Ptr< TcpSocketState > tcb)
Estimates minimum and maximum One-Way Delays and calculates the smoothed One-Way Delay.
Definition tcp-lp.cc:106
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition tcp-lp.cc:65
uint32_t m_owdMaxRsv
Reserved Maximum One-Way Delay.
Definition tcp-lp.h:95
static TypeId GetTypeId()
Get the type ID.
Definition tcp-lp.cc:24
void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked) override
Invokes Congestion Avoidance of TcpNewReno if TcpLp is not within inference.
Definition tcp-lp.cc:71
uint32_t m_owdMin
Minimum One-Way Delay.
Definition tcp-lp.h:93
TcpLp()
Creates an unbound tcp socket.
Definition tcp-lp.cc:33
@ LP_WITHIN_INF
TcpLp is within Inference.
Definition tcp-lp.h:88
@ LP_VALID_OWD
Calculated One-Way Delay is valid.
Definition tcp-lp.h:86
@ LP_WITHIN_THR
TcpLp is within Threshold.
Definition tcp-lp.h:87
uint32_t OwdCalculator(Ptr< TcpSocketState > tcb)
Calculates One-Way Delay using Sender and Receiver timestamps.
Definition tcp-lp.cc:82
Time m_lastDrop
Last time when cwnd was reduced.
Definition tcp-lp.h:96
uint32_t m_sOwd
Smoothed One-Way Delay.
Definition tcp-lp.h:92
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:94
int64_t GetMilliSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
Definition nstime.h:397
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_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:35
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition nstime.h:1320
Every class exported by the ns3 library is enclosed in the ns3 namespace.