A Discrete-Event Network Simulator
API
tcp-dctcp.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 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: Shravya K.S. <shravya.ks0@gmail.com>
19  *
20  */
21 
22 #include "tcp-dctcp.h"
23 #include "ns3/log.h"
24 #include "ns3/abort.h"
25 #include "ns3/tcp-socket-state.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("TcpDctcp");
30 
32 
34 {
35  static TypeId tid = TypeId ("ns3::TcpDctcp")
37  .AddConstructor<TcpDctcp> ()
38  .SetGroupName ("Internet")
39  .AddAttribute ("DctcpShiftG",
40  "Parameter G for updating dctcp_alpha",
41  DoubleValue (0.0625),
43  MakeDoubleChecker<double> (0, 1))
44  .AddAttribute ("DctcpAlphaOnInit",
45  "Initial alpha value",
46  DoubleValue (1.0),
48  MakeDoubleChecker<double> (0, 1))
49  .AddAttribute ("UseEct0",
50  "Use ECT(0) for ECN codepoint, if false use ECT(1)",
51  BooleanValue (true),
54  .AddTraceSource ("CongestionEstimate",
55  "Update sender-side congestion estimate state",
57  "ns3::TcpDctcp::CongestionEstimateTracedCallback")
58  ;
59  return tid;
60 }
61 
62 std::string TcpDctcp::GetName () const
63 {
64  return "TcpDctcp";
65 }
66 
68  : TcpLinuxReno (),
69  m_ackedBytesEcn (0),
70  m_ackedBytesTotal (0),
71  m_priorRcvNxt (SequenceNumber32 (0)),
72  m_priorRcvNxtFlag (false),
73  m_nextSeq (SequenceNumber32 (0)),
74  m_nextSeqFlag (false),
75  m_ceState (false),
76  m_delayedAckReserved (false),
77  m_initialized (false)
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
83  : TcpLinuxReno (sock),
84  m_ackedBytesEcn (sock.m_ackedBytesEcn),
85  m_ackedBytesTotal (sock.m_ackedBytesTotal),
86  m_priorRcvNxt (sock.m_priorRcvNxt),
87  m_priorRcvNxtFlag (sock.m_priorRcvNxtFlag),
88  m_alpha (sock.m_alpha),
89  m_nextSeq (sock.m_nextSeq),
90  m_nextSeqFlag (sock.m_nextSeqFlag),
91  m_ceState (sock.m_ceState),
92  m_delayedAckReserved (sock.m_delayedAckReserved),
93  m_g (sock.m_g),
94  m_useEct0 (sock.m_useEct0),
95  m_initialized (sock.m_initialized)
96 {
97  NS_LOG_FUNCTION (this);
98 }
99 
101 {
102  NS_LOG_FUNCTION (this);
103 }
104 
106 {
107  NS_LOG_FUNCTION (this);
108  return CopyObject<TcpDctcp> (this);
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION (this << tcb);
115  NS_LOG_INFO (this << "Enabling DctcpEcn for DCTCP");
119  m_initialized = true;
120 }
121 
122 // Step 9, Section 3.3 of RFC 8257. GetSsThresh() is called upon
123 // entering the CWR state, and then later, when CWR is exited,
124 // cwnd is set to ssthresh (this value). bytesInFlight is ignored.
125 uint32_t
127 {
128  NS_LOG_FUNCTION (this << tcb << bytesInFlight);
129  return static_cast<uint32_t> ((1 - m_alpha / 2.0) * tcb->m_cWnd);
130 }
131 
132 void
133 TcpDctcp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time &rtt)
134 {
135  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
136  m_ackedBytesTotal += segmentsAcked * tcb->m_segmentSize;
138  {
139  m_ackedBytesEcn += segmentsAcked * tcb->m_segmentSize;
140  }
141  if (m_nextSeqFlag == false)
142  {
144  m_nextSeqFlag = true;
145  }
146  if (tcb->m_lastAckedSeq >= m_nextSeq)
147  {
148  double bytesEcn = 0.0; // Corresponds to variable M in RFC 8257
149  if (m_ackedBytesTotal > 0)
150  {
151  bytesEcn = static_cast<double> (m_ackedBytesEcn * 1.0 / m_ackedBytesTotal);
152  }
153  m_alpha = (1.0 - m_g) * m_alpha + m_g * bytesEcn;
155  NS_LOG_INFO (this << "bytesEcn " << bytesEcn << ", m_alpha " << m_alpha);
156  Reset (tcb);
157  }
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION (this << alpha);
164  NS_ABORT_MSG_IF (m_initialized, "DCTCP has already been initialized");
165  m_alpha = alpha;
166 }
167 
168 void
170 {
171  NS_LOG_FUNCTION (this << tcb);
173  m_ackedBytesEcn = 0;
174  m_ackedBytesTotal = 0;
175 }
176 
177 void
179 {
180  NS_LOG_FUNCTION (this << tcb);
182  {
183  SequenceNumber32 tmpRcvNxt;
184  /* Save current NextRxSequence. */
185  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
186 
187  /* Generate previous ACK without ECE */
188  tcb->m_rxBuffer->SetNextRxSequence (m_priorRcvNxt);
190 
191  /* Recover current RcvNxt. */
192  tcb->m_rxBuffer->SetNextRxSequence (tmpRcvNxt);
193  }
194 
195  if (m_priorRcvNxtFlag == false)
196  {
197  m_priorRcvNxtFlag = true;
198  }
199  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
200  m_ceState = true;
202 }
203 
204 void
206 {
207  NS_LOG_FUNCTION (this << tcb);
209  {
210  SequenceNumber32 tmpRcvNxt;
211  /* Save current NextRxSequence. */
212  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
213 
214  /* Generate previous ACK with ECE */
215  tcb->m_rxBuffer->SetNextRxSequence (m_priorRcvNxt);
217 
218  /* Recover current RcvNxt. */
219  tcb->m_rxBuffer->SetNextRxSequence (tmpRcvNxt);
220  }
221 
222  if (m_priorRcvNxtFlag == false)
223  {
224  m_priorRcvNxtFlag = true;
225  }
226  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
227  m_ceState = false;
228 
230  {
232  }
233 }
234 
235 void
237  const TcpSocketState::TcpCAEvent_t event)
238 {
239  NS_LOG_FUNCTION (this << tcb << event);
240  switch (event)
241  {
244  {
245  m_delayedAckReserved = true;
246  }
247  break;
250  {
251  m_delayedAckReserved = false;
252  }
253  break;
254  default:
255  /* Don't care for the rest. */
256  break;
257  }
258 }
259 
260 void
262  const TcpSocketState::TcpCAEvent_t event)
263 {
264  NS_LOG_FUNCTION (this << tcb << event);
265  switch (event)
266  {
268  CeState0to1 (tcb);
269  break;
271  CeState1to0 (tcb);
272  break;
275  UpdateAckReserved (tcb, event);
276  break;
277  default:
278  /* Don't care for the rest. */
279  break;
280  }
281 }
282 
283 } // namespace ns3
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Last ACK received had ECE bit set in TCP header.
AttributeValue implementation for Boolean.
Definition: boolean.h:36
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-dctcp.cc:105
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
TcpCAEvent_t
Congestion avoidance events.
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:85
virtual void CwndEvent(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Trigger events/calculations on occurrence of congestion window event.
Definition: tcp-dctcp.cc:261
TracedValue< EcnState_t > m_ecnState
Current ECN State, represented as combination of EcnState values.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
uint32_t m_segmentSize
Segment size.
#define NS_LOG_INFO(msg)
Use NS_LOG to output a message of level LOG_INFO.
Definition: log.h:281
Ptr< TcpRxBuffer > m_rxBuffer
Rx buffer (reordering buffer)
virtual void Init(Ptr< TcpSocketState > tcb)
Set configuration required by congestion control algorithm, This method will force DctcpEcn mode and ...
Definition: tcp-dctcp.cc:112
Receiver sends an ACK with ECE bit set in TCP header.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
Last packet received had CE bit set in IP header.
Callback< void, uint8_t > m_sendEmptyPacketCallback
Callback to send an empty packet.
void CeState1to0(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to false.
Definition: tcp-dctcp.cc:205
bool m_useEct0
Use ECT(0) for ECN codepoint.
Definition: tcp-dctcp.h:141
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-dctcp.cc:62
static TypeId GetTypeId(void)
Get the type ID.
Definition: tcp-dctcp.cc:33
EcnMode_t m_ecnMode
ECN mode.
SequenceNumber32 m_lastAckedSeq
Last sequence ACKed.
ECN is enabled but currently there is no action pertaining to ECE or CWR to be taken.
void UpdateAckReserved(Ptr< TcpSocketState > tcb, const TcpSocketState::TcpCAEvent_t event)
Updates the value of m_delayedAckReserved.
Definition: tcp-dctcp.cc:236
void Reset(Ptr< TcpSocketState > tcb)
Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq.
Definition: tcp-dctcp.cc:169
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-dctcp.cc:133
UseEcn_t m_useEcn
Socket ECN capability.
TracedCallback< uint32_t, uint32_t, double > m_traceCongestionEstimate
Callback pointer for congestion state update.
Definition: tcp-dctcp.h:146
bool m_ceState
DCTCP Congestion Experienced state.
Definition: tcp-dctcp.h:138
ECN functionality as described in RFC 8257.
double m_alpha
Parameter used to estimate the amount of network congestion.
Definition: tcp-dctcp.h:135
SequenceNumber32 m_nextSeq
TCP sequence number threshold for beginning a new observation window.
Definition: tcp-dctcp.h:136
Every class exported by the ns3 library is enclosed in the ns3 namespace.
An implementation of DCTCP.
Definition: tcp-dctcp.h:38
virtual ~TcpDctcp(void)
Destructor.
Definition: tcp-dctcp.cc:100
double m_g
Estimation gain.
Definition: tcp-dctcp.h:140
void InitializeDctcpAlpha(double alpha)
Initialize the value of m_alpha.
Definition: tcp-dctcp.cc:161
void CeState0to1(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to true.
Definition: tcp-dctcp.cc:178
uint32_t m_ackedBytesEcn
Number of acked bytes which are marked.
Definition: tcp-dctcp.h:131
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:42
EcnCodePoint_t m_ectCodePoint
ECT code point to use.
uint32_t m_ackedBytesTotal
Total number of acked bytes.
Definition: tcp-dctcp.h:132
TcpDctcp()
Create an unbound tcp socket.
Definition: tcp-dctcp.cc:67
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
bool m_priorRcvNxtFlag
Variable used in setting the value of m_priorRcvNxt for first time.
Definition: tcp-dctcp.h:134
SequenceNumber32 m_priorRcvNxt
Sequence number of the first missing byte in data.
Definition: tcp-dctcp.h:133
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
bool m_delayedAckReserved
Delayed Ack state.
Definition: tcp-dctcp.h:139
virtual uint32_t GetSsThresh(Ptr< const TcpSocketState > tcb, uint32_t bytesInFlight)
Get the slow start threshold after a loss event.
Definition: tcp-dctcp.cc:126
bool m_nextSeqFlag
Variable used in setting the value of m_nextSeq for first time.
Definition: tcp-dctcp.h:137
bool m_initialized
Whether DCTCP has been initialized.
Definition: tcp-dctcp.h:142
This class can be used to hold variables of floating point type such as &#39;double&#39; or &#39;float&#39;...
Definition: double.h:41
received CE marked IP packet.
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
TracedValue< SequenceNumber32 > m_nextTxSequence
Next seqnum to be sent (SND.NXT), ReTx pushes it back.