A Discrete-Event Network Simulator
API
tcp-dctcp.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 NITK Surathkal
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Shravya K.S. <shravya.ks0@gmail.com>
18  *
19  */
20 
21 #include "tcp-dctcp.h"
22 
23 #include "ns3/abort.h"
24 #include "ns3/log.h"
25 #include "ns3/tcp-socket-state.h"
26 
27 namespace ns3
28 {
29 
30 NS_LOG_COMPONENT_DEFINE("TcpDctcp");
31 
33 
34 TypeId
36 {
37  static TypeId tid =
38  TypeId("ns3::TcpDctcp")
40  .AddConstructor<TcpDctcp>()
41  .SetGroupName("Internet")
42  .AddAttribute("DctcpShiftG",
43  "Parameter G for updating dctcp_alpha",
44  DoubleValue(0.0625),
46  MakeDoubleChecker<double>(0, 1))
47  .AddAttribute("DctcpAlphaOnInit",
48  "Initial alpha value",
49  DoubleValue(1.0),
51  MakeDoubleChecker<double>(0, 1))
52  .AddAttribute("UseEct0",
53  "Use ECT(0) for ECN codepoint, if false use ECT(1)",
54  BooleanValue(true),
57  .AddTraceSource("CongestionEstimate",
58  "Update sender-side congestion estimate state",
60  "ns3::TcpDctcp::CongestionEstimateTracedCallback");
61  return tid;
62 }
63 
64 std::string
66 {
67  return "TcpDctcp";
68 }
69 
71  : TcpLinuxReno(),
72  m_ackedBytesEcn(0),
73  m_ackedBytesTotal(0),
74  m_priorRcvNxt(SequenceNumber32(0)),
75  m_priorRcvNxtFlag(false),
76  m_nextSeq(SequenceNumber32(0)),
77  m_nextSeqFlag(false),
78  m_ceState(false),
79  m_delayedAckReserved(false),
80  m_initialized(false)
81 {
82  NS_LOG_FUNCTION(this);
83 }
84 
86  : TcpLinuxReno(sock),
87  m_ackedBytesEcn(sock.m_ackedBytesEcn),
88  m_ackedBytesTotal(sock.m_ackedBytesTotal),
89  m_priorRcvNxt(sock.m_priorRcvNxt),
90  m_priorRcvNxtFlag(sock.m_priorRcvNxtFlag),
91  m_alpha(sock.m_alpha),
92  m_nextSeq(sock.m_nextSeq),
93  m_nextSeqFlag(sock.m_nextSeqFlag),
94  m_ceState(sock.m_ceState),
95  m_delayedAckReserved(sock.m_delayedAckReserved),
96  m_g(sock.m_g),
97  m_useEct0(sock.m_useEct0),
98  m_initialized(sock.m_initialized)
99 {
100  NS_LOG_FUNCTION(this);
101 }
102 
104 {
105  NS_LOG_FUNCTION(this);
106 }
107 
110 {
111  NS_LOG_FUNCTION(this);
112  return CopyObject<TcpDctcp>(this);
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION(this << tcb);
119  NS_LOG_INFO(this << "Enabling DctcpEcn for DCTCP");
123  m_initialized = true;
124 }
125 
126 // Step 9, Section 3.3 of RFC 8257. GetSsThresh() is called upon
127 // entering the CWR state, and then later, when CWR is exited,
128 // cwnd is set to ssthresh (this value). bytesInFlight is ignored.
129 uint32_t
131 {
132  NS_LOG_FUNCTION(this << tcb << bytesInFlight);
133  return static_cast<uint32_t>((1 - m_alpha / 2.0) * tcb->m_cWnd);
134 }
135 
136 void
137 TcpDctcp::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt)
138 {
139  NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
140  m_ackedBytesTotal += segmentsAcked * tcb->m_segmentSize;
142  {
143  m_ackedBytesEcn += segmentsAcked * tcb->m_segmentSize;
144  }
145  if (m_nextSeqFlag == false)
146  {
148  m_nextSeqFlag = true;
149  }
150  if (tcb->m_lastAckedSeq >= m_nextSeq)
151  {
152  double bytesEcn = 0.0; // Corresponds to variable M in RFC 8257
153  if (m_ackedBytesTotal > 0)
154  {
155  bytesEcn = static_cast<double>(m_ackedBytesEcn * 1.0 / m_ackedBytesTotal);
156  }
157  m_alpha = (1.0 - m_g) * m_alpha + m_g * bytesEcn;
159  NS_LOG_INFO(this << "bytesEcn " << bytesEcn << ", m_alpha " << m_alpha);
160  Reset(tcb);
161  }
162 }
163 
164 void
166 {
167  NS_LOG_FUNCTION(this << alpha);
168  NS_ABORT_MSG_IF(m_initialized, "DCTCP has already been initialized");
169  m_alpha = alpha;
170 }
171 
172 void
174 {
175  NS_LOG_FUNCTION(this << tcb);
177  m_ackedBytesEcn = 0;
178  m_ackedBytesTotal = 0;
179 }
180 
181 void
183 {
184  NS_LOG_FUNCTION(this << tcb);
186  {
187  SequenceNumber32 tmpRcvNxt;
188  /* Save current NextRxSequence. */
189  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
190 
191  /* Generate previous ACK without ECE */
192  tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
194 
195  /* Recover current RcvNxt. */
196  tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
197  }
198 
199  if (m_priorRcvNxtFlag == false)
200  {
201  m_priorRcvNxtFlag = true;
202  }
203  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
204  m_ceState = true;
206 }
207 
208 void
210 {
211  NS_LOG_FUNCTION(this << tcb);
213  {
214  SequenceNumber32 tmpRcvNxt;
215  /* Save current NextRxSequence. */
216  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
217 
218  /* Generate previous ACK with ECE */
219  tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
221 
222  /* Recover current RcvNxt. */
223  tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
224  }
225 
226  if (m_priorRcvNxtFlag == false)
227  {
228  m_priorRcvNxtFlag = true;
229  }
230  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
231  m_ceState = false;
232 
235  {
237  }
238 }
239 
240 void
242 {
243  NS_LOG_FUNCTION(this << tcb << event);
244  switch (event)
245  {
248  {
249  m_delayedAckReserved = true;
250  }
251  break;
254  {
255  m_delayedAckReserved = false;
256  }
257  break;
258  default:
259  /* Don't care for the rest. */
260  break;
261  }
262 }
263 
264 void
266 {
267  NS_LOG_FUNCTION(this << tcb << event);
268  switch (event)
269  {
271  CeState0to1(tcb);
272  break;
274  CeState1to0(tcb);
275  break;
278  UpdateAckReserved(tcb, event);
279  break;
280  default:
281  /* Don't care for the rest. */
282  break;
283  }
284 }
285 
286 } // namespace ns3
AttributeValue implementation for Boolean.
Definition: boolean.h:37
This class can be used to hold variables of floating point type such as 'double' or 'float'.
Definition: double.h:42
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
An implementation of DCTCP.
Definition: tcp-dctcp.h:39
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition: tcp-dctcp.cc:109
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-dctcp.cc:35
SequenceNumber32 m_priorRcvNxt
Sequence number of the first missing byte in data.
Definition: tcp-dctcp.h:132
double m_alpha
Parameter used to estimate the amount of network congestion.
Definition: tcp-dctcp.h:134
double m_g
Estimation gain.
Definition: tcp-dctcp.h:140
bool m_initialized
Whether DCTCP has been initialized.
Definition: tcp-dctcp.h:142
bool m_ceState
DCTCP Congestion Experienced state.
Definition: tcp-dctcp.h:138
bool m_priorRcvNxtFlag
Variable used in setting the value of m_priorRcvNxt for first time.
Definition: tcp-dctcp.h:133
void InitializeDctcpAlpha(double alpha)
Initialize the value of m_alpha.
Definition: tcp-dctcp.cc:165
SequenceNumber32 m_nextSeq
TCP sequence number threshold for beginning a new observation window.
Definition: tcp-dctcp.h:136
uint32_t m_ackedBytesEcn
Number of acked bytes which are marked.
Definition: tcp-dctcp.h:130
void Init(Ptr< TcpSocketState > tcb) override
Set configuration required by congestion control algorithm, This method will force DctcpEcn mode and ...
Definition: tcp-dctcp.cc:116
TcpDctcp()
Create an unbound tcp socket.
Definition: tcp-dctcp.cc:70
void Reset(Ptr< TcpSocketState > tcb)
Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq.
Definition: tcp-dctcp.cc:173
uint32_t m_ackedBytesTotal
Total number of acked bytes.
Definition: tcp-dctcp.h:131
bool m_nextSeqFlag
Variable used in setting the value of m_nextSeq for first time.
Definition: tcp-dctcp.h:137
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-dctcp.cc:65
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition: tcp-dctcp.cc:130
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-dctcp.cc:137
void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event) override
Trigger events/calculations on occurrence of congestion window event.
Definition: tcp-dctcp.cc:265
void CeState1to0(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to false.
Definition: tcp-dctcp.cc:209
void UpdateAckReserved(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Updates the value of m_delayedAckReserved.
Definition: tcp-dctcp.cc:241
bool m_delayedAckReserved
Delayed Ack state.
Definition: tcp-dctcp.h:139
TracedCallback< uint32_t, uint32_t, double > m_traceCongestionEstimate
Callback pointer for congestion state update.
Definition: tcp-dctcp.h:146
bool m_useEct0
Use ECT(0) for ECN codepoint.
Definition: tcp-dctcp.h:141
void CeState0to1(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to true.
Definition: tcp-dctcp.cc:182
~TcpDctcp() override
Destructor.
Definition: tcp-dctcp.cc:103
Reno congestion control algorithm.
uint32_t m_segmentSize
Segment size.
TcpCAEvent_t
Congestion avoidance events.
@ CA_EVENT_ECN_IS_CE
received CE marked IP packet.
@ CA_EVENT_ECN_NO_CE
ECT set, but not CE marked.
@ CA_EVENT_DELAYED_ACK
Delayed ack is sent.
@ CA_EVENT_NON_DELAYED_ACK
Non-delayed ack is sent.
EcnMode_t m_ecnMode
ECN mode.
Callback< void, uint8_t > m_sendEmptyPacketCallback
Callback to send an empty packet.
UseEcn_t m_useEcn
Socket ECN capability.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
@ DctcpEcn
ECN functionality as described in RFC 8257.
@ ECN_ECE_RCVD
Last ACK received had ECE bit set in TCP header.
@ ECN_IDLE
ECN is enabled but currently there is no action pertaining to ECE or CWR to be taken.
@ ECN_CE_RCVD
Last packet received had CE bit set in IP header.
@ ECN_SENDING_ECE
Receiver sends an ACK with ECE bit set in TCP header.
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.
TracedValue< EcnState_t > m_ecnState
Current ECN State, represented as combination of EcnState values.
EcnCodePoint_t m_ectCodePoint
ECT code point to use.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
T Get() const
Get the underlying value.
Definition: traced-value.h:249
a unique identifier for an interface.
Definition: type-id.h:60
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:935
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: boolean.h:86
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: double.h:43
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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:275
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Every class exported by the ns3 library is enclosed in the ns3 namespace.