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 #include "ns3/tcp-socket-base.h"
26 #include "ns3/log.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("TcpLp");
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::TcpLp")
38  .AddConstructor<TcpLp> ()
39  .SetGroupName ("Internet")
40  ;
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 
57 TcpLp::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 
81 void
82 TcpLp::CongestionAvoidance (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
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 
92 uint32_t
94 {
95  NS_LOG_FUNCTION (this << tcb);
96 
97  int64_t owd = 0;
98 
100 
101  if (owd < 0)
102  {
103  owd = -owd;
104  }
105  if (owd > 0)
106  {
107  m_flag |= LP_VALID_OWD;
108  }
109  else
110  {
111  m_flag &= ~LP_VALID_OWD;
112  }
113  return owd;
114 }
115 
116 void
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 
166 void
167 TcpLp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
168  const Time &rtt)
169 {
170  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
171 
172  if (!rtt.IsZero ())
173  {
174  RttSample (tcb);
175  }
176 
177  Time timestamp = Simulator::Now ();
178  /* Calculation of inference time */
179  if (timestamp.GetMilliSeconds () > tcb->m_rcvTimestampEchoReply)
180  {
181  m_inference = 3 * (timestamp - MilliSeconds (tcb->m_rcvTimestampEchoReply));
182  }
183 
184  /* Test if within inference */
185  if (!m_lastDrop.IsZero () && (timestamp - m_lastDrop < m_inference))
186  {
188  }
189  else
190  {
191  m_flag &= ~LP_WITHIN_INF;
192  }
193 
194  /* Test if within threshold */
195  if (m_sOwd >> 3 <=
196  m_owdMin + 15 * (m_owdMax - m_owdMin) / 100)
197  {
199  }
200  else
201  {
202  m_flag &= ~LP_WITHIN_THR;
203  }
204 
205  if (m_flag & LP_WITHIN_THR)
206  {
207  return;
208  }
209 
210  m_owdMin = m_sOwd >> 3;
211  m_owdMax = m_sOwd >> 2;
212  m_owdMaxRsv = m_sOwd >> 2;
213 
214  /* happened within inference
215  * drop congestion window to 1 */
216  if (m_flag & LP_WITHIN_INF)
217  {
218  tcb->m_cWnd = 1U * tcb->m_segmentSize;
219  }
220 
221  /* happened after inference
222  * cut congestion window to half */
223  else
224  {
225  tcb->m_cWnd = std::max (tcb->m_cWnd.Get () >> 1U, 1U * tcb->m_segmentSize);
226  }
227 
228  /* record this time of reduction of cwnd */
229  m_lastDrop = timestamp;
230 }
231 
232 std::string
234 {
235  return "TcpLp";
236 }
237 } // namespace ns3
virtual ~TcpLp(void)
Definition: tcp-lp.cc:70
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:91
#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:98
uint32_t m_sOwd
Smoothed One-Way Delay.
Definition: tcp-lp.h:97
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:202
Time MilliSeconds(uint64_t value)
Construct a Time in the indicated unit.
Definition: nstime.h:1022
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:167
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Invokes Congestion Avoidance of TcpNewReno if TcpLp is not within inference.
Definition: tcp-lp.cc:82
#define max(a, b)
Definition: 80211b.c:43
TcpLp is within Threshold.
Definition: tcp-lp.h:92
bool IsZero(void) const
Definition: nstime.h:288
Time m_inference
Current inference period.
Definition: tcp-lp.h:102
TcpLp(void)
Creates an unbound tcp socket.
Definition: tcp-lp.cc:44
uint32_t m_flag
TcpLp state flag.
Definition: tcp-lp.h:96
TcpLp is within Inference.
Definition: tcp-lp.h:93
uint32_t m_owdMax
Maximum One-Way Delay.
Definition: tcp-lp.h:99
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:249
TracedValue< uint32_t > m_cWnd
Congestion window.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across socket.
Definition: tcp-lp.cc:76
Introspection did not find any typical Config paths.
Definition: tcp-lp.h:33
int64_t GetMilliSeconds(void) const
Get an approximation of the time stored in this instance in the indicated unit.
Definition: nstime.h:359
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-lp.cc:233
void RttSample(Ptr< TcpSocketState > tcb)
Estimates minimum and maximum One-Way Delays and calculates the smoothed One-Way Delay.
Definition: tcp-lp.cc:117
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:100
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-lp.cc:34
uint32_t OwdCalculator(Ptr< TcpSocketState > tcb)
Calculates One-Way Delay using Sender and Receiver timestamps.
Definition: tcp-lp.cc:93
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
Time m_lastDrop
Last time when cwnd was reduced.
Definition: tcp-lp.h:101