A Discrete-Event Network Simulator
API
tcp-lp.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2016 NITK Surathkal
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: Charitha Sangaraju <charitha29193@gmail.com>
19 * Nandita G <gm.nandita@gmail.com>
20 * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21 *
22 */
23
24#include "tcp-lp.h"
25
26#include "ns3/log.h"
27#include "ns3/simulator.h"
28
29namespace ns3 {
30
33
34TypeId
36{
37 static TypeId tid = TypeId ("ns3::TcpLp")
39 .AddConstructor<TcpLp> ()
40 .SetGroupName ("Internet")
41 ;
42 return tid;
43}
44
46 : TcpNewReno (),
47 m_flag (0),
48 m_sOwd (0),
49 m_owdMin (0xffffffff),
50 m_owdMax (0),
51 m_owdMaxRsv (0),
52 m_lastDrop (Time (0)),
53 m_inference (Time (0))
54{
55 NS_LOG_FUNCTION (this);
56}
57
58TcpLp::TcpLp (const TcpLp& sock)
59 : TcpNewReno (sock),
60 m_flag (sock.m_flag),
61 m_sOwd (sock.m_sOwd),
62 m_owdMin (sock.m_owdMin),
63 m_owdMax (sock.m_owdMax),
64 m_owdMaxRsv (sock.m_owdMaxRsv),
65 m_lastDrop (sock.m_lastDrop),
66 m_inference (sock.m_inference)
67{
68 NS_LOG_FUNCTION (this);
69}
70
72{
73 NS_LOG_FUNCTION (this);
74}
75
78{
79 return CopyObject<TcpLp> (this);
80}
81
82void
84{
85 NS_LOG_FUNCTION (this << tcb << segmentsAcked);
86
87 if (!(m_flag & LP_WITHIN_INF))
88 {
89 TcpNewReno::CongestionAvoidance (tcb, segmentsAcked);
90 }
91}
92
95{
96 NS_LOG_FUNCTION (this << tcb);
97
98 int64_t owd = 0;
99
101
102 if (owd < 0)
103 {
104 owd = -owd;
105 }
106 if (owd > 0)
107 {
109 }
110 else
111 {
112 m_flag &= ~LP_VALID_OWD;
113 }
114 return owd;
115}
116
117void
119{
120 NS_LOG_FUNCTION (this << tcb );
121
122 uint32_t mowd = OwdCalculator (tcb);
123
124 if (!(m_flag & LP_VALID_OWD))
125 {
126 return;
127 }
128
129 /* record the next minimum owd */
130 if (mowd < m_owdMin)
131 {
132 m_owdMin = mowd;
133 }
134
135 if (mowd > m_owdMax)
136 {
137 if (mowd > m_owdMaxRsv)
138 {
139 if (m_owdMaxRsv == 0)
140 {
141 m_owdMax = mowd;
142 }
143 else
144 {
146 }
147 m_owdMaxRsv = mowd;
148 }
149 else
150 {
151 m_owdMax = mowd;
152 }
153 }
154
155 /* Calculation for Smoothed Owd */
156 if (m_sOwd != 0)
157 {
158 mowd -= m_sOwd >> 3;
159 m_sOwd += mowd; /* owd = 7/8 owd + 1/8 new owd */
160 }
161 else
162 {
163 m_sOwd = mowd << 3; /* owd = 1/8 new owd */
164 }
165}
166
167void
169 const Time &rtt)
170{
171 NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
172
173 if (!rtt.IsZero ())
174 {
175 RttSample (tcb);
176 }
177
178 Time timestamp = Simulator::Now ();
179 /* Calculation of inference time */
180 if (timestamp.GetMilliSeconds () > tcb->m_rcvTimestampEchoReply)
181 {
182 m_inference = 3 * (timestamp - MilliSeconds (tcb->m_rcvTimestampEchoReply));
183 }
184
185 /* Test if within inference */
186 if (!m_lastDrop.IsZero () && (timestamp - m_lastDrop < m_inference))
187 {
189 }
190 else
191 {
192 m_flag &= ~LP_WITHIN_INF;
193 }
194
195 /* Test if within threshold */
196 if (m_sOwd >> 3 <=
197 m_owdMin + 15 * (m_owdMax - m_owdMin) / 100)
198 {
200 }
201 else
202 {
203 m_flag &= ~LP_WITHIN_THR;
204 }
205
206 if (m_flag & LP_WITHIN_THR)
207 {
208 return;
209 }
210
211 m_owdMin = m_sOwd >> 3;
212 m_owdMax = m_sOwd >> 2;
213 m_owdMaxRsv = m_sOwd >> 2;
214
215 /* happened within inference
216 * drop congestion window to 1 */
217 if (m_flag & LP_WITHIN_INF)
218 {
219 tcb->m_cWnd = 1U * tcb->m_segmentSize;
220 }
221
222 /* happened after inference
223 * cut congestion window to half */
224 else
225 {
226 tcb->m_cWnd = std::max (tcb->m_cWnd.Get () >> 1U, 1U * tcb->m_segmentSize);
227 }
228
229 /* record this time of reduction of cwnd */
230 m_lastDrop = timestamp;
231}
232
233std::string
235{
236 return "TcpLp";
237}
238} // namespace ns3
#define max(a, b)
Definition: 80211b.c:43
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:195
TCP-LP (Low Priority) congestion control algorithm.
Definition: tcp-lp.h:41
Time m_inference
Current inference period.
Definition: tcp-lp.h:109
uint32_t m_flag
TcpLp state flag.
Definition: tcp-lp.h:103
uint32_t m_owdMax
Maximum One-Way Delay.
Definition: tcp-lp.h:106
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-lp.cc:77
void RttSample(Ptr< TcpSocketState > tcb)
Estimates minimum and maximum One-Way Delays and calculates the smoothed One-Way Delay.
Definition: tcp-lp.cc:118
uint32_t m_owdMaxRsv
Reserved Maximum One-Way Delay.
Definition: tcp-lp.h:107
virtual ~TcpLp(void)
Definition: tcp-lp.cc:71
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Invokes Congestion Avoidance of TcpNewReno if TcpLp is not within inference.
Definition: tcp-lp.cc:83
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-lp.cc:35
uint32_t m_owdMin
Minimum One-Way Delay.
Definition: tcp-lp.h:105
@ LP_WITHIN_INF
TcpLp is within Inference.
Definition: tcp-lp.h:100
@ LP_VALID_OWD
Calculated One-Way Delay is valid.
Definition: tcp-lp.h:98
@ LP_WITHIN_THR
TcpLp is within Threshold.
Definition: tcp-lp.h:99
uint32_t OwdCalculator(Ptr< TcpSocketState > tcb)
Calculates One-Way Delay using Sender and Receiver timestamps.
Definition: tcp-lp.cc:94
TcpLp(void)
Creates an unbound tcp socket.
Definition: tcp-lp.cc:45
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-lp.cc:168
Time m_lastDrop
Last time when cwnd was reduced.
Definition: tcp-lp.h:108
uint32_t m_sOwd
Smoothed One-Way Delay.
Definition: tcp-lp.h:104
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-lp.cc:234
The NewReno implementation.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
bool IsZero(void) const
Exactly equivalent to t == 0.
Definition: nstime.h:300
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:383
T Get(void) const
Get the underlying value.
Definition: traced-value.h:232
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1252
Every class exported by the ns3 library is enclosed in the ns3 namespace.