A Discrete-Event Network Simulator
API
tcp-prr-recovery.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2018 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: Viyom Mittal <viyommittal@gmail.com>
19  * Vivek Jain <jain.vivek.anand@gmail.com>
20  * Mohit P. Tahiliani <tahiliani@nitk.edu.in>
21  *
22  */
23 
24 #include "tcp-prr-recovery.h"
25 #include "tcp-socket-state.h"
26 
27 #include "ns3/log.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("TcpPrrRecovery");
32 NS_OBJECT_ENSURE_REGISTERED (TcpPrrRecovery);
33 
34 TypeId
36 {
37  static TypeId tid = TypeId ("ns3::TcpPrrRecovery")
39  .AddConstructor<TcpPrrRecovery> ()
40  .SetGroupName ("Internet")
41  .AddAttribute ("ReductionBound", "Type of Reduction Bound",
42  EnumValue (SSRB),
44  MakeEnumChecker (CRB, "CRB",
45  SSRB, "SSRB"))
46  ;
47  return tid;
48 }
49 
52 {
53  NS_LOG_FUNCTION (this);
54 }
55 
57  : TcpClassicRecovery (recovery),
58  m_prrDelivered (recovery.m_prrDelivered),
59  m_prrOut (recovery.m_prrOut),
60  m_recoveryFlightSize (recovery.m_recoveryFlightSize),
61  m_reductionBoundMode (recovery.m_reductionBoundMode)
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
71 void
73  uint32_t unAckDataCount, uint32_t deliveredBytes)
74 {
75  NS_LOG_FUNCTION (this << tcb << dupAckCount << unAckDataCount);
76  NS_UNUSED (dupAckCount);
77 
78  m_prrOut = 0;
79  m_prrDelivered = 0;
80  m_recoveryFlightSize = unAckDataCount;
81 
82  DoRecovery (tcb, deliveredBytes);
83 }
84 
85 void
86 TcpPrrRecovery::DoRecovery (Ptr<TcpSocketState> tcb, uint32_t deliveredBytes)
87 {
88  NS_LOG_FUNCTION (this << tcb << deliveredBytes);
89  m_prrDelivered += deliveredBytes;
90 
91  int sendCount;
92  if (tcb->m_bytesInFlight > tcb->m_ssThresh)
93  {
94  sendCount = std::ceil (m_prrDelivered * tcb->m_ssThresh * 1.0 / m_recoveryFlightSize) - m_prrOut;
95  }
96  else
97  {
98  int limit = static_cast<int> (tcb->m_ssThresh - tcb->m_bytesInFlight);
100  {
101  limit = m_prrDelivered - m_prrOut;
102  }
103  else if (m_reductionBoundMode == SSRB)
104  {
105  if (tcb->m_isRetransDataAcked)
106  {
107  limit = std::max (m_prrDelivered - m_prrOut, deliveredBytes) + tcb->m_segmentSize;
108  }
109  else
110  {
111  limit = deliveredBytes;
112  }
113  }
114  sendCount = std::min (limit, static_cast<int> (tcb->m_ssThresh - tcb->m_bytesInFlight));
115  }
116 
117  /* Force a fast retransmit upon entering fast recovery */
118  sendCount = std::max (sendCount, static_cast<int> (m_prrOut > 0 ? 0 : tcb->m_segmentSize));
119  tcb->m_cWnd = tcb->m_bytesInFlight + sendCount;
120  tcb->m_cWndInfl = tcb->m_cWnd;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << tcb);
127  tcb->m_cWnd = tcb->m_ssThresh.Get ();
128  tcb->m_cWndInfl = tcb->m_cWnd;
129 }
130 
131 void
133 {
134  NS_LOG_FUNCTION (this << bytesSent);
135  m_prrOut += bytesSent;
136 }
137 
140 {
141  return CopyObject<TcpPrrRecovery> (this);
142 }
143 
144 std::string
146 {
147  return "PrrRecovery";
148 }
149 
150 } // namespace ns3
virtual void ExitRecovery(Ptr< TcpSocketState > tcb) override
Performs cwnd adjustments at the end of recovery.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Slow Start Reduction Bound.
virtual void UpdateBytesSent(uint32_t bytesSent) override
Keeps track of bytes sent during recovery phase.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual void DoRecovery(Ptr< TcpSocketState > tcb, uint32_t deliveredBytes) override
Performs recovery based on the recovery algorithm.
#define min(a, b)
Definition: 80211b.c:42
uint32_t m_recoveryFlightSize
value of bytesInFlight at the start of recovery phase
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uint32_t m_segmentSize
Segment size.
bool m_isRetransDataAcked
Retransmitted data is ACKed if true.
virtual Ptr< TcpRecoveryOps > Fork() override
Copy the recovery algorithm across socket.
TracedValue< uint32_t > m_cWndInfl
Inflated congestion window trace (used only for backward compatibility purpose)
Hold variables of type enum.
Definition: enum.h:54
#define max(a, b)
Definition: 80211b.c:43
virtual void EnterRecovery(Ptr< TcpSocketState > tcb, uint32_t dupAckCount, uint32_t unAckDataCount, uint32_t deliveredBytes) override
Performs variable initialization at the start of recovery.
TcpPrrRecovery(void)
Create an unbound tcp socket.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:203
static TypeId GetTypeId(void)
Get the type ID.
TracedValue< uint32_t > m_bytesInFlight
Bytes in flight.
TracedValue< uint32_t > m_ssThresh
Slow start threshold.
An implementation of PRR.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_prrOut
total bytes sent during recovery phase
ReductionBound_t m_reductionBoundMode
mode of Reduction Bound to be used
TracedValue< uint32_t > m_cWnd
Congestion window.
T Get(void) const
Get the underlying value.
Definition: traced-value.h:229
Ptr< const AttributeChecker > MakeEnumChecker(int v, std::string n, Ts... args)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.h:161
uint32_t m_prrDelivered
total bytes delivered during recovery phase
The Classic recovery implementation.
std::string GetName() const override
Get the name of the recovery algorithm.
Conservative Reduction Bound.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
virtual ~TcpPrrRecovery(void) override