A Discrete-Event Network Simulator
API
tcp-linux-reno.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 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  * Author: Apoorva Bhargava <apoorvabhargava13@gmail.com>
19  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
20  *
21  */
22 
23 #include "tcp-linux-reno.h"
24 #include "ns3/log.h"
25 #include "ns3/simulator.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("TcpLinuxReno");
30 NS_OBJECT_ENSURE_REGISTERED (TcpLinuxReno);
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::TcpLinuxReno")
37  .SetGroupName ("Internet")
38  .AddConstructor<TcpLinuxReno> ()
39  ;
40  return tid;
41 }
42 
44 {
45  NS_LOG_FUNCTION (this);
46 }
47 
49  : TcpCongestionOps (sock)
50 {
51  NS_LOG_FUNCTION (this);
52 }
53 
55 {
56 }
57 
58 uint32_t
59 TcpLinuxReno::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
60 {
61  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
62 
63  if (segmentsAcked >= 1)
64  {
65  uint32_t sndCwnd = tcb->m_cWnd;
66  tcb->m_cWnd = std::min ((sndCwnd + (segmentsAcked * tcb->m_segmentSize)), (uint32_t)tcb->m_ssThresh);
67  NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
68  return segmentsAcked - ((tcb->m_cWnd - sndCwnd) / tcb->m_segmentSize);
69  }
70 
71  return 0;
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
78 
79  uint32_t w = tcb->m_cWnd / tcb->m_segmentSize;
80  NS_LOG_DEBUG ("w in segments " << w << " m_cWndCnt " << m_cWndCnt << " segments acked " << segmentsAcked);
81  if (m_cWndCnt >= w)
82  {
83  m_cWndCnt = 0;
84  tcb->m_cWnd += tcb->m_segmentSize;
85  NS_LOG_DEBUG ("Adding 1 segment to m_cWnd");
86  }
87 
88  m_cWndCnt += segmentsAcked;
89  NS_LOG_DEBUG ("Adding 1 segment to m_cWndCnt");
90  if (m_cWndCnt >= w)
91  {
92  uint32_t delta = m_cWndCnt / w;
93 
94  m_cWndCnt -= delta * w;
95  tcb->m_cWnd += delta * tcb->m_segmentSize;
96  NS_LOG_DEBUG ("Subtracting delta * w from m_cWndCnt " << delta * w);
97  }
98  NS_LOG_DEBUG ("At end of CongestionAvoidance(), m_cWnd: " << tcb->m_cWnd << " m_cWndCnt: " << m_cWndCnt);
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
105 
106  // Linux tcp_in_slow_start() condition
107  if (tcb->m_cWnd < tcb->m_ssThresh)
108  {
109  NS_LOG_DEBUG ("In slow start, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
110  segmentsAcked = SlowStart (tcb, segmentsAcked);
111  }
112  else
113  {
114  NS_LOG_DEBUG ("In cong. avoidance, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
115  CongestionAvoidance (tcb, segmentsAcked);
116  }
117 }
118 
119 std::string
121 {
122  return "TcpLinuxReno";
123 }
124 
125 uint32_t
127  uint32_t bytesInFlight)
128 {
129  NS_LOG_FUNCTION (this << state << bytesInFlight);
130 
131  // In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
132  return std::max<uint32_t> (2 * state->m_segmentSize, state->m_cWnd / 2);
133 }
134 
135 void
137 {
138  NS_LOG_FUNCTION (this << tcb);
139 
140  tcb->m_cWnd = std::max ( tcb->m_cWnd.Get () / 2, tcb->m_segmentSize);
141 }
142 
145 {
146  return CopyObject<TcpLinuxReno> (this);
147 }
148 
149 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
virtual void ReduceCwnd(Ptr< TcpSocketState > tcb)
Reduces congestion window on receipt of ECN Echo Flag.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
#define min(a, b)
Definition: 80211b.c:42
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
uint32_t m_segmentSize
Segment size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
uint32_t m_cWndCnt
Linear increase counter.
std::string GetName() const
Get the name of the congestion control algorithm.
#define max(a, b)
Definition: 80211b.c:43
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
Congestion control abstract class.
Introspection did not find any typical Config paths.
TracedValue< uint32_t > m_cWnd
Congestion window.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
T Get(void) const
Get the underlying value.
Definition: traced-value.h:229
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923