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 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("TcpLp");
33 
34 TypeId
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 
58 TcpLp::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 
82 void
83 TcpLp::CongestionAvoidance (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
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 
93 uint32_t
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  {
108  m_flag |= LP_VALID_OWD;
109  }
110  else
111  {
112  m_flag &= ~LP_VALID_OWD;
113  }
114  return owd;
115 }
116 
117 void
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 
167 void
168 TcpLp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
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 
233 std::string
235 {
236  return "TcpLp";
237 }
238 } // namespace ns3
virtual ~TcpLp(void)
Definition: tcp-lp.cc:71
uint32_t m_rcvTimestampValue
Receiver Timestamp value.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Calculated One-Way Delay is valid.
Definition: tcp-lp.h:93
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
uint32_t m_owdMin
Minimum One-Way Delay.
Definition: tcp-lp.h:100
uint32_t m_sOwd
Smoothed One-Way Delay.
Definition: tcp-lp.h:99
uint32_t m_rcvTimestampEchoReply
Sender Timestamp echoed by the receiver.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1078
uint32_t m_segmentSize
Segment size.
The NewReno implementation.
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-lp.cc:168
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
#define max(a, b)
Definition: 80211b.c:43
TcpLp is within Threshold.
Definition: tcp-lp.h:94
bool IsZero(void) const
Definition: nstime.h:294
Time m_inference
Current inference period.
Definition: tcp-lp.h:104
TcpLp(void)
Creates an unbound tcp socket.
Definition: tcp-lp.cc:45
uint32_t m_flag
TcpLp state flag.
Definition: tcp-lp.h:98
TcpLp is within Inference.
Definition: tcp-lp.h:95
uint32_t m_owdMax
Maximum One-Way Delay.
Definition: tcp-lp.h:101
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static Time Now(void)
Return the current simulation virtual time.
Definition: simulator.cc:193
TracedValue< uint32_t > m_cWnd
Congestion window.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-lp.cc:77
Introspection did not find any typical Config paths.
Definition: tcp-lp.h:35
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:365
T Get(void) const
Get the underlying value.
Definition: traced-value.h:227
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-lp.cc:234
void RttSample(Ptr< TcpSocketState > tcb)
Estimates minimum and maximum One-Way Delays and calculates the smoothed One-Way Delay.
Definition: tcp-lp.cc:118
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
NewReno congestion avoidance.
uint32_t m_owdMaxRsv
Reserved Maximum One-Way Delay.
Definition: tcp-lp.h:102
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-lp.cc:35
uint32_t OwdCalculator(Ptr< TcpSocketState > tcb)
Calculates One-Way Delay using Sender and Receiver timestamps.
Definition: tcp-lp.cc:94
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
Time m_lastDrop
Last time when cwnd was reduced.
Definition: tcp-lp.h:103