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 "tcp-socket-state.h"
24 
25 #include "ns3/abort.h"
26 #include "ns3/log.h"
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("TcpDctcp");
32 
34 
35 TypeId
37 {
38  static TypeId tid =
39  TypeId("ns3::TcpDctcp")
41  .AddConstructor<TcpDctcp>()
42  .SetGroupName("Internet")
43  .AddAttribute("DctcpShiftG",
44  "Parameter G for updating dctcp_alpha",
45  DoubleValue(0.0625),
47  MakeDoubleChecker<double>(0, 1))
48  .AddAttribute("DctcpAlphaOnInit",
49  "Initial alpha value",
50  DoubleValue(1.0),
52  MakeDoubleChecker<double>(0, 1))
53  .AddAttribute("UseEct0",
54  "Use ECT(0) for ECN codepoint, if false use ECT(1)",
55  BooleanValue(true),
58  .AddTraceSource("CongestionEstimate",
59  "Update sender-side congestion estimate state",
61  "ns3::TcpDctcp::CongestionEstimateTracedCallback");
62  return tid;
63 }
64 
65 std::string
67 {
68  return "TcpDctcp";
69 }
70 
72  : TcpLinuxReno(),
73  m_ackedBytesEcn(0),
74  m_ackedBytesTotal(0),
75  m_priorRcvNxt(SequenceNumber32(0)),
76  m_priorRcvNxtFlag(false),
77  m_nextSeq(SequenceNumber32(0)),
78  m_nextSeqFlag(false),
79  m_ceState(false),
80  m_delayedAckReserved(false),
81  m_initialized(false)
82 {
83  NS_LOG_FUNCTION(this);
84 }
85 
87  : TcpLinuxReno(sock),
88  m_ackedBytesEcn(sock.m_ackedBytesEcn),
89  m_ackedBytesTotal(sock.m_ackedBytesTotal),
90  m_priorRcvNxt(sock.m_priorRcvNxt),
91  m_priorRcvNxtFlag(sock.m_priorRcvNxtFlag),
92  m_alpha(sock.m_alpha),
93  m_nextSeq(sock.m_nextSeq),
94  m_nextSeqFlag(sock.m_nextSeqFlag),
95  m_ceState(sock.m_ceState),
96  m_delayedAckReserved(sock.m_delayedAckReserved),
97  m_g(sock.m_g),
98  m_useEct0(sock.m_useEct0),
99  m_initialized(sock.m_initialized)
100 {
101  NS_LOG_FUNCTION(this);
102 }
103 
105 {
106  NS_LOG_FUNCTION(this);
107 }
108 
111 {
112  NS_LOG_FUNCTION(this);
113  return CopyObject<TcpDctcp>(this);
114 }
115 
116 void
118 {
119  NS_LOG_FUNCTION(this << tcb);
120  NS_LOG_INFO(this << "Enabling DctcpEcn for DCTCP");
124  m_initialized = true;
125 }
126 
127 // Step 9, Section 3.3 of RFC 8257. GetSsThresh() is called upon
128 // entering the CWR state, and then later, when CWR is exited,
129 // cwnd is set to ssthresh (this value). bytesInFlight is ignored.
130 uint32_t
132 {
133  NS_LOG_FUNCTION(this << tcb << bytesInFlight);
134  return static_cast<uint32_t>((1 - m_alpha / 2.0) * tcb->m_cWnd);
135 }
136 
137 void
138 TcpDctcp::PktsAcked(Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time& rtt)
139 {
140  NS_LOG_FUNCTION(this << tcb << segmentsAcked << rtt);
141  m_ackedBytesTotal += segmentsAcked * tcb->m_segmentSize;
143  {
144  m_ackedBytesEcn += segmentsAcked * tcb->m_segmentSize;
145  }
146  if (!m_nextSeqFlag)
147  {
149  m_nextSeqFlag = true;
150  }
151  if (tcb->m_lastAckedSeq >= m_nextSeq)
152  {
153  double bytesEcn = 0.0; // Corresponds to variable M in RFC 8257
154  if (m_ackedBytesTotal > 0)
155  {
156  bytesEcn = static_cast<double>(m_ackedBytesEcn * 1.0 / m_ackedBytesTotal);
157  }
158  m_alpha = (1.0 - m_g) * m_alpha + m_g * bytesEcn;
160  NS_LOG_INFO(this << "bytesEcn " << bytesEcn << ", m_alpha " << m_alpha);
161  Reset(tcb);
162  }
163 }
164 
165 void
167 {
168  NS_LOG_FUNCTION(this << alpha);
169  NS_ABORT_MSG_IF(m_initialized, "DCTCP has already been initialized");
170  m_alpha = alpha;
171 }
172 
173 void
175 {
176  NS_LOG_FUNCTION(this << tcb);
178  m_ackedBytesEcn = 0;
179  m_ackedBytesTotal = 0;
180 }
181 
182 void
184 {
185  NS_LOG_FUNCTION(this << tcb);
187  {
188  SequenceNumber32 tmpRcvNxt;
189  /* Save current NextRxSequence. */
190  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
191 
192  /* Generate previous ACK without ECE */
193  tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
195 
196  /* Recover current RcvNxt. */
197  tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
198  }
199 
200  if (!m_priorRcvNxtFlag)
201  {
202  m_priorRcvNxtFlag = true;
203  }
204  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
205  m_ceState = true;
207 }
208 
209 void
211 {
212  NS_LOG_FUNCTION(this << tcb);
214  {
215  SequenceNumber32 tmpRcvNxt;
216  /* Save current NextRxSequence. */
217  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence();
218 
219  /* Generate previous ACK with ECE */
220  tcb->m_rxBuffer->SetNextRxSequence(m_priorRcvNxt);
222 
223  /* Recover current RcvNxt. */
224  tcb->m_rxBuffer->SetNextRxSequence(tmpRcvNxt);
225  }
226 
227  if (!m_priorRcvNxtFlag)
228  {
229  m_priorRcvNxtFlag = true;
230  }
231  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence();
232  m_ceState = false;
233 
236  {
238  }
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION(this << tcb << event);
245  switch (event)
246  {
249  {
250  m_delayedAckReserved = true;
251  }
252  break;
255  {
256  m_delayedAckReserved = false;
257  }
258  break;
259  default:
260  /* Don't care for the rest. */
261  break;
262  }
263 }
264 
265 void
267 {
268  NS_LOG_FUNCTION(this << tcb << event);
269  switch (event)
270  {
272  CeState0to1(tcb);
273  break;
275  CeState1to0(tcb);
276  break;
279  UpdateAckReserved(tcb, event);
280  break;
281  default:
282  /* Don't care for the rest. */
283  break;
284  }
285 }
286 
287 } // namespace ns3
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:77
An implementation of DCTCP.
Definition: tcp-dctcp.h:43
Ptr< TcpCongestionOps > Fork() override
Copy the congestion control algorithm across sockets.
Definition: tcp-dctcp.cc:110
static TypeId GetTypeId()
Get the type ID.
Definition: tcp-dctcp.cc:36
SequenceNumber32 m_priorRcvNxt
Sequence number of the first missing byte in data.
Definition: tcp-dctcp.h:136
double m_alpha
Parameter used to estimate the amount of network congestion.
Definition: tcp-dctcp.h:138
double m_g
Estimation gain.
Definition: tcp-dctcp.h:144
bool m_initialized
Whether DCTCP has been initialized.
Definition: tcp-dctcp.h:146
bool m_ceState
DCTCP Congestion Experienced state.
Definition: tcp-dctcp.h:142
bool m_priorRcvNxtFlag
Variable used in setting the value of m_priorRcvNxt for first time.
Definition: tcp-dctcp.h:137
void InitializeDctcpAlpha(double alpha)
Initialize the value of m_alpha.
Definition: tcp-dctcp.cc:166
SequenceNumber32 m_nextSeq
TCP sequence number threshold for beginning a new observation window.
Definition: tcp-dctcp.h:140
uint32_t m_ackedBytesEcn
Number of acked bytes which are marked.
Definition: tcp-dctcp.h:134
void Init(Ptr< TcpSocketState > tcb) override
Set configuration required by congestion control algorithm, This method will force DctcpEcn mode and ...
Definition: tcp-dctcp.cc:117
TcpDctcp()
Create an unbound tcp socket.
Definition: tcp-dctcp.cc:71
void Reset(Ptr< TcpSocketState > tcb)
Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq.
Definition: tcp-dctcp.cc:174
uint32_t m_ackedBytesTotal
Total number of acked bytes.
Definition: tcp-dctcp.h:135
bool m_nextSeqFlag
Variable used in setting the value of m_nextSeq for first time.
Definition: tcp-dctcp.h:141
std::string GetName() const override
Get the name of the congestion control algorithm.
Definition: tcp-dctcp.cc:66
uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight) override
Get the slow start threshold after a loss event.
Definition: tcp-dctcp.cc:131
void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt) override
Timing information on received ACK.
Definition: tcp-dctcp.cc:138
void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event) override
Trigger events/calculations on occurrence of congestion window event.
Definition: tcp-dctcp.cc:266
void CeState1to0(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to false.
Definition: tcp-dctcp.cc:210
void UpdateAckReserved(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Updates the value of m_delayedAckReserved.
Definition: tcp-dctcp.cc:242
bool m_delayedAckReserved
Delayed Ack state.
Definition: tcp-dctcp.h:143
TracedCallback< uint32_t, uint32_t, double > m_traceCongestionEstimate
Callback pointer for congestion state update.
Definition: tcp-dctcp.h:150
bool m_useEct0
Use ECT(0) for ECN codepoint.
Definition: tcp-dctcp.h:145
void CeState0to1(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to true.
Definition: tcp-dctcp.cc:183
~TcpDctcp() override
Destructor.
Definition: tcp-dctcp.cc:104
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:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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.
Ptr< const AttributeChecker > MakeBooleanChecker()
Definition: boolean.cc:124
Ptr< const AttributeAccessor > MakeBooleanAccessor(T1 a1)
Definition: boolean.h:86
Ptr< const AttributeAccessor > MakeDoubleAccessor(T1 a1)
Definition: double.h:43