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 "ns3/tcp-congestion-ops.h"
26 #include "ns3/log.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("TcpPrrRecovery");
31 NS_OBJECT_ENSURE_REGISTERED (TcpPrrRecovery);
32 
33 TypeId
35 {
36  static TypeId tid = TypeId ("ns3::TcpPrrRecovery")
38  .AddConstructor<TcpPrrRecovery> ()
39  .SetGroupName ("Internet")
40  .AddAttribute ("ReductionBound", "Type of Reduction Bound",
41  EnumValue (SSRB),
43  MakeEnumChecker (CRB, "CRB",
44  SSRB, "SSRB"))
45  ;
46  return tid;
47 }
48 
51 {
52  NS_LOG_FUNCTION (this);
53 }
54 
56  : TcpClassicRecovery (recovery),
57  m_prrDelivered (recovery.m_prrDelivered),
58  m_prrOut (recovery.m_prrOut),
59  m_recoveryFlightSize (recovery.m_recoveryFlightSize),
60  m_reductionBoundMode (recovery.m_reductionBoundMode)
61 {
62  NS_LOG_FUNCTION (this);
63 }
64 
66 {
67  NS_LOG_FUNCTION (this);
68 }
69 
70 void
72  uint32_t unAckDataCount, uint32_t deliveredBytes)
73 {
74  NS_LOG_FUNCTION (this << tcb << dupAckCount << unAckDataCount);
75  NS_UNUSED (dupAckCount);
76 
77  m_prrOut = 0;
78  m_prrDelivered = 0;
79  m_recoveryFlightSize = unAckDataCount;
80 
81  DoRecovery (tcb, deliveredBytes);
82 }
83 
84 void
85 TcpPrrRecovery::DoRecovery (Ptr<TcpSocketState> tcb, uint32_t deliveredBytes)
86 {
87  NS_LOG_FUNCTION (this << tcb << deliveredBytes);
88  m_prrDelivered += deliveredBytes;
89 
90  int sendCount;
91  if (tcb->m_bytesInFlight > tcb->m_ssThresh)
92  {
93  sendCount = std::ceil (m_prrDelivered * tcb->m_ssThresh * 1.0 / m_recoveryFlightSize) - m_prrOut;
94  }
95  else
96  {
97  int limit = static_cast<int> (tcb->m_ssThresh - tcb->m_bytesInFlight);
99  {
100  limit = m_prrDelivered - m_prrOut;
101  }
102  else if (m_reductionBoundMode == SSRB)
103  {
104  limit = std::max (m_prrDelivered - m_prrOut, deliveredBytes) + tcb->m_segmentSize;
105  }
106  sendCount = std::min (limit, static_cast<int> (tcb->m_ssThresh - tcb->m_bytesInFlight));
107  }
108 
109  /* Force a fast retransmit upon entering fast recovery */
110  sendCount = std::max (sendCount, static_cast<int> (m_prrOut > 0 ? 0 : tcb->m_segmentSize));
111  tcb->m_cWnd = tcb->m_bytesInFlight + sendCount;
112  tcb->m_cWndInfl = tcb->m_cWnd;
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << tcb);
119  tcb->m_cWnd = tcb->m_ssThresh.Get ();
120  tcb->m_cWndInfl = tcb->m_cWnd;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << bytesSent);
127  m_prrOut += bytesSent;
128 }
129 
132 {
133  return CopyObject<TcpPrrRecovery> (this);
134 }
135 
136 std::string
138 {
139  return "PrrRecovery";
140 }
141 
142 } // 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
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:209
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:204
#define NS_UNUSED(x)
Mark a local variable as unused.
Definition: unused.h:36
uint32_t m_segmentSize
Segment size.
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.
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.
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
T Get(void) const
Get the underlying value.
Definition: traced-value.h:218
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:915
virtual ~TcpPrrRecovery(void) override