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 
81  // Floor w to 1 if w == 0
82  if (w == 0)
83  {
84  w = 1;
85  }
86 
87  NS_LOG_DEBUG ("w in segments " << w << " m_cWndCnt " << m_cWndCnt << " segments acked " << segmentsAcked);
88  if (m_cWndCnt >= w)
89  {
90  m_cWndCnt = 0;
91  tcb->m_cWnd += tcb->m_segmentSize;
92  NS_LOG_DEBUG ("Adding 1 segment to m_cWnd");
93  }
94 
95  m_cWndCnt += segmentsAcked;
96  NS_LOG_DEBUG ("Adding 1 segment to m_cWndCnt");
97  if (m_cWndCnt >= w)
98  {
99  uint32_t delta = m_cWndCnt / w;
100 
101  m_cWndCnt -= delta * w;
102  tcb->m_cWnd += delta * tcb->m_segmentSize;
103  NS_LOG_DEBUG ("Subtracting delta * w from m_cWndCnt " << delta * w);
104  }
105  NS_LOG_DEBUG ("At end of CongestionAvoidance(), m_cWnd: " << tcb->m_cWnd << " m_cWndCnt: " << m_cWndCnt);
106 }
107 
108 void
110 {
111  NS_LOG_FUNCTION (this << tcb << segmentsAcked);
112 
113  // Linux tcp_in_slow_start() condition
114  if (tcb->m_cWnd < tcb->m_ssThresh)
115  {
116  NS_LOG_DEBUG ("In slow start, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
117  segmentsAcked = SlowStart (tcb, segmentsAcked);
118  }
119  else
120  {
121  NS_LOG_DEBUG ("In cong. avoidance, m_cWnd " << tcb->m_cWnd << " m_ssThresh " << tcb->m_ssThresh);
122  CongestionAvoidance (tcb, segmentsAcked);
123  }
124 }
125 
126 std::string
128 {
129  return "TcpLinuxReno";
130 }
131 
132 uint32_t
134  uint32_t bytesInFlight)
135 {
136  NS_LOG_FUNCTION (this << state << bytesInFlight);
137 
138  // In Linux, it is written as: return max(tp->snd_cwnd >> 1U, 2U);
139  return std::max<uint32_t> (2 * state->m_segmentSize, state->m_cWnd / 2);
140 }
141 
144 {
145  return CopyObject<TcpLinuxReno> (this);
146 }
147 
148 } // namespace ns3
#define min(a, b)
Definition: 80211b.c:42
Congestion control abstract class.
Reno congestion control algorithm.
virtual void IncreaseWindow(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance algorithm implementation.
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
std::string GetName() const
Get the name of the congestion control algorithm.
virtual uint32_t SlowStart(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Slow start phase handler.
virtual void CongestionAvoidance(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked)
Congestion avoidance phase handler.
uint32_t m_cWndCnt
Linear increase counter.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_segmentSize
Segment size.
TracedValue< uint32_t > m_cWnd
Congestion window.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
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_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
Every class exported by the ns3 library is enclosed in the ns3 namespace.