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 "math.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  ;
55  return tid;
56 }
57 
58 std::string TcpDctcp::GetName () const
59 {
60  return "TcpDctcp";
61 }
62 
64  : TcpNewReno ()
65 {
66  NS_LOG_FUNCTION (this);
67  m_ackedBytesEcn = 0;
70  m_priorRcvNxtFlag = false;
72  m_nextSeqFlag = false;
73  m_ceState = false;
74  m_delayedAckReserved = false;
75 }
76 
78  : TcpNewReno (sock),
79  m_ackedBytesEcn (sock.m_ackedBytesEcn),
80  m_ackedBytesTotal (sock.m_ackedBytesTotal),
81  m_priorRcvNxt (sock.m_priorRcvNxt),
82  m_priorRcvNxtFlag (sock.m_priorRcvNxtFlag),
83  m_alpha (sock.m_alpha),
84  m_nextSeq (sock.m_nextSeq),
85  m_nextSeqFlag (sock.m_nextSeqFlag),
86  m_ceState (sock.m_ceState),
87  m_delayedAckReserved (sock.m_delayedAckReserved),
88  m_g (sock.m_g),
89  m_useEct0 (sock.m_useEct0)
90 {
91  NS_LOG_FUNCTION (this);
92 }
93 
95 {
96  NS_LOG_FUNCTION (this);
97 }
98 
100 {
101  NS_LOG_FUNCTION (this);
102  return CopyObject<TcpDctcp> (this);
103 }
104 
105 void
107 {
108  NS_LOG_FUNCTION (this << tcb);
109  NS_LOG_INFO (this << "Enabling DctcpEcn for DCTCP");
113 }
114 
115 void
117 {
118  NS_LOG_FUNCTION (this << tcb);
119  uint32_t val = static_cast<uint32_t> ((1 - m_alpha / 2.0) * tcb->m_cWnd);
120  tcb->m_cWnd = std::max (val, 2 * tcb->m_segmentSize);
121 }
122 
123 void
124 TcpDctcp::PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked, const Time &rtt)
125 {
126  NS_LOG_FUNCTION (this << tcb << segmentsAcked << rtt);
127  m_ackedBytesTotal += segmentsAcked * tcb->m_segmentSize;
129  {
130  m_ackedBytesEcn += segmentsAcked * tcb->m_segmentSize;
131  }
132  if (m_nextSeqFlag == false)
133  {
135  m_nextSeqFlag = true;
136  }
137  if (tcb->m_lastAckedSeq >= m_nextSeq)
138  {
139  double bytesEcn = 0.0;
140  if (m_ackedBytesTotal > 0)
141  {
142  bytesEcn = static_cast<double> (m_ackedBytesEcn * 1.0 / m_ackedBytesTotal);
143  }
144  m_alpha = (1.0 - m_g) * m_alpha + m_g * bytesEcn;
145  NS_LOG_INFO (this << "bytesEcn " << bytesEcn << ", m_alpha " << m_alpha);
146  Reset (tcb);
147  }
148 }
149 
150 void
152 {
153  NS_LOG_FUNCTION (this << alpha);
154  m_alpha = alpha;
155 }
156 
157 void
159 {
160  NS_LOG_FUNCTION (this << tcb);
162  m_ackedBytesEcn = 0;
163  m_ackedBytesTotal = 0;
164 }
165 
166 void
168 {
169  NS_LOG_FUNCTION (this << tcb);
171  {
172  SequenceNumber32 tmpRcvNxt;
173  /* Save current NextRxSequence. */
174  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
175 
176  /* Generate previous ACK without ECE */
177  tcb->m_rxBuffer->SetNextRxSequence (m_priorRcvNxt);
179 
180  /* Recover current RcvNxt. */
181  tcb->m_rxBuffer->SetNextRxSequence (tmpRcvNxt);
182  }
183 
184  if (m_priorRcvNxtFlag == false)
185  {
186  m_priorRcvNxtFlag = true;
187  }
188  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
189  m_ceState = true;
191 }
192 
193 void
195 {
196  NS_LOG_FUNCTION (this << tcb);
198  {
199  SequenceNumber32 tmpRcvNxt;
200  /* Save current NextRxSequence. */
201  tmpRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
202 
203  /* Generate previous ACK with ECE */
204  tcb->m_rxBuffer->SetNextRxSequence (m_priorRcvNxt);
206 
207  /* Recover current RcvNxt. */
208  tcb->m_rxBuffer->SetNextRxSequence (tmpRcvNxt);
209  }
210 
211  if (m_priorRcvNxtFlag == false)
212  {
213  m_priorRcvNxtFlag = true;
214  }
215  m_priorRcvNxt = tcb->m_rxBuffer->NextRxSequence ();
216  m_ceState = false;
217 
219  {
221  }
222 }
223 
224 void
226  const TcpSocketState::TcpCAEvent_t event)
227 {
228  NS_LOG_FUNCTION (this << tcb << event);
229  switch (event)
230  {
233  {
234  m_delayedAckReserved = true;
235  }
236  break;
239  {
240  m_delayedAckReserved = false;
241  }
242  break;
243  default:
244  /* Don't care for the rest. */
245  break;
246  }
247 }
248 
249 void
251  const TcpSocketState::TcpCAEvent_t event)
252 {
253  NS_LOG_FUNCTION (this << tcb << event);
254  switch (event)
255  {
257  CeState0to1 (tcb);
258  break;
260  CeState1to0 (tcb);
261  break;
264  UpdateAckReserved (tcb, event);
265  break;
266  default:
267  /* Don't care for the rest. */
268  break;
269  }
270 }
271 
272 } // namespace ns3
log2() macro definition; to deal with Bug 1467.
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
SequenceNumber< uint32_t, int32_t > SequenceNumber32
32 bit Sequence number.
virtual Ptr< TcpCongestionOps > Fork()
Copy the congestion control algorithm across sockets.
Definition: tcp-dctcp.cc:99
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
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:250
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)
The NewReno implementation.
virtual void Init(Ptr< TcpSocketState > tcb)
Set configuration required by congestion control algorithm, This method will force DctcpEcn mode and ...
Definition: tcp-dctcp.cc:106
Receiver sends an ACK with ECE bit set in TCP header.
void SetDctcpAlpha(double alpha)
Sets the value of m_alpha.
Definition: tcp-dctcp.cc:151
Last packet received had CE bit set in IP header.
Callback< void, uint8_t > m_sendEmptyPacketCallback
void CeState1to0(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to false.
Definition: tcp-dctcp.cc:194
bool m_useEct0
Use ECT(0) for ECN codepoint.
Definition: tcp-dctcp.h:129
#define max(a, b)
Definition: 80211b.c:43
virtual std::string GetName() const
Get the name of the congestion control algorithm.
Definition: tcp-dctcp.cc:58
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:225
void Reset(Ptr< TcpSocketState > tcb)
Resets the value of m_ackedBytesEcn, m_ackedBytesTotal and m_nextSeq.
Definition: tcp-dctcp.cc:158
virtual void PktsAcked(Ptr< TcpSocketState > tcb, uint32_t segmentsAcked, const Time &rtt)
Timing information on received ACK.
Definition: tcp-dctcp.cc:124
UseEcn_t m_useEcn
Socket ECN capability.
bool m_ceState
DCTCP Congestion Experienced state.
Definition: tcp-dctcp.h:126
ECN functionality as described in RFC 8257.
double m_alpha
Parameter used to estimate the amount of network congestion.
Definition: tcp-dctcp.h:123
SequenceNumber32 m_nextSeq
TCP sequence number threshold for beginning a new observation window.
Definition: tcp-dctcp.h:124
Every class exported by the ns3 library is enclosed in the ns3 namespace.
An implementation of DCTCP.
Definition: tcp-dctcp.h:36
virtual ~TcpDctcp(void)
Destructor.
Definition: tcp-dctcp.cc:94
double m_g
Estimation gain.
Definition: tcp-dctcp.h:128
void CeState0to1(Ptr< TcpSocketState > tcb)
Changes state of m_ceState to true.
Definition: tcp-dctcp.cc:167
uint32_t m_ackedBytesEcn
Number of acked bytes which are marked.
Definition: tcp-dctcp.h:119
TracedValue< uint32_t > m_cWnd
Congestion window.
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:120
TcpDctcp()
Create an unbound tcp socket.
Definition: tcp-dctcp.cc:63
bool m_priorRcvNxtFlag
Variable used in setting the value of m_priorRcvNxt for first time.
Definition: tcp-dctcp.h:122
SequenceNumber32 m_priorRcvNxt
Sequence number of the first missing byte in data.
Definition: tcp-dctcp.h:121
Ptr< const AttributeChecker > MakeBooleanChecker(void)
Definition: boolean.cc:121
bool m_delayedAckReserved
Delayed Ack state.
Definition: tcp-dctcp.h:127
virtual void ReduceCwnd(Ptr< TcpSocketState > tcb)
Reduces congestion window on receipt of ECN Echo Flag.
Definition: tcp-dctcp.cc:116
bool m_nextSeqFlag
Variable used in setting the value of m_nextSeq for first time.
Definition: tcp-dctcp.h:125
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.
ECT set, but not CE marked.